Practical 2: Variables, Script M-files and Graphing

Naming of Numerical Values in MATLAB

Why would we want to name numerical values? Here is one example: Consider the polynomial function

y=x^{2}+4x+3 to be calculated for x = 3.

We could do so by typing in the following:

3^2 + 4*3 + 3

but what if we also want to know the answer when x = 7 and x = 5? Wouldn’t it be easier to create a name for 3 called x as follows:

x = 3

and then evaluate our polynomial function by typing in:

x^2 + 4x + 3

x is what we call a variable.