Chapter 7. Symbolic Math Toolbox - Faculty.nps.edu

Transcription

Chapter 7. Symbolic Math ToolboxAll 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 ofAeronautics and Astronautics, Professional Development Programs, 12700 Sunrise Valley Drive, Suite 200, Reston, VA 20191-5807.1 out of 27Engineering Computations and Modeling in MATLAB/Simulink

Outline 7.1 Introduction7.2 Symbolic Math Toolbox Overview7.3 Getting Started7.4 Basic Operations7.5 Linear Algebra and Calculus7.6 Solving Algebraic and Differential Equations7.7 Simplification and Substitution7.8 Other Functions7.9 Plotting Symbolic Expressions7.10 Using Symbolic Expressions in Numerical Operations7.11 LaTeX Representation of Symbolic Expression7.12 Symbolic Calculators7.13 Units of Measurements in Symbolic Math Toolbox (optional)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 ofAeronautics and Astronautics, Professional Development Programs, 12700 Sunrise Valley Drive, Suite 200, Reston, VA 20191-5807.2 out of 27Engineering Computations and Modeling in MATLAB/Simulink

SMT HistoryOriginally, the computational engine underlying theSymbolic Math toolbox was the Maple kernel,developed at the University of Waterloo in Canada.Before R2007b, the Basic Symbolic Math toolboxincluded in the Student Version was a collection ofmore than a hundred MATLAB functions allowingaccess to the functions in Maple’s linear algebrapackage. The Extended Symbolic Math toolboxaugmented the basic toolbox by including access tonon-graphics packages, programming features anduser defined procedures in Maple.As of R2007b , Symbolic Math Toolbox - now a singleproduct - uses the MuPAD computational engine,originally developed by the MuPAD research group atthe University of Paderborn, Germany. Thefunctionality of the MuPAD language, together withincluded libraries, goes far beyond that of the previousSymbolic Math Toolbox software. The functionality ofExtended Symbolic Math Toolbox has been taken overby 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 ofAeronautics and Astronautics, Professional Development Programs, 12700 Sunrise Valley Drive, Suite 200, Reston, VA 20191-5807.3 out of 27Engineering Computations and Modeling in MATLAB/Simulink

Areas Supported by SMTSubjectAreas SupportedLinear AlgebraInverses, determinants, eigenvalues, singular value decomposition, canonicalforms of symbolic matricesCalculusDifferentiation, integration, limits, summation, and Taylor seriesSolving (Systems of) EquationsSymbolic and numerical solutions to algebraic and differential equationsFormula Manipulation andSimplificationSimplification or modification of symbolic expressions, substitution of partsof expressionsIntegral TransformsFourier, Laplace, z- transforms and their corresponding inverse transformsPolynomialsCharacteristic and minimal polynomials, coefficients of polynomialsNumbers and PrecisionVariable-precision arithmetic and elementary number-theoretic operationsNumber TheoryModular arithmetic operations and sequences of numbersSpecial FunctionsSpecial functions in applied mathematics such as Airy functions, binomialcoefficients, error functions, Bessel functions, Dirac delta function, Legendrepolynomials, Jacobian, and Chebyschev functionsPlotting Symbolic ExpressionsEasy 2-D and 3-D plotting of symbolic expressionsAll 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 ofAeronautics and Astronautics, Professional Development Programs, 12700 Sunrise Valley Drive, Suite 200, Reston, VA 20191-5807.4 out of 27Engineering Computations and Modeling in MATLAB/Simulink

SMT ExamplesAll 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 ofAeronautics and Astronautics, Professional Development Programs, 12700 Sunrise Valley Drive, Suite 200, Reston, VA 20191-5807.5 out of 27Engineering Computations and Modeling in MATLAB/Simulink

