![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/198913/image.png)
solve differential equation by method of undetermined coefficient
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
madhan ravi
le 13 Déc 2018
Modifié(e) : madhan ravi
le 13 Déc 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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/198913/image.png)
6 commentaires
madhan ravi
le 13 Déc 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
le 13 Déc 2018
if you use fplot then replace all the ezplots with:
fplot({x1(t),x2(t),x3(t)})
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!