Problem with ode45 solver and initial conditions for it
Información
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Mostrar comentarios más antiguos
I'm trying to numerically solve the optimal control problem. When I try to generalize my programm to high order systems I meet the strange problem with ode45.
When the initial conditions is written manually the ode45 correctly solves the problem. But if i taking the initial conditions from WorkSpace or as result of previous programm the solver goes wrong.
Here is the code for checking:
function PSystemSolve(psi0,x0, SysOrder,k)
%Correct working example
X0=[-1.0000 0 1.0000 0.7951];%manually entered initial condition vector
options1=odeset('Events', @odeEvent, 'RelTol',1e-9,'AbsTol',1e-9);
[~,~,TE,XE,IE]=ode45(@NonLinSystem, [0 inf],X0, options1)
%Wrong working example
options1=odeset('Events', @odeEvent, 'RelTol',1e-9,'AbsTol',1e-9);
[~,~,TE,XE,IE]=ode45(@NonLinSystem, [0 inf],[x0 psi0], options1)
function [value, isterminal, direction]=odeEvent(t,x)
global SysOrder k
value=[x(k); x(2*SysOrder)];
isterminal=[1; 0];
direction=0;
function RPF=NonLinSystem(~,x) %The simple system
RPF=[x(2);...
-x(2)+abs(x(4))/x(4);...
0;...
x(4)-x(3)];
I thought that problem is with classes of psi0 and x0, but they are double and all must be clear with solver.
If this information is not enough to answer I'll send the other part of code. I don't do this in first message, beacuse the whole program is very large.
4 comentarios
Walter Roberson
el 19 de Mayo de 2020
Compute
[x0 psi0] - X0
and I suspect you will see some non-zero values due to round-off error in computation. For example, the 1.0000 might really be 1.0000 - 1e-16 or so.
Ivan Khomich
el 19 de Mayo de 2020
Walter Roberson
el 19 de Mayo de 2020
I think we would need the code involved in the ode, and also the exact psi0 and x0 that are needed (either attach a .m or use num2hex() to show their internal representation.)
global SysOrder k
My first assumption is always that problems with code are caused by use of global variables; I find it is not worth debugging anything else until the global variables have been eliminated.
Ivan Khomich
el 5 de Jun. de 2020
Respuestas (1)
Ivan Khomich
el 5 de Jun. de 2020
0 votos
La pregunta está cerrada.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!