Basic OperationsArithmetic OperationsBasic Operations AdditionceilRound symbolic matrix toward positive infinity-SubtractionconjSymbolic complex conjugate*MultiplicationeqSymbolic equality test.*Array multiplicationfixRound toward zero\Left divisionfloorRound symbolic matrix toward negative infinity.\Array left divisionfracSymbolic matrix elementwise fractional partsimagImaginary part of complex number/Right division./Array right divisionlatexLaTeX representation of symbolic expression Matrix or scalar raised to a powerlog10Logarithm base 10 of entries of symbolic matrix. Array raised to a powerIog2Logarithm base 2 of entries of symbolic matrix’Complex conjugate transposemodSymbolic matrix elementwise modulus.’Real transposeprettyPretty-print symbolic expressionsquoremSymbolic matrix elementwise quotient and remainderrealReal part of imaginary numberroundSymbolic matrix elementwise roundsizeSymbolic matrix dimensionssortSort symbolic vectors or polynomialssymSymbolic numbers, variables, and objectssymsShortcut for constructing symbolic objectssymvarFind symbolic variables in symbolic expression or matrixa sym('a');syms x yY (x a sqrt(x))/ypretty(Y)symvar(Y)Y (x a x (1/2))/yax sqrt(x)-----------yans [ a, x, y] and other functionsAll 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 ofAeronautics and Astronautics, Professional Development Programs, 12700 Sunrise Valley Drive, Suite 200, Reston, VA 20191-5807.6 out of 27Engineering Computations and Modeling in MATLAB/Simulink

Linear Algebra & CalculusLinear AlgebraCalculuscolspaceBasis for column spacediffDifferentiate symbolic expressiondetSymbolic matrix determinantintIntegrate symbolic expressiondiagCreate or extract symbolic diagonalsgradientGradient vector of a scalar functioneigSymbolic eigenvalues and eigenvectorshessianHessian matrix of a scalar functionexpmSymbolic matrix exponentialjacobianJacobian matrixinvSymbolic matrix inverselaplacianLaplacian of a scalar functionjordanJordan canonical formlimitLimit of symbolic expressionnullBasis for null spacesymsumSymbolic summation of seriespolyCharacteristic polynomial of matrixtaylorTaylor series expansionrankSymbolic matrix rank and other functionsrrefReduced row echelon formsvdSymbolic singular value decompositiontrilSymbolic lower triangletriuSymbolic upper triangle and other functionssyms x k adiff(cos(x 2))int(cos(x) 2,0,pi)d (cos( x 2 ))dx cos ( x)dx20limit(sin(x)/x)syms a11 a22 a21 a22inv([a11 a22; a21 a22])limx 0sin( x )x symsum(x k/factorial(k),k,0,inf) k 0xkk!taylor(sin(x-a),x,a,'Order',10) f ( x) n 0f ( n ) (a )( x a )nn!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 ofAeronautics and Astronautics, Professional Development Programs, 12700 Sunrise Valley Drive, Suite 200, Reston, VA 20191-5807.7 out of 27Engineering Computations and Modeling in MATLAB/Simulink

Solving EquationsKey Functionssyms a b c x,syms x y,Symbolic solution of algebraic equationsdsolveSymbolic solution of ordinary differential equationssolving a single equation withrespect to xsolve(a*x 2 b*x c,x)[X,Y] solve([5*x 6*y 8,2*x 3*y 1])syms a x y,[f.x f.y]syms x y,solvef solve([a*x 2 y 2-1,x sqrt(y)-1],[x,y]);solving two equations withrespect to x and ysolving two equations withrespect to x and y[A,b] equationsToMatrix([x 2*y-3,2x 3*y]); z A\balternative approachdsolve('Dx-a*x sin(t)','x(0) 1')DxD2xD3x– the1st-orderderivative– the 2nd-order derivative– the 3rd-order derivativeg dsolve('Dx y','Dy cos(t)','x(0) 1','y(0) 0');[g.x g.y]dsolve('D3x x-1','x(0) 0','Dx(0) 2','D2x(0) 0')obsolete syntaxsyms x(t); D1 diff(x); D2 diff(x,2);dsolve(diff(x,3) x-1,[x(0) 0,D1(0) 2,D2(0) 0])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 ofAeronautics and Astronautics, Professional Development Programs, 12700 Sunrise Valley Drive, Suite 200, Reston, VA 20191-5807.8 out of 27Engineering Computations and Modeling in MATLAB/Simulink

