![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/198913/image.png)
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
![THEeq.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/198912/THEeq.png)
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/198913/image.png)
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!