error using ode23
Show older comments
These are my errors im not sure what is causing it.
Error in odearguments (line 90) f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode23 (line 114) odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
code for ode(where t is a vector I've defined as linspace(0,0.2,10000)):
options=odeset('Maxstep', 1e-5);
[t,x]= ode23(@boost,[0:1e-7:0.2], [0 0], options);
3 Comments
Star Strider
on 21 Jan 2018
Please post the code for your ‘boost’ ODE function. That could be where the problem is.
Adam Makin
on 21 Jan 2018
Adam Makin
on 21 Jan 2018
Answers (1)
Star Strider
on 21 Jan 2018
0 votes
You have not passed ‘T’ and ‘d’ to ‘boost’ as extra parameters, nor have you defined them in the function. Since ‘boost’ is not an anonymous function, it will not get them from your workspace. You have to pass them as extra arguments if you want ‘boost’ (and ‘pwm’) to use them.
I cannot run your code to test it, since I do not have the ‘pwm’ function. I cannot find it in the current online documentation.
That aside, assuming that the various conditions in your if blocks create discontinuities, note that the derivatives do not exist at discontinuities, so the ODE integration functions will have significant problems with them.
3 Comments
Adam Makin
on 21 Jan 2018
Star Strider
on 21 Jan 2018
First, using global variables are considered very poor programming practice. It can be extremely difficult to debug code that uses them. Other functions can alter them internally, creating chaos in your code.
Second, functions have their own workspaces, so unless you also declare them as global in the functions, the functions do not know they exist.
So instead, pass them as arguments to your functions, so you know what values your functions are receiving, and you know that they are receiving the values.
@Adam Makin: Both of the methods described here are much more reliable than using global variables:
Categories
Find more on Programming 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!