problem to solve an EDO
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
更多回答(8 个)
Colin
2013-1-17
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 个评论
Colin
2013-1-17
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 个评论
Colin
2013-1-17
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!