8.4: Interactive Mode
In command mode, MATLAB displays a prompt (\(\gg\)) and waits for your input. You may type any legal mathematical expression for immediate evaluation. Try the following three examples (press “enter” or “return” at the end of each line):
≫ 2+2 ≫ 5^2 ≫ 2*sin(pi/4)
The variable
pi
= 3.14
is built into MATLAB, as are the
sin
function and hundreds of other functions. When you entered each of the preceding lines, MATLAB stored the results in a variable called
ans
for
answer
. The value of
ans
was then displayed. The last line should have produced the square root of 2. We can manipulate
ans
to find out
≫ ans^2
The new answer is very close to 2, as expected. Let's see what the roundoff error is:
≫ ans-2