02.03.2016 Views

MATLAB by rudra pratap

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

18<br />

Tutorial Lessons<br />

» 2 + 2<br />

ans<br />

4<br />

Enter 2+2 and hit the return/enter<br />

key. Note that the result of an unassigned<br />

expression is saved in the<br />

default variable ans .<br />

>> X = 2 + 2<br />

X =<br />

You can also assign the value of an<br />

expression to a variable.<br />

4<br />

»y = 2A2 + log (pi ) *sin (x) ;<br />

»y<br />

A semicolon at the end suppresses<br />

screen output. MA TLAB remembers<br />

y, though. You can recall the value<br />

y <strong>by</strong> simply typing y.<br />

y =<br />

3.1337<br />

» theta = aces (-1)<br />

theta =<br />

<strong>MATLAB</strong> knows trigonometry.<br />

Here is arccosine of -1.<br />

3.1416<br />

» format short e<br />

» theta<br />

theta =<br />

The floating point output display<br />

is controlled <strong>by</strong> the format<br />

command. Here are two examples.<br />

More information will be provided<br />

on this later.<br />

3.1416e+000<br />

>> format long<br />

» theta<br />

theta =<br />

»quit<br />

3.141592653589793<br />

Quit <strong>MATLAB</strong>. You can also quit <strong>by</strong><br />

selecting Quit from the file menu on<br />

Macs and PCs.<br />

Figure 2.1: Lesson 1: Some simple calculations in <strong>MATLAB</strong>.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!