How to use wrapTo2Pi in user defined function which will be solved by ode45?

7 vues (au cours des 30 derniers jours)
Cenk Demir
Cenk Demir le 9 Oct 2017
Modifié(e) : Jan le 10 Oct 2017
I have systems of ODE which is
function dxdt = dyn(t,x)
dxdt=[((-x(2))/b)+(x(1)*(x(3)+x(2))/2))
wrapTo2Pi(a*x(1))
(d*x(1)*x(3))];
To solve this system;
[T,X] = ode45(@dyn, [0:0.0005:90], x0);
When I work on this problem, wrapTo2Pi function did not work. For x(2), I can see numbers which are bigger than 2*pi. Is there any way to use wrapTo2Pi in this format?
Note: These ODE system, initial condition and time properties are only sample to show my problem.
  1 commentaire
dpb
dpb le 9 Oct 2017
I'd guess it'll foul things up, but you can try wrapping each x inside the call; you've only done one of three here...

Connectez-vous pour commenter.

Réponse acceptée

Torsten
Torsten le 10 Oct 2017
Modifié(e) : dpb le 10 Oct 2017
You solve dx(2)/dt = wrapTo2Pi(a*x(1)), not x(2)-wrapTo2Pi(a*x(1))=0. So of course, x(2) can become larger than 2*pi.
Best wishes
Torsten.
  1 commentaire
dpb
dpb le 10 Oct 2017
Modifié(e) : dpb le 10 Oct 2017
I'm guessing trying to wrap phase during the solution will wreak havok with the discontinuities introduced--probably better solution would be to do the solution and then unwrap phase when done. Can always try and see what happens, of course...
PS. Added the missing capital T in the wrapTo2Pi() functions, Torsten...dpb

Connectez-vous pour commenter.

Plus de réponses (1)

Jan
Jan le 10 Oct 2017
Modifié(e) : Jan le 10 Oct 2017
ODE45 cannot handle discontinuities. The step size controller will either stop the integration with an error or even worse reduce the step size until the discontinuity is concealed by rounding errors. Then the result can be dominated by rounding errors. See http://www.mathworks.com/matlabcentral/answers/59582#answer_72047.
I can see numbers which are bigger than 2*pi
This is not clear enough: Which values are bigger? While dxdt(2) cannot be larger, x(2) can of course.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by