solve differential equation by method of undetermined coefficient
22 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
madhan ravi
2018-12-13
编辑:madhan ravi
2018-12-13
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 个评论
madhan ravi
2018-12-13
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
2018-12-13
if you use fplot then replace all the ezplots with:
fplot({x1(t),x2(t),x3(t)})
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!