3-D Plots and Loops - Survey - Higher College of Technology

Symbolic Toolbox
Dr GUNASEKARAN THANGAVEL
Lecturer & Program Co-ordinator
Electronics & Telecommunication Engineering
EEE Section
Department of Engineering
Higher College of Technology, Muscat.
Can other languages do the
following?




integrate sin(x) and give –cos(x)+c as the
result?
Differentiate sin(x) and give out cos(x)?
Solve a D2y=-a2y and give
y=A sin(ax)+B cos(ax)?
Factorize x^2-3x+2 and give (x-1)(x-2)?
Introduction
 Symbols will be processed instead of
numerics.
 Mathematical expressions will be
manipulated.
 Example:
>>syms x
>>s=x^2-3*x+2;
>>factor(s)
 Ans: (x-1)*(x-2)
Simplification of mathematical
expressions
 Collect(s) –collects the coefficients of s
>>syms x
>>s=x^2-3*x+2*x+2*x^2+1
>>collect(s)
Ans: 3*x^2-x+1
Expand
 Expand(s)- performs an expansion of s
>>syms x
>>s=(x-2)^2;
>>expand(s)
ans =
x^2-4*x+4
Simple
 Simple(s)- simplifies the form of s to a
shorter form ,if possible.
>> syms x
>> s= cos(x)^2+sin(x)^2 ;
>> simple(s)
ans =
1
Poly2sym
 Converts coefficients of the
polynomial into symbolic polynomial
>> s=[1 2 3];
>> poly2sym(s)
ans =
x^2+2*x+3
sym2poly
 Converts symbolic polynomial into
coefficients of the polynomial
>> s=x^2+2*x+3;
>> sym2poly(s)
ans =
1
2
3
symadd and symsub
 Performs symbolic addition and
symbolic subtraction.
>>
>>
>>
>>
syms x
s1=1/(1+x);
s2=1/(1-x);
symadd(s1,s2)
>>
>>
>>
>>
syms x
s1=1/(1+x);
s2=1/(1-x);
symsub(s1,s2)
ans =
ans =
1/(1+x)+1/(1-x)
1/(1+x)-1/(1-x)
symmul and symdiv
 Performs symbolic addition and
symbolic subtraction.
>>
>>
>>
>>
syms x
s1=(1+x);
s2=(1-x);
symmul(s1,s2)
>>
>>
>>
>>
syms x
s1=(1+x);
s2=(1-x);
symdiv(s1,s2)
ans =
ans =
(1+x)*(1-x)
(1+x)/(1-x)
Equation solving
 Solve(f)- solves a symbolic
expression
>> syms x
>> f='x^2+4*x+4=0';
>> solve(f)
ans =
[ -2]
[ -2]
Differential Equation solving
 dsolve(‘ differential equation’, initial
conditions)
 Example: dx
  ax
dt
dsolve('Dx = -a*x') returns
ans = exp(-a*t)*C1
Differential Equation solving…
 The independent variable of our choice
can be included after the initial
conditions
dy
  ay
dx
y = dsolve('Dy = -a*y',‘y(0) = 1',‘x') returns
y = exp(-a*x)
Differentiation
.
DIFF(S) differentiates a symbolic expression S with
respect to its
free variable
DIFF(S,'v') differentiates S with respect to v.
DIFF(S,n), for a positive integer n, differentiates S n
times.
Examples
.
>> syms x
>> s=sin(x);
>> diff(s)
>> syms x
>> s=x^3;
>> diff(s,2)
ans =
ans =
cos(x)
6*x
Integration
 int(S) is the indefinite integral of S
with respect to its symbolic variable
 int(S,a,b) is the definite integral of S
with respect to its symbolic variable
from a to b
Examples
 indefinite integral and definite integral
>> syms x
>> int(sin(x))
ans =
-cos(x)
>> syms x
>> int(sin(x),0,2*pi)
ans =
0
User defined function
 It is a good practice to create user
defined functions if the program
requires to perform same operation
with different inputs then and there.
 In such cases, the operation will be
cast into a user defined function.
 That should be stored in separate file
with filename same as function name.
Syndax
 function z=name(input arguments)
operation
Example:
function z=add(a,b);
z=a+b;
Thank you
.
You can find…
 This ppt is available in the following
locations
\\172.16.51.33\c\3dplots\symbolictoolbox.ppt
\\172.16.51.37\zs37\matlabworkshop\symbolic
toolbox.ppt
Excercise
 1.Integrate x from 0 to 1
 2.Differentiate x^3-5x^2+2x+8
 3.Solve the following differential
equation D2y(x)=-a^2y(x)
 4.Solve x^2+2x+1