Dynamic Systems Modelingmm22y2(t)k2k1mm11y1(t)A system of differential equations governing anoscillatory motion of two-body mass–spring system on ahorizontal frictionless surfacem1 y1 k1 y1 k2 ( y2 y1 )m2 y2 k2 ( y2 y1 )syms y1(t) y2(t)% Define system parameters (in kg and kg/s/s)m1 1; m2 1; k1 3; k2 2;m1 m2 1kg k1 3kg / s 2 k 2 2kg / s 2% Define equationseqn1 m1*diff(y1,t,2) -k1*y1 k2*(y2-y1);eqn2 m2*diff(y2,t,2) -k2*(y2-y1);% Define initial conditions (in m and m/s)Dy1 diff(y1,t); Dy2 diff(y2,t);y1 1m y1 2 6m / scond [y1(0) 1, Dy1(0) -2*sqrt(6),.y2 2 m y2 6 m / sy2(0) 2, Dy2(0) sqrt(6)];% Find a solutionSol dsolve([eqn1 eqn2],cond);% Plot the results within t [0;10]ssubplot(221), ezplot(Sol.y1,[0 10]), ylabel('y 1(t), m')subplot(223), ezplot(Sol.y2,[0 10]), ylabel('y 2(t), m')subplot(222), ezplot(diff(Sol.y1),[0 10]), ylabel(' \dot{y} 1(t) , m/s','interpreter','latex')subplot(224), ezplot(diff(Sol.y2),[0 10]), ylabel(' \dot{y} 2(t) , m/s','interpreter','latex')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 ofAeronautics and Astronautics, Professional Development Programs, 12700 Sunrise Valley Drive, Suite 200, Reston, VA 20191-5807.9 out of 27Engineering Computations and Modeling in MATLAB/Simulink

For advanced usersThe Full List of EquationSolving FunctionsLinear and Nonlinear Equations and vpasolveConverts a set of linear equations to the matrix formPerforms a functional inverseSolves a linear system of equations given in the matrix formFinds the poles of an expression or functionSolves an equation or system of equations symbolicallySolves an equation or system of equations numericallyOrdinary Differential Equations and SystemsdsolvemassMatrixFormSolves an ordinary differential equation or system of equationsodeFunctionConverts a system of symbolic algebraic expressions to a MATLAB function handle suitable for ode45, ode15s, andother ODE solversodeToVectorFieldConverts higher-order differential equations to systems of the 1st-order differential nciesConverts a system of DAEs to a MATLAB function handle suitable for the ode15i solverExtracts the mass matrix and right side of semi-linear system of differential algebraic equations (DAEs)Differential Algebraic EquationsFinds consistent initial conditions for the 1st-order implicit ODE system with algebraic constraintsSearches for decoupled blocks in systems of equationsFinds an incidence matrix of system of equationsChecks if the differential index of system of equations is lower than 2Extracts the mass matrix and right side of semi-linear system of DAEsConverts a system of the 1st-order DAEs to the equivalent system of differential index 1Converts a system of the 1st-order semi-linear DAEs to equivalent system of differential index 0Reduces a system of higher-order differential equations to equivalent system of the 1st-order differential equationsSimplifies a system of the 1st-order DAEs by eliminating redundant equations and variablesAll 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 ofAeronautics and Astronautics, Professional Development Programs, 12700 Sunrise Valley Drive, Suite 200, Reston, VA 20191-5807.10 out of 27Engineering Computations and Modeling in MATLAB/Simulink

Simplification & Substitutionsyms x yT children(x 2-x*y-y 2)Simplification and SubstitutionchildrenExtracting subexpressions or terms of symbolic expressioncoeffsDetermining coefficients of multivariate polynomialcollectCollecting coefficientscombineCombining the terms of an identical algebraic structurecomposePerforming functional compositionisolateIsolating a variable or expression in equationexpandSymbolic expansion of polynomials and elementary functionsfactorFactorizationhornerHorner nested polynomial representationnumdenExtracting numerator and denominatorlhs, hrsExtracting the left- and right-hand sides of equationrewriteRewriting an expression in terms of another functionT [ -x*y, x 2, -y 2]syms x[c,t] coeffs(16*x 2 19*x 11)c [ 16, 19, 11]t [ x 2, x, 1]syms y(x)f y 2*x y*x 2 y*sin(x) x*y;coefy collect(f,y)simplifyFraction Simplifying symbolic rational expressionscoefy(x) x*y(x) 2 (x sin(x) x 2)*y(x)simpleSearch for simplest form of symbolic expressionsimplifySymbolic simplificationsubexprRewriting a symbolic expression in terms of common subexpressionssyms xsin2tan rewrite(sin(x),'tan')syms xsin2tan (2*tan(x/2))/(tan(x/2) 2 1)y cos(2*x)syms x y rho phi R asimple(y)zdc (x-a) 2 y 2-R 2;syms xzpc subs(zdc,{x,y},{rho*cos(phi),rho*sin(phi)})y cos(2*x); expand(y)simplify(zpc)subsSymbolic substitutionans - R 2 a 2 - 2*cos(phi)*a*rho rho 2ans 2*cos(x) 2 - 1All 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 ofAeronautics and Astronautics, Professional Development Programs, 12700 Sunrise Valley Drive, Suite 200, Reston, VA 20191-5807.11 out of 27The simple function was removed after R2014bEngineering Computations and Modeling in MATLAB/Simulink

