solve differential equation by method of undetermined coefficient
Show older comments
so given three differential equations to solve undetermined coefficient given initial solutions. not sure how to add initial condition to code . here what i have so far .
initial conditions are x1(0) = 2 ; x2(0) = 6 x3(0) = 1
A = sym([.9375, 0 , 0; .9375 -.625 0; 0 .625 -75/135])
eig(A)
[V,D]=eig(A)
Id3 = sym([1,0,0;0,1,0;0,0,1])
syms lambda
B = lambda*Id3 - A
p = charpoly(A,lambda)
evs = solve(p)
s = null(evs(1)*Id3-A)
ps = vpa(fsolve(@f,[0;0;0]))
m file is
function [ z] = f( x )
z(1) = (15/16)*x(1)+20;
z(2) = (15/16) *x(1)-(5/8)*x(2);
z(3) = (5/8)*x(2)-(75/135)*x(3);
end

Answers (1)
madhan ravi
on 13 Dec 2018
Edited: madhan ravi
on 13 Dec 2018
tspan=[0 10];
ic=[2;6;1]; %initical conditions
[t,x]=ode45(@myod,tspan,ic);
plot(t,x)
legend('equation 1','equation 2','equation 3')
function z = myod(t,x)
z=zeros(3,1);
z(1) = (15/16)*x(1)+20;
z(2) = (15/16) *x(1)-(5/8)*x(2);
z(3) = (5/8)*x(2)-(75/135)*x(3);
end

6 Comments
madhan ravi
on 13 Dec 2018
z=zeros(3,1); .... what does that mean
madhan ravi
on 13 Dec 2018
It's just store the variable values called preallocation(search google).
madhan ravi
on 13 Dec 2018
ok thank you
madhan ravi
on 13 Dec 2018
Edited: madhan ravi
on 13 Dec 2018
Anytime :) , please when you make a comment respond to the one who posts an answer instead of posting a separate answer , thank you for understanding.
madhan ravi
on 13 Dec 2018
or if you want to symbolic approach then:
syms x1(t) x2(t) x3(t)
dx1dt=diff(x1);
dx2dt=diff(x2);
dx3dt=diff(x3);
eqn1 = dx1dt == (15/16)*x1+20;
eqn2 = dx2dt == (15/16) *x1-(5/8)*x2;
eqn3 = dx3dt == (5/8)*x2-(75/135)*x3;
conds=[dx1dt(0)==2;dx2dt(0)==6;dx3dt(0)==1];
[x1(t),x2(t),x3(t)]=dsolve(eqn1,eqn2,eqn3,conds);
ezplot(x1(t))
hold on
ezplot(x2(t))
ezplot(x3(t))
legend('equation 1','equation 2','equation 3')
madhan ravi
on 13 Dec 2018
if you use fplot then replace all the ezplots with:
fplot({x1(t),x2(t),x3(t)})
Categories
Find more on Common Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!