All rights reserved. No part of this publication may be reproduced, distributed, or transmitted, unless for course participation, in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the Publisher and/or Author. Contact the American Institute of Aeronautics and Astronautics, Professional Development Programs, Suite 500, 1801 Alexander Bell Drive, Reston, VA 20191-4344. 1 out of 30
Engineering Computations and Modeling in MATLAB/Simulink
Chapter 7. Symbolic Math Toolbox
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted, unless for course participation, in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the Publisher and/or Author. Contact the American Institute of Aeronautics and Astronautics, Professional Development Programs, Suite 500, 1801 Alexander Bell Drive, Reston, VA 20191-4344. 2 out of 30
Engineering Computations and Modeling in MATLAB/Simulink
Outline • 7.1 Introduction • 7.2 Symbolic Math Toolbox Overview • 7.3 Getting Started • 7.4 Basic Operations • 7.5 Linear Algebra and Calculus • 7.6 Solving Algebraic and Differential Equations • 7.7 Simplification and Substitution • 7.8 Other Functions • 7.9 MuPAD Development Environment • 7.10 Plotting Symbolic Expressions • 7.11 Using Symbolic Expressions in Numerical Operations • 7.12 LaTeX Representation of Symbolic Expression • 7.13 Symbolic Calculators
Engineering Computations and Modeling in MATLAB/Simulink
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted, unless for course participation, in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the Publisher and/or Author. Contact the American Institute of Aeronautics and Astronautics, Professional Development Programs, Suite 500, 1801 Alexander Bell Drive, Reston, VA 20191-4344. 3 out of 30
Engineering Computations and Modeling in MATLAB/Simulink
Toolbox Overview
Originally, the computational engine underlying the Symbolic Math toolbox was the Maple kernel, developed at the University of Waterloo in Canada. Before R2007b, the Basic Symbolic Math toolbox included in the Student Version was a collection of more than a hundred MATLAB functions allowing access to the functions in Maple’s linear algebra package. The Extended Symbolic Math toolbox augmented the basic toolbox by including access to non-graphics packages, programming features and user defined procedures in Maple.
As of R2007b+, Symbolic Math Toolbox - now a single product - uses the MuPAD computational engine, originally developed by the MuPAD research group at the University of Paderborn, Germany. The functionality of the MuPAD language, together with included libraries, goes far beyond that of the previous Symbolic Math Toolbox software. The functionality of Extended Symbolic Math Toolbox has been taken over by MuPad environment (MuPAD Notebook).
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted, unless for course participation, in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the Publisher and/or Author. Contact the American Institute of Aeronautics and Astronautics, Professional Development Programs, Suite 500, 1801 Alexander Bell Drive, Reston, VA 20191-4344. 4 out of 30
Engineering Computations and Modeling in MATLAB/Simulink
Areas Supported by Toolbox
Subject Areas Supported
Linear Algebra Inverses, determinants, eigenvalues, singular value decomposition, canonical forms of symbolic matrices
Calculus Differentiation, integration, limits, summation, and Taylor series
Solving (Systems of) Equations Symbolic and numerical solutions to algebraic and differential equations
Simplification and Substitution Methods of simplifying algebraic expressions
Integral Transforms Fourier, Laplace, z- transforms and their corresponding inverse transforms
Conversions and Variable Precision Arithmetic
Conversion and numerical evaluation of mathematical expressions to any specified accuracy
Special Functions Special functions in applied mathematics such as Airy functions, binomial
coefficients, error functions, Bessel functions, Dirac delta function, Legendre polynomials, Jacobian, and Chebyschev functions
Plotting Symbolic Expressions Easy 2D and 3D plotting of symbolic expressions
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted, unless for course participation, in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the Publisher and/or Author. Contact the American Institute of Aeronautics and Astronautics, Professional Development Programs, Suite 500, 1801 Alexander Bell Drive, Reston, VA 20191-4344. 5 out of 30
Engineering Computations and Modeling in MATLAB/Simulink
Symbolic Math Demos
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted, unless for course participation, in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the Publisher and/or Author. Contact the American Institute of Aeronautics and Astronautics, Professional Development Programs, Suite 500, 1801 Alexander Bell Drive, Reston, VA 20191-4344. 6 out of 30
Engineering Computations and Modeling in MATLAB/Simulink
Basic Operations
sym('a') syms x y y=(x^a+sqrt(x))/y pretty(y) symvar(y)
y = (x^a + x^(1/2))/y a 1/2 x + x --------- y ans = [ a, x, y]
Arithmetic Operations + Addition - Subtraction * Multiplication .* Array multiplication \ Left division .\ Array left division / Right division ./ Array right division ^ Matrix or scalar raised to a power .^ Array raised to a power ’ Complex conjugate transpose .’ Real transpose
Basic Operations ceil Round symbolic matrix toward positive infinity conj Symbolic complex conjugate eq Symbolic equality test fix Round toward zero floor Round symbolic matrix toward negative infinity frac Symbolic matrix elementwise fractional parts imag Imaginary part of complex number latex LaTeX representation of symbolic expression log10 Logarithm base 10 of entries of symbolic matrix Iog2 Logarithm base 2 of entries of symbolic matrix mod Symbolic matrix elementwise modulus pretty Pretty-print symbolic expressions quorem Symbolic matrix elementwise quotient and remainder real Real part of imaginary number round Symbolic matrix elementwise round size Symbolic matrix dimensions sort Sort symbolic vectors or polynomials sym Symbolic numbers, variables, and objects syms Shortcut for constructing symbolic objects symvar Find symbolic variables in symbolic expression or matrix
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted, unless for course participation, in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the Publisher and/or Author. Contact the American Institute of Aeronautics and Astronautics, Professional Development Programs, Suite 500, 1801 Alexander Bell Drive, Reston, VA 20191-4344. 7 out of 30
Engineering Computations and Modeling in MATLAB/Simulink
Linear Algebra & Calculus
syms a11 a22 a21 a22 inv([a11 a22; a21 a22])
syms x k a diff(cos(x^2)) int(cos(x)^2,0,pi) limit(sin(x)/x) symsum(x^k/sym('k!'),k,0,inf) taylor(sin(x-a),x,a,'Order',10)
Linear Algebra colspace Basis for column space det Symbolic matrix determinant diag Create or extract symbolic diagonals eig Symbolic eigenvalues and eigenvectors expm Symbolic matrix exponential inv Symbolic matrix inverse jordan Jordan canonical form null Basis for null space poly Characteristic polynomial of matrix rank Symbolic matrix rank rref Reduced row echelon form svd Symbolic singular value decomposition tril Symbolic lower triangle triu Symbolic upper triangle
Calculus diff Differentiate symbolic expression int Integrate symbolic expression jacobian Jacobian matrix limit Limit of symbolic expression symsum Symbolic summation of series taylor Taylor series expansion
( )
0
( )( ) ( )!
nn
n
f af x x an
∞
=
= −∑
2(cos( ))d xdx2
0
cos ( )x dxπ
∫
0
sin( )limx
xx→
0 !
k
k
xk
∞
=∑
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted, unless for course participation, in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the Publisher and/or Author. Contact the American Institute of Aeronautics and Astronautics, Professional Development Programs, Suite 500, 1801 Alexander Bell Drive, Reston, VA 20191-4344. 8 out of 30
Engineering Computations and Modeling in MATLAB/Simulink
Solving Equations
syms a b c x, solve(a*x^2+b*x+c,x)
syms x y, [x,y]=solve([5*x+6*y-8,2*x+3*y-1])
syms a x y, f=solve([a*x^2+y^2-1,x+sqrt(y)-1],[x,y]); [f.x f.y]
dsolve('Dx-a*x=sin(t)','x(0)=1')
g=dsolve('Dx=y','Dy=cos(t)','x(0)=1','y(0)=0'); [g.x g.y]
dsolve('D3x=x-1','x(0)=0','Dx(1)=2','D2x(0)=0')
Solution of Equations compose Functional composition dsolve Symbolic solution of ordinary differential equations finverse Functional inverse solve Symbolic solution of algebraic equations
syms x(t); D1=diff(x); D2=diff(x,2); dsolve(diff(x,3)==x-1,[x(0)==0,D1(1)==2,D2(0)==0])
Dx – the 1st-order derivative
D2x – the 2nd-order derivative
D3x – the 3rd-order derivative
solving a single equation with respect to x
solving two equations with respect to x and y
solving two equations with respect to x and y
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted, unless for course participation, in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the Publisher and/or Author. Contact the American Institute of Aeronautics and Astronautics, Professional Development Programs, Suite 500, 1801 Alexander Bell Drive, Reston, VA 20191-4344. 9 out of 30
Engineering Computations and Modeling in MATLAB/Simulink
Simplification & Substitution
syms x y=cos(2*x) simple(y)
Simplification and Substitution coeffs Coefficients of multivariate polynomial collect Collect coefficients expand Symbolic expansion of polynomials and elementary functions factor Factorization horner Horner nested polynomial representation numden Numerator and denominator simple Search for simplest form of symbolic expression simplify Symbolic simplification subexpr Rewrite symbolic expression in terms of common subexpressions subs Symbolic substitution in symbolic expression of matrix
syms x y rho phi R a zdc=(x-a)^2+y^2-R^2; zpc=subs(zdc,{x,y},{rho*cos(phi),rho*sin(phi)}) simplify(zpc)
Double strikethrough functions should be removed if using R2014b+
syms x y=cos(2*x) expand(y)
ans = 2*cos(x)^2 - 1
ans = - R^2 + a^2 - 2*cos(phi)*a*rho + rho^2
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted, unless for course participation, in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the Publisher and/or Author. Contact the American Institute of Aeronautics and Astronautics, Professional Development Programs, Suite 500, 1801 Alexander Bell Drive, Reston, VA 20191-4344. 10 out of 30
Engineering Computations and Modeling in MATLAB/Simulink
Integral & z-Transforms
syms a t laplace(t*exp(-a*t))
syms w x y ilaplace(w/(y^2 + w^2),y)
Integral Transforms fourier Fourier integral transform ifourier Inverse Fourier integral transform ztrans z-transform transform iztrans Inverse z-transform laplace Laplace transform ilaplace Inverse Laplace transform
1( ) ( )2
i tf t F e dωω ωπ
∞
−∞
= ∫( ) ( ) i tF f t e dtωω
∞−
−∞
= ∫
11( ) ( ) , 1, 2,...2
n
z R
f n F z z dz niπ
−
=
= =∫0
( )( ) nn
f nF zz
∞
=
=∑
0
( ) ( ) stF s f t e dt∞
−= ∫( ) ( )
c ist
c i
f t F s e ds+ ∞
− ∞
= ∫
ans = 1/(a + s)^2
ans = sin(w*y)
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted, unless for course participation, in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the Publisher and/or Author. Contact the American Institute of Aeronautics and Astronautics, Professional Development Programs, Suite 500, 1801 Alexander Bell Drive, Reston, VA 20191-4344. 11 out of 30
Engineering Computations and Modeling in MATLAB/Simulink
Other Functions syms x f=taylor(sin(x),'Order',4) t=inline(char(f)); t(5)
f = - x^3/6 + x ans = -15.8333
Conversions ccode C code representation of symbolic expression char Convert symbolic objects to strings double Convert symbolic matrix to MATLAB numeric form emlBlock Convert symbolic expression to MATLAB Function block fortran Fortran representation of symbolic expression int8, int16, int32, int64 Convert symbolic matrix to signed integers latex LaTeX representation of symbolic expression matlabFunction Convert symbolic expression to function handle or file poly2sym Polynomial coefficient vector to symbolic polynomial single Convert symbolic matrix to single precision sym2poly Symbolic-to-numeric polynomial conversion uint8, uint16, uint32, uint64 Convert symbolic matrix to unsigned integers
Variable Precision Arithmetic digits Variable precision accuracy
vpa Variable precisian arithmetic
Special Functions cosint Cosine integral dirac Dirac delta gamma Gamma function heaviside Heaviside step function hyperqeom Generalized hypergeometric lambertw Lambert's W function mfun Numeric evaluation of special mathematical function mfunlist List special functions for use with mfun sinint Sine integral zeta Riemann Zeta
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted, unless for course participation, in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the Publisher and/or Author. Contact the American Institute of Aeronautics and Astronautics, Professional Development Programs, Suite 500, 1801 Alexander Bell Drive, Reston, VA 20191-4344. 12 out of 30
Engineering Computations and Modeling in MATLAB/Simulink
Pedagogical and Graphical Applications ezcontour Contour plotter ezcontourf Filled contour plotter ezmesh 3D mesh plotter ezmeshc Combined mesh and contour plotter ezplot 2D parametric curve plotter ezplot3 3D parametric curve plotter ezpolar Polar coordinate plotter ezsurf 3D colored surface plotter ezsurfc Combined surface and contour plot funtool Function calculator rsums Interactive evaluation of Riemann sums taylortool Taylor series calculator
Calculators & Plotting g=dsolve('Dx=y','Dy=cos(t)',... 'x(0)=1','y(0)=0'); ezplot(g.x,g.y)
syms r phi x=r*cos(phi); y=r*sin(phi); z=1+besselj(1,3*r)*cos(phi); ezmesh(x,y,z)
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted, unless for course participation, in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the Publisher and/or Author. Contact the American Institute of Aeronautics and Astronautics, Professional Development Programs, Suite 500, 1801 Alexander Bell Drive, Reston, VA 20191-4344. 13 out of 30
Engineering Computations and Modeling in MATLAB/Simulink
MuPAD Functions
MuPAD clear all Remove items from MATLAB workspace and reset MuPAD engine doc Get help for MuPAD functions evalin Evaluate MuPAD expressions feval Evaluate MuPAD expressions getVar Get variable from MuPAD notebook mupad Start MuPAD notebook mupadwelcome Start MuPAD interfaces openmn Open MuPAD notebook openmu Open MuPAD program file openmuphlp Open MuPAD help file openxvc Open MuPAD XVC graphics file openxvz Open MuPAD XVZ graphics file reset Close MuPAD engine setVar Assign variable in MuPAD notebook symengine Return symbolic engine trace Enable and disable tracing of MuPAD commands
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted, unless for course participation, in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the Publisher and/or Author. Contact the American Institute of Aeronautics and Astronautics, Professional Development Programs, Suite 500, 1801 Alexander Bell Drive, Reston, VA 20191-4344. 14 out of 30
Engineering Computations and Modeling in MATLAB/Simulink
MuPAD >> mupadwelcome or >> mupad
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted, unless for course participation, in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the Publisher and/or Author. Contact the American Institute of Aeronautics and Astronautics, Professional Development Programs, Suite 500, 1801 Alexander Bell Drive, Reston, VA 20191-4344. 15 out of 30
Engineering Computations and Modeling in MATLAB/Simulink
MuPAD Notebook
Insert Calculation Insert Text Paragraph Evaluate Stop
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted, unless for course participation, in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the Publisher and/or Author. Contact the American Institute of Aeronautics and Astronautics, Professional Development Programs, Suite 500, 1801 Alexander Bell Drive, Reston, VA 20191-4344. 16 out of 30
Engineering Computations and Modeling in MATLAB/Simulink
MuPAD Syntax MATLAB MuPAD
Assignment = =:
List variables whos anames(All,User)
Numerical value of an expression double(expression) float(expression)
Suppress output ; :
Enter a matrix [a, b, c; d, e, f] matrix([a, b ,c], [d, e, f])
{a,b,c} cell array set
Linear algebra commands nothing extra is needed linalg:: prefix or use(linalg)
Autocompletion <Tab> <Ctrl>+<Space>
Equality and inequality comparison ==, ~= =, <>
MATLAB MuPAD
besselj, bessely, besseli, besselk besselJ, besselY, besselI, besselK
lambertw lambertW
sinint, cosint Si, Ci
eilergamma, catalan EULER, CATALAN
conj conjugate
laplace, ilaplace transform::laplace, transform::ilaplace
ztrans, iztrans transform::ztrans, transform::iztrans
MATLAB MuPAD
Inf infinity
pi PI
i I
NaN undefined
fix trunc
log ln
MATLAB MuPAD
asin acos atan asinh acosh atanh acsc asec acot
acsch asech acoth
arcsin arccos arctan arcsinh arccosh arctanh arcsc arcsec arccot
arccsch arcsech arccoth
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted, unless for course participation, in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the Publisher and/or Author. Contact the American Institute of Aeronautics and Astronautics, Professional Development Programs, Suite 500, 1801 Alexander Bell Drive, Reston, VA 20191-4344. 17 out of 30
Engineering Computations and Modeling in MATLAB/Simulink
MuPAD Computations1
1 2 3
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted, unless for course participation, in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the Publisher and/or Author. Contact the American Institute of Aeronautics and Astronautics, Professional Development Programs, Suite 500, 1801 Alexander Bell Drive, Reston, VA 20191-4344. 18 out of 30
Engineering Computations and Modeling in MATLAB/Simulink
MuPAD Computations2
4 5 6
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted, unless for course participation, in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the Publisher and/or Author. Contact the American Institute of Aeronautics and Astronautics, Professional Development Programs, Suite 500, 1801 Alexander Bell Drive, Reston, VA 20191-4344. 19 out of 30
Engineering Computations and Modeling in MATLAB/Simulink
MuPAD Computations3
7 8
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted, unless for course participation, in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the Publisher and/or Author. Contact the American Institute of Aeronautics and Astronautics, Professional Development Programs, Suite 500, 1801 Alexander Bell Drive, Reston, VA 20191-4344. 20 out of 30
Engineering Computations and Modeling in MATLAB/Simulink
Quick MuPAD/MATLAB Interchange
Copy and paste to the MATLAB Workspace to receive
sin(x)^2/x
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted, unless for course participation, in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the Publisher and/or Author. Contact the American Institute of Aeronautics and Astronautics, Professional Development Programs, Suite 500, 1801 Alexander Bell Drive, Reston, VA 20191-4344. 21 out of 30
Engineering Computations and Modeling in MATLAB/Simulink
The getVar and setVar Functions
>> g=sqrt(f) g = (exp(y)*asin(x))^(1/2) >> setVar(h_ntb,'w',g)
>> h_ntb=mupad; >> f = getVar(h_ntb,'f') f = exp(y)*asin(x)
MuPAD => MATLAB MATLAB => MuPAD
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted, unless for course participation, in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the Publisher and/or Author. Contact the American Institute of Aeronautics and Astronautics, Professional Development Programs, Suite 500, 1801 Alexander Bell Drive, Reston, VA 20191-4344. 22 out of 30
Engineering Computations and Modeling in MATLAB/Simulink
The matlabFunction Functions >> syms ps M
>> q = 0.7*ps*M^2; >> hq = matlabFunction(q) hq = @(M,ps)M.^2.*ps.*(7.0./1.0e1)
syms lat lon Rlon = [cos(lon) sin(lon) 0; -sin(lon) cos(lon) 0; 0 0 1]; Rlat = [cos(lat) 0 sin(lat); 0 1 0; -sin(lat) 0 cos(lat)]; R = Rlat*Rlon; F = matlabFunction(R,'file','RotationMatrix.m')
function R = RotationMatrix(lat,lon) %ROTATIONMATRIX % R = ROTATIONMATRIX(LAT,LON) % 13-Nov-2017 19:59:41 t2 = cos(lat); t3 = sin(lon); t4 = cos(lon); t5 = sin(lat); R = reshape([t2.*t4,-t3,-t4.*t5,t2.*t3,t4,-t3.*t5,t5,0.0,t2],[3,3]);
Creates a function handle F to the
RotationMatrix function saved as
RotationMatrix.m
>> M = [0.2,0.2,0.6]; ps = [101325, 60000, 101325]; >> hq(M,ps) ans = 1.0e+004 * 0.2837 0.1680 2.5534
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted, unless for course participation, in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the Publisher and/or Author. Contact the American Institute of Aeronautics and Astronautics, Professional Development Programs, Suite 500, 1801 Alexander Bell Drive, Reston, VA 20191-4344. 23 out of 30
Engineering Computations and Modeling in MATLAB/Simulink
z=[1 3 4]; x=poly(z);
fs=poly2sym(x)
fc=char(fs)
xz=fzero(fc,1.82)
fa=str2func(['@(x)' fc])
fplot(fa,[0 5]), grid
hold, plot(xz,fa(xz),'rp')
Symbolic to String and Function Handle
fs = x^3-8*x^2+19*x-12
fc = x^3-8*x^2+19*x-12
xz = 1.0000
fa = @(x)19*x-8*x^2+x^3-12
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted, unless for course participation, in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the Publisher and/or Author. Contact the American Institute of Aeronautics and Astronautics, Professional Development Programs, Suite 500, 1801 Alexander Bell Drive, Reston, VA 20191-4344. 24 out of 30
Engineering Computations and Modeling in MATLAB/Simulink
syms t
fsym=cos(t)*exp(t)
ezplot(fsym) % it works! :-)
xmin=fminsearch(fsym,3) % it doesn’t work :-(
finl=inline(char(fsym))
xmin=fminsearch(finl,3) % it works now :-)
hold, plot(xmin,finl(xmin),'rp')
Symbolic to Inline Function
fsym = cos(t)*exp(t)
??? Error using ==> fcnchk at 105
If FUN is a MATLAB object, it must have an feval method.
Error in ==> fminsearch at 178
funfcn = fcnchk(funfcn,length(varargin));
finl =
Inline function:
finl(t) = cos(t)*exp(t)
xmin = 3.9270
Current plot held
1
2
1
2
3
3
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted, unless for course participation, in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the Publisher and/or Author. Contact the American Institute of Aeronautics and Astronautics, Professional Development Programs, Suite 500, 1801 Alexander Bell Drive, Reston, VA 20191-4344. 25 out of 30
Engineering Computations and Modeling in MATLAB/Simulink
inline vs. fcnchk syms t
fsym=cos(t)*exp(t)
ezplot(fsym)
finl=fcnchk(char(fsym)) % fcnchk is equivalent to inline
xmin=fminsearch(finl,3) % it works now :-)
hold, plot(xmin,finl(xmin),'rp')
ezplot('sin(2*x)')
ezplot('sin(2*t)')
syms t
fsym=cos(t)*exp(t);
finl=fcnchk(char(fsym),'vectorized')
finl =
Inline function:
finl(t) = cos(t).*exp(t).*ones(size(t))
What’s the difference?
finl=inline(vectorize(char(fsym)))
fzero('sin(2*x)',3)
fzero('sin(2*t)',3)
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted, unless for course participation, in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the Publisher and/or Author. Contact the American Institute of Aeronautics and Astronautics, Professional Development Programs, Suite 500, 1801 Alexander Bell Drive, Reston, VA 20191-4344. 26 out of 30
Engineering Computations and Modeling in MATLAB/Simulink
LaTeX Representation of Symbolic Expression
>> syms x y t >> F1 = diff(atan(x)) >> F2 = sym(hilb(3)) >> F4 =(x^2+1/x)/sqrt((sin(x)+cos(x))/x^3.5) >> F5 = taylor(sin(x),'Order',8,'ExpansionPoint',pi/2)
>> H1=latex(F1); >> H2=latex(F2); >> H4=latex(F4); >> H5=latex(F5); >> text(.2,.25,['$$' H1 '$$'],'interpreter','latex','fontsize',14) >> text(.6,.2, ['$$' H2 '$$'],'interpreter','latex','fontsize',16) >> text(.3,.5, ['$$' H4 '$$'],'interpreter','latex','fontsize',18) >> text(.1,.8, ['$$' H5 '$$'],'interpreter','latex','fontsize',14)
F1 = 1/(x^2 + 1) F2 = [ 1, 1/2, 1/3] [ 1/2, 1/3, 1/4] [ 1/3, 1/4, 1/5] F4 = (1/x + x^2)/((cos(x) + sin(x))/x^(7/2))^(1/2) F5 = (x - pi/2)^4/24 - (x - pi/2)^2/2 - (x - pi/2)^6/720 + 1
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted, unless for course participation, in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the Publisher and/or Author. Contact the American Institute of Aeronautics and Astronautics, Professional Development Programs, Suite 500, 1801 Alexander Bell Drive, Reston, VA 20191-4344. 27 out of 30
Engineering Computations and Modeling in MATLAB/Simulink
Riemann Sums Calculator >> syms x >> rsums(sin(pi*x))
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted, unless for course participation, in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the Publisher and/or Author. Contact the American Institute of Aeronautics and Astronautics, Professional Development Programs, Suite 500, 1801 Alexander Bell Drive, Reston, VA 20191-4344. 28 out of 30
Engineering Computations and Modeling in MATLAB/Simulink
Function Calculator funtool
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted, unless for course participation, in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the Publisher and/or Author. Contact the American Institute of Aeronautics and Astronautics, Professional Development Programs, Suite 500, 1801 Alexander Bell Drive, Reston, VA 20191-4344. 29 out of 30
Engineering Computations and Modeling in MATLAB/Simulink
Taylor Series Calculator taylortool taylortool('f')
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted, unless for course participation, in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the Publisher and/or Author. Contact the American Institute of Aeronautics and Astronautics, Professional Development Programs, Suite 500, 1801 Alexander Bell Drive, Reston, VA 20191-4344. 30 out of 30
Engineering Computations and Modeling in MATLAB/Simulink
The End of Chapter 7
Questions?
Top Related