Integral & z-TransformsIntegral TransformsfourierFourier integral transformifourierInverse Fourier integral transformztransz-transform transformiztransInverse z-transformlaplaceLaplace transformilaplaceInverse Laplace transform F ( ) F ( z) n 0 f (t )e i t dtf ( n)znF ( s ) f (t )e st dt0 1f (t ) F ( )ei t d 2 1f ( n) F ( z ) z n 1dz , n 1, 2,. 2 i z Rc i f (t ) F ( s )e st dsc i syms a tlaplace(t*exp(-a*t))ans 1/(a s) 2syms w x yilaplace(w/(y 2 w 2),y)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 ofAeronautics and Astronautics, Professional Development Programs, 12700 Sunrise Valley Drive, Suite 200, Reston, VA 20191-5807.12 out of 27Engineering Computations and Modeling in MATLAB/Simulink

Other FunctionsConversionsccodeC code representation of symbolic expressioncharConvert symbolic objects to stringsdoubleConvert symbolic matrix to MATLAB numeric formemlBlockConvert symbolic expression to MATLAB Function blockfortranFortran representation of symbolic expressionint8, int16, int32, int64Convert symbolic matrix to signed integerslatexLaTeX representation of symbolic expressionmatlabFunctionConvert symbolic expression to function handle or filepoly2symPolynomial coefficient vector to symbolic polynomialsingleConvert symbolic matrix to single precisionsym2polySymbolic-to-numeric polynomial conversionuint8, uint16, uint32, uint64Convert symbolic matrix to unsigned integerssyms xf taylor(sin(x),'Order',4)t inline(char(f));t(5)f - x 3/6 xans -15.8333Special FunctionscosintCosine integraldiracDirac deltagammaGamma functionVariable Precision ArithmeticheavisideHeaviside step functiondigitsVariable precision accuracyhyperqeomGeneralized hypergeometricvpaVariable precisian arithmeticlambertwLambert's W functionmfunNumeric evaluation of special mathematical functionmfunlistList special functions for use with mfunsinintSine integralzetaRiemann Zeta and other functionsAll 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 ofAeronautics and Astronautics, Professional Development Programs, 12700 Sunrise Valley Drive, Suite 200, Reston, VA 20191-5807.13 out of 27Engineering Computations and Modeling in MATLAB/Simulink

