Page 498 - Applied Numerical Methods Using MATLAB
P. 498
SOLVING DIFFERENTIAL EQUATIONS 487
Besides, other MATLAB functions such as jordan(A) and svd(A) can be
used to get the Jordan canonical form together with the corresponding similarity
transformation matrix and the singular value decomposition of a symbolic matrix.
G.4 SOLVING ALGEBRAIC EQUATIONS
We can use the backslash (\) operator to solve a set of linear equations written
in a matrix–vector form.
>>syms R11 R12 R21 R22 b1 b2
>>R = [R11 R12; R21 R22]; b = [b1; b2];
>>x=R\b
x = [ (R12*b2 - b1*R22)/(-R11*R22 + R21*R12)]
[ (-R11*b2 + R21*b1)/(-R11*R22 + R21*R12)]
We can also use the MATLAB function solve() to solve symbolic algebraic
equations.
>>syms abcx
>>fx = a*x^2+b*x+c;
nd
>>solve(fx) %formula for roots of 2 -order polynomial eq
ans = [ 1/2/a*(-b + (b^2 - 4*a*c)^(1/2))]
[ 1/2/a*(-b - (b^2 - 4*a*c)^(1/2))]
>>syms x1 x2 b1 b2
>>fx1 = x1 + x2 - b1; fx2 = x1 + 2*x2 - b2; %a system of simultaneous algebraic eq.
>>[x1o,x2o] = solve(fx1,fx2) %
x1o = 2*b1 - b2
x2o=-b1+b2
G.5 SOLVING DIFFERENTIAL EQUATIONS
We can use the MATLAB function dsolve() to solve symbolic differential
equations.
>>syms abcx
>>xo = dsolve(’Dx + a*x = 0’) % a differential eq.(d.e.) w/o initial condition
xo = exp(-a*t)*C1 % a solution with undetermined constant
>>xo = dsolve(’Dx + a*x = 0’,’x(0) = 2’) % a d.e. with initial condition
xo = 2*exp(-a*t) % a solution with undetermined constant
>>xo = dsolve(’Dx=1+x^2’) % a differential eq. w/o initial condition
xo = tan(t - C1) % a solution with undetermined constant
>>xo = dsolve(’Dx=1+ x^2’,’x(0) = 1’) % with the initial condition
xo = tan(t + 1/4*pi) % a solution with determined constant
nd
>>yo = dsolve(’D2u = -u’,’t’)%a2 -order d.e. without initial condition
yo = C1*sin(t) + C2*cos(t)
>>xo = dsolve(’D2u = -u’,’u(0) = 1,Du(0) = 0’,’t’) % with the initial condition
xo = cos(t))
st
>>yo = dsolve(’(Dy)^2 + y^2 = 1’,’y(0) = 0’,’x’)%a1 -order nonlinear d.e.(nlde)
yo = [ sin(x)] %two solutions
[ -sin(x)]
md
>>yo = dsolve(’D2y = cos(2*x) - y’,’y(0) = 1,Dy(0) = 0’,’x’)%a2 -order nlde
yo = 4/3*cos(x) - 2/3*cos(x)^2 + 1/3
>>S = dsolve(’Df=3*f + 4*g’,’Dg=-4*f + 3*g’);

