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

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 件のコメント

dpb
dpb 2017 年 10 月 9 日
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...

サインインしてコメントする。

 採用された回答

Torsten
Torsten 2017 年 10 月 10 日
編集済み: dpb 2017 年 10 月 10 日

0 投票

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 件のコメント

dpb
dpb 2017 年 10 月 10 日
編集済み: dpb 2017 年 10 月 10 日
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

サインインしてコメントする。

その他の回答 (1 件)

Jan
Jan 2017 年 10 月 10 日
編集済み: Jan 2017 年 10 月 10 日
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.

質問済み:

2017 年 10 月 9 日

編集済み:

Jan
2017 年 10 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by