Easy Plotting Functions(may be removed in the future releases)Easy Visualization Tools &Calculatorssyms r phiezcontourContour plotterezcontourfFilled contour plotterezmesh3D mesh plotterezmeshcCombined mesh and contour plotterezplot2D parametric curve plotterezplot33D parametric curve plotterezpolarPolar coordinate plotterezsurf3D colored surface plotterezsurfcCombined surface and contour plotx r*cos(phi); y r*sin(phi);z 1 besselj(1,3*r)*cos(phi);ezmesh(x,y,z)Graphical CalculatorsfuntoolFunction calculatorrsumsInteractive evaluation of Riemann sumstaylortoolTaylor series calculatorsyms x(t) y(t)g dsolve([diff(x) y,diff(y) cos(t)],[x(0) 1, y(0) 0]);ezplot(g.x,g.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 ofAeronautics and Astronautics, Professional Development Programs, 12700 Sunrise Valley Drive, Suite 200, Reston, VA 20191-5807.14 out of 27Engineering Computations and Modeling in MATLAB/Simulink

z [1 3 4]; x poly(z);Symbolic to Character &Function Handlefs poly2sym(x)fc char(fs)xz fzero(fc,1.82)fa str2func(['@(x)' fc])fplot(fa,[0 5]), gridhold, plot(xz,fa(xz),'rp')fs x 3-8*x 2 19*x-12fc 'x 3-8*x 2 19*x-12'xz 1.0000fa @(x)19*x-8*x 2 x 3-12All 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 ofAeronautics and Astronautics, Professional Development Programs, 12700 Sunrise Valley Drive, Suite 200, Reston, VA 20191-5807.15 out of 27Engineering Computations and Modeling in MATLAB/Simulink

Symbolic to Inline Functionsyms t1fsym cos(t)*exp(t)ezplot(fsym)% it works! :-)2xmin fminsearch(fsym,3) % it doesn’t work :-(3finl inline(char(fsym))xmin fminsearch(finl,3) % it works now :-)hold, plot(xmin,finl(xmin),'rp')fsym exp(t)*cos(t)2 Error using fcnchk (line 107)If FUN is a MATLAB object, it must have an feval method.Error in fminsearch (line 173)funfcn fcnchk(funfcn,length(varargin));13finl Inline function:finl(t) exp(t)*co(t)xmin 3.9270Current plot held13All 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 ofAeronautics and Astronautics, Professional Development Programs, 12700 Sunrise Valley Drive, Suite 200, Reston, VA 20191-5807.16 out of 27Engineering Computations and Modeling in MATLAB/Simulink

