% Symbolic Differentiation and Integration Examples
clear
clc
syms x real
'Example 1'
Y=5/sqrt(6-2*x^2+3*x)
'Produces Typeset Output of Symbolic Equation'
pretty(Y) % Produces Typeset Output of Symbolic Equation
ezplot(Y) % Creates a simple default plot of Y vs. x
pause
'Differentiate Y'
W=diff(Y) % Differentiate Y
pause
'Integrate Y'
J=int(Y) % Integrate Y
'Calculate Definite Integral of Y'
J1=int(Y,2,2.5) % Calculate Definite Integral of Y
'Convert Definite Integral to F.P.'
J2=double(J1)
pause
'Differentiate J'
K=diff(J) % Differentiate J
'Symplify the Symbolic Expression of K'
Yn=simple(K) % Symplify the Symbolic Expression of K
pause
'Example 2'
Y=(3*x^2-2*tan(x))*exp(0.1*x)
pretty(Y)
ezplot(Y)
pause
'Differentiate Y'
W=diff(Y)
pause
'Integrate Y'
J=int(Y) % Notice that this integral cannot be solved in closed form
'Notice that this integral cannot be solved in closed form'
'Calculate the Definite Integral of Y'
J1=int(Y,2,2.5) % Definite Integral has no Symbolic Expression
'This Definite Integral has no Symbolic Expression'
J2=double(J1) % It can be calculated numerically!
'It can be calculated numerically using the "double" command'
pause
'Differentiate J'
K=diff(J) % Notice that Matlab has a problem with this derivative
'Notice that Matlab has a problem with this derivative'
'Even when simplified it is not the same as Y'
Yn=simple(K) % Even when simplified it is not the same as Y
pause
'Create a Taylor Series Expansion (order 6) for Y around x=2.25'
TY=taylor(Y,6,2.25) % Create a Taylor Series Expansion (order 6) for Y around x=2.25
'Compute the Definite Integral of Y from its Taylor Series'
J3=int(TY,2,2.5)
'Compare the Integral Result with J2 above'
J3=double(J3) % Compare Integration Result with J2