MATLAB Guide

MATLAB is an interactive system. You type commands at the prompt ( ?) in the Command Window and computations are performed when you press the enter or return key. At its simplest level, MATLAB can be used like a pocket calculator:
<span class="unicode">?</span> (1+sqrt(5))/2 ans = 1.6180 <span class="unicode">?</span> 2^ (-53) ans = 1.1102e-016
The first example computes (1 + ?5)/2 and the second 2 ?53. Note that the second result is displayed in exponential notation: it represents 1.1102 10 ?16. The variable ans is created (or overwritten, if it already exists) when an expression is not assigned to a variable. It can be referenced later, just like any other variable. Unlike in most programming languages, variables are not declared prior to use but are created by MATLAB when they are assigned:
<span class="unicode">?</span> x = sin(22) x = -0.0089
Here we have assigned to x the sine of 22 radians. The printing of output can be suppressed by appending a semicolon. The next example assigns a value to y without displaying the result:
<span class="unicode">?</span> y = 2*x + exp (-3)/(1+cos(.1));
Commas or semicolons are used to separate statements that appear on the same line:
<span class="unicode">?</span> x = 2,...