inline vs. fcnchksyms tfsym cos(t)*exp(t)ezplot(fsym)finl fcnchk(char(fsym)) % fcnchk is equivalent to inlinexmin fminsearch(finl,3) % it works now :-)hold, plot(xmin,finl(xmin),'rp')syms tWhat’s the difference?fsym cos(t)*exp(t);finl fcnchk(char(fsym),'vectorized')finl inline(vectorize(char(fsym)))finl Inline function:finl(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 ofAeronautics and Astronautics, Professional Development Programs, 12700 Sunrise Valley Drive, Suite 200, Reston, VA 20191-5807.17 out of 27Engineering Computations and Modeling in MATLAB/Simulink

hqsyms ps Mq 0.7*ps*M 2;hq matlabFunction(q) @(M,ps)M. 2.*ps.*(7.0./1.0e1)The matlabFunctionFunction M [0.2,0.2,0.6]; ps [101325, 60000, 101325]; hq(M,ps)ans 1.0e 04 *0.28370.16802.5534Creates a functionhandle F to theRotationMatrixfunction saved asRotationMatrix.msyms lat lonRlon [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 n R RotationMatrix(lat,lon)%ROTATIONMATRIX% R ROTATIONMATRIX(LAT,LON)% 13-Nov-2018 19:59:41t2 cos(lat);t3 sin(lon);t4 cos(lon);t5 sin(lat);R .0,t2],[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 ofAeronautics and Astronautics, Professional Development Programs, 12700 Sunrise Valley Drive, Suite 200, Reston, VA 20191-5807.18 out of 27Engineering Computations and Modeling in MATLAB/Simulink

LaTeX Representation ofSymbolic 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)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 H1 latex(F1); H2 latex(F2); H4 latex(F4); H5 latex(F5); text(0.2,0.25,[' ' H1 ' '],'interpreter','latex','fontsize',14) text(0.6,0.2, [' ' H2 ' '],'interpreter','latex','fontsize',16) text(0.3,0.5, [' ' H4 ' '],'interpreter','latex','fontsize',18) text(0.1,0.8, [' ' H5 ' '],'interpreter','latex','fontsize',14)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 ofAeronautics and Astronautics, Professional Development Programs, 12700 Sunrise Valley Drive, Suite 200, Reston, VA 20191-5807.19 out of 27Engineering Computations and Modeling in MATLAB/Simulink

For advanced usersUsing odeToVectorFieldFunction%% Define the 4th-order ODEsyms y(t)eqn diff(y,4) 2*diff(y,2)-10*y*diff(y);y ( iv ) 2 y 10 yy 0%% Rewrite equation into state space[V,S] odeToVectorField(eqn)odefun matlabFunction(V,'vars',{'t','Y'})V Y[2]Y[3]Y[4]10*Y[1]*Y[2] - 2*Y[3]S yDyD2yD3yY1 Y2( y )Y2 Y3( y )Y3 Y4( y )Y4 2Y3 10Y1Y2( 2 y 10 yy )odefun @(t,Y)[Y(2);Y(3);Y(4);Y(3).*-2.0 Y(1).*Y(2).*1.0e1]%% Integrate numerically within 0 t 2sinitConditions [0,-3,5,-3]; % set initial conditionsode23(odefun,[0,2],initConditions)grid, xlabel('Time, s'), ylabel('Solution')legend(' x(t) ',' \dot{x}(t) ',' \ddot{x}(t) ',' x {(iii)}(t) ',13)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 ofAeronautics and Astronautics, Professional Development Programs, 12700 Sunrise Valley Drive, Suite 200, Reston, VA 20191-5807.20 out of 27Engineering Computations and Modeling in MATLAB/Simulink

For advanced usersUsing odeFunctionFunction to Create a Handle%%%% Define the 4th-order ODEsyms y(t)eqn diff(y,4) 2*diff(y,2)-10*y*diff(y);%% Rewrite ODE as a system of 1st-orderODEs[eqs,vars] reduceDifferentialOrder(eqn,y)%% Find the mass matrix M and the righthand sides of equations% M(t,x(t),\dot{x}(t) F(t,x(t)) [M,F] massMatrixForm(eqs,vars)%% Rewrite the system in the standard form% \dot{x}(t) f(t,x(t)) f M\F%% Convert to a MATLAB function handleodefun odeFunction(f,vars);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 ofAeronautics and Astronautics, Professional Development Programs, 12700 Sunrise Valley Drive, Suite 200, Reston, VA 20191-5807.21 out of 27Engineering 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 ofAeronautics and Astronautics, Professional Development Programs, 12700 Sunrise Valley Drive, Suite 200, Reston, VA 20191-5807.22 out of 27Engineering Computations and Modeling in MATLAB/Simulink

Function Calculator funtoolAll 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 ofAeronautics and Astronautics, Professional Development Programs, 12700 Sunrise Valley Drive, Suite 200, Reston, VA 20191-5807.23 out of 27Engineering 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 ofAeronautics and Astronautics, Professional Development Programs, 12700 Sunrise Valley Drive, Suite 200, Reston, VA 20191-5807.24 out of 27Engineering Computations and Modeling in MATLAB/Simulink

For advanced usersSMT Units of MeasurementsIntroduced in R2017a%%%% Define unitsu symunit;% loading units collectiond 5*u.fps% using foot per secondw 50*u.lbm% using pound masss 10*u.km/u.hr, % using length and time unitss simplify(d)% simplifying to (default) speed unit%% Combine the different-unit valuesd 500*u.m 0.9*u.mi 70*u.ft 157*u.ind simplify(d)% simplifying to (default) single unitd separateUnits(d);% extracting expression with no unitsd double(d)% converting symbolic variable to a doubleprecision number%% Unit conversionslen 1*u.mi;% define 1 statute milelen unitConvert(len,u.inm)% convert to international nautical mileslen unitConvert(len,u.nmile) % convert to British imperial nauticalmileslen unitConvert(len,u.km)% convert to kilometers[len,un] separateUnits(len); % separate units from expressionlen double(len)% convert expression to double typeun% show units%% Convert to SI or U.S. unit systemm 5*u.kg;a 2*u.m/u.s 2;F m*aF unitConvert(F,'SI','Derived')F unitConvert(F,'US')F unitConvert(F,'US','Derived')%% Use units in differential equationssyms V(t) a v0T t*u.s;% time in secondsA a*u.m/u.s 2;% acceleration in meters per secondAll rights reserved. No part eqn1 A diff(V,T)of this publication may be reproduced,%distributed,or transmitted,unless for course participation, in any form or by any means,differentialequationor stored in a database or retrievalsystem, without the prior writtenthe Publisher and/or Author. Contact the American Institute ofcond V(0) v0*u.m/u.s;% perm

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, 12700 Sunrise Valley Drive, Suite 200, Reston, VA 2019