Download presentation
Presentation is loading. Please wait.
Published byHoward Ferguson Modified over 6 years ago
1
Symbolic Toolbox Dr GUNASEKARAN THANGAVEL Lecturer & Program Co-ordinator Electronics & Telecommunication Engineering EEE Section Department of Engineering Higher College of Technology, Muscat.
2
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)?
3
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)
4
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
5
Expand Expand(s)- performs an expansion of s >>syms x
x^2-4*x+4
6
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
7
Poly2sym Converts coefficients of the polynomial into symbolic polynomial >> s=[1 2 3]; >> poly2sym(s) ans = x^2+2*x+3
8
sym2poly Converts symbolic polynomial into coefficients of the polynomial >> s=x^2+2*x+3; >> sym2poly(s) ans =
9
symadd and symsub Performs symbolic addition and symbolic subtraction.
>> syms x >> s1=1/(1+x); >> s2=1/(1-x); >> symadd(s1,s2) ans = 1/(1+x)+1/(1-x) >> syms x >> s1=1/(1+x); >> s2=1/(1-x); >> symsub(s1,s2) ans = 1/(1+x)-1/(1-x)
10
symmul and symdiv Performs symbolic addition and symbolic subtraction.
>> syms x >> s1=(1+x); >> s2=(1-x); >> symmul(s1,s2) ans = (1+x)*(1-x) >> syms x >> s1=(1+x); >> s2=(1-x); >> symdiv(s1,s2) ans = (1+x)/(1-x)
11
Equation solving Solve(f)- solves a symbolic expression
>> syms x >> f='x^2+4*x+4=0'; >> solve(f) ans = [ -2]
12
Differential Equation solving
dsolve(‘ differential equation’, initial conditions) Example: dsolve('Dx = -a*x') returns ans = exp(-a*t)*C1
13
Differential Equation solving…
The independent variable of our choice can be included after the initial conditions y = dsolve('Dy = -a*y',‘y(0) = 1',‘x') returns y = exp(-a*x)
14
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.
15
Examples . >> syms x >> syms x >> s=sin(x);
>> diff(s) ans = cos(x) >> syms x >> s=x^3; >> diff(s,2) ans = 6*x
16
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
17
Examples indefinite integral and definite integral >> syms x
>> int(sin(x)) ans = -cos(x) >> syms x >> int(sin(x),0,2*pi) ans =
18
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.
19
Syndax function z=name(input arguments) operation Example:
function z=add(a,b); z=a+b;
20
Thank you .
21
You can find… This ppt is available in the following locations
\\ \c\3dplots\symbolictoolbox.ppt \\ \zs37\matlabworkshop\symbolictoolbox.ppt
22
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.