How to use wrapTo2Pi in user defined function which will be solved by ode45?
Show older comments
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 Comment
dpb
on 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...
Accepted Answer
More Answers (1)
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.
Categories
Find more on Lengths and Angles in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!