problem to solve an EDO
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
hi, i'm tring to solve an EDO but i've got this error message : Index exceeds matrix dimensions Error in ==> f_cine at 3 f=abs(y(:,1)-y(:,2)-y(:,3))-sg0 and i don't understand.
Here this is my function describing the system: function dy=f_cine(y,t)
global C1 C2 D1 D2 Q b K n E sig0 ep
f=abs(y(1)-y(2)-y(3))-sg0
if f<0
dy(4)=0
else
dy(4)=(f/K)^n
end
dy(2)=C(1)*dy(5)-D1*y(2)*dy(4)
dy(3)=C(2)*dy(5)-D2*y(3)*dy(4)
dy(5)=sign(y(1)-y(2)-y(3))*dy(4) dy(1)=E*(ep-dy(5)) dy=dy' end
thanks for your help
0 commentaires
Réponse acceptée
Plus de réponses (8)
Colin
le 17 Jan 2013
next to y = zeros(5,1); you should also initiate dy = zeros(5,1); otherwise Matlab does not know of wich size dy is
How does the RHS of your ODE look like?
0 commentaires
Colin
le 17 Jan 2013
This is, what you coded:
y(5)=sign(y(1)-y(2)-y(3))*dy(4)
dy(2)=C1*dy(5)-D1*y(2)*dy(4)
dy(3)=C2*dy(5)-D2*y(3)*dy(4)
dy(1)=E*(ep-dy(5))
dy=dy'
I guess, what you want to have
dy = zeros(5,1);
dy(1)=E*(ep-y(5))
dy(2)=C1*y(5)-D1*y(2)*y(4)
dy(3)=C2*y(5)-D2*y(3)*y(4)
dy(5)=sign(y(1)-y(2)-y(3))*y(4)
Is that correct? If not, please post the mathematical form of your differential equation.
0 commentaires
Colin
le 17 Jan 2013
If I understand this correct, you want to solve an implicit system of differential equations, as for example de/dt is part of your RHS. Maybe you can elliminate that terms by substitution and solve this with ode45.
To solve implict systems of differential equations, have a look to the solver ode15i.
If you have also given de/dt at the final time, you need to solve a boundary value problem, not just an initial value problem. bvp4c for example is a solver, which can solve boundary value problems.
If your method diverges, you should have a closer look to that parts of your differential equations containing sign(). Some methods are using Taylor expansions to integrate the system. If your RHS is not continous differentiable to some order, this might be a problem.
0 commentaires
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!