NC Lect Symbolic 15
NC Lect Symbolic 15
Symbolic Calculations
>> syms a b c x
>> y=a*x^2+b*x+c;
>> syms x y
>> f=sin(x+y);
>> expand(f)
Symbolic Calculations in MATLAB
>> syms x
>> y= x* (x^2+ sin (x)) * (x^3+ exp (x) );
>> collect (y)
x2y + xy - x2 - 2x by powers of x.
>> syms x y
>> collect (x^2y + x*y - x^2 - 2* x, x)
Symbolic Calculations in MATLAB
>> syms x
>> factor(x^4-1)
The Simplify Command Example: Simplify the expression
y = x4 - 81 / x2 -9
The simplify command is used to .
rewrite a symbolic expression with >> syms x
the least number of characters. >> y= (x^4-81) / (x^2-9);
>> simplify(y)
Symbolic Calculations in MATLAB
>> syms x y c
>> f=exp (c*log (sqrt (x^2+
y^2) ) );
>> simplify(f)
Symbolic Calculations in MATLAB
>> syms x y
>> f=sin (x) + cos (y);
>> subs ( f, fx, yg, f1, 2g)
19
Basic Calculus in MATLAB
Limits
Limits can be calculated in MATLAB by using the limit command. To
compute limits of the form f(x), we use the syntax limit(f,a).
Derivatives
Derivatives can be computed using the diff command. To find the
derivative of a function of one variable f(x), we use the syntax diff (f).
Basic Calculus in MATLAB
Basic Calculus in MATLAB
Integration
Integrals can be computed using the int command. To evaluate indefinite
integrals of the form
Basic Calculus in MATLAB
Basic Calculus in MATLAB
M-Files Overviews
Script M-Files
Function M-Files
A function M-le is used to perform operations with a function. This
typically involves inputting some variable or variables which are
processed by the M-le and some output is returned. As before, click the
\New Script" icon in the upper left corner of the MATLAB window. A new
window will appear with MATLAB's default editor.
Basic Calculus in MATLAB
Every function M-le begins with the function command, and the input is
placed in paren-theses after the name of the function M-le. To save this le,
click the \Save" icon in the upper left corner of the MATLAB window and
choose \Save As". Save your M-file as CosineDiff.m. For every function M-
file, the file name must be the same as the name of the function. To run
this function M-file, enter the following command in the command window:
>> CosineDiff(0)
function CosineInt(a,b)
syms x
f=cos(x);
Int (f,a,b)
A switch statement takes a variable, say x, and performs different
operations depending on the value of that variable.