Page 495 - Applied Numerical Methods Using MATLAB
P. 495
484 SYMBOLIC COMPUTATION
>>symsabxnt
>>diff(x^n))
ans = x^n*n/x
>>simplify(ans)
ans = x^(n - 1)*n
>>f = exp(a*x)*cos(b*t)
>>diff(f) %equivalently diff(f,x)
d d
ans = a*exp(a*x)*cos(b*t) % f = e ax cos (bt) = ae ax cos (bt)
dx dx
>>diff(f,t)
d d
ans = -exp(a*x)*sin(b*t)*b % f = e ax cos (bt) =− be ax sin (bt)
dt dt
>>diff(f,2) %equivalently diff(f,x,2)
d 2
2 ax
ans = a^2*exp(a*x)*cos(b*t) % f = a e cos (bt)
dx 2
>>diff(f,t,2)
d 2
ans = -exp(a*x)*cos(b*t)*b^2 % f =−e ax cos (bt)b 2
dt 2
>>g = [cos(x)*cos(t) cos(x)*sin(t)];
>>jacob g = jacobian(g,[x t])
jacob g = [ -sin(x)*cos(t), -cos(x)*sin(t)]
[ -sin(x)*sin(t), cos(x)*cos(t)]
Note that the jacobian() function finds the jacobian defined by (C.9)—that is,
T
the derivative of a vector function [g 1 g 2 ] with respect to a vector variable
T
[x t] —as
∂g 1 /∂x ∂g 1 /∂t
J = (G.1)
∂g 2 /∂x ∂g 2 /∂t
G.2.4 Integration
The int() function returns the indefinite/definite integral (anti-derivative) of a
function or an expression with respect to the variable given as its second input
argument or its free variable which might be determined by using the findsym
function.
>>symsaxyt
>>int(x^n)
1
n n + 1
ans = x^(n + 1)/(n + 1) % x dx = x
n + 1
>>int(1/(1 + x^2))
1
ans = atan(x) % dx = tan − 1 x
1 + x 2
>>int(a^x) %equivalently diff(f,x,2)
1
x x
ans = 1/log(a)*a^x % a dx = a
log a
>>int(sin(a*t),0,pi) %equivalently int(sin(a*t),t,0,pi)
1 π 1 1
π
ans = -cos(pi*a)/a + 1/a % sin (at) dt =− cos (at) =− cos (aπ) +
0 a 0 a a

