2. Simple Mathematics

Assignment statements

The preceding MATLAB commands that assign the value of the expression after the ’=’ sign to the variable before the ’=’ sign are assignment statements. Note that all variables in the expression after the ’=’ sign must have previously been allocated a value, or else an error occurs. For example, enter the following commands:

a=3

B=4

c=sqrt(a^2+b^2)

You will see the error message ??? Undefined function or variable ’b’Consider the following:

clear all

x=7

x=x^2-12

The last line has nothing at all to do with a mathematical equation. It is a MATLAB assignment statement that calculates x2 −12 at x = 7 and stores the result in the variable x, thereby over-writing the previous value.