Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why do I receive an error about an undefined variable or the recursion limit when calling ODE45?

0
10 Posted

Why do I receive an error about an undefined variable or the recursion limit when calling ODE45?

0
10

One common cause of an “Undefined function or variable” error or an error about the RecursionLimit being exceeded when using an ODE solver like ODE45 is that the function being called by the ODE solver itself contains the call to the ODE solver. For instance, if your code is: function dy = myodefunction(t, y) dy = [y(2); 2*t]; y0 = [0; 1]; tspan = [0 10]; [t, y] = ode45(@myodefunction, y0, tspan); If you call myodefunction with no inputs, you will receive an error on the second line, where MATLAB tries to use t and y to define dy. If you call myodefunction with two inputs, it will proceed without error to the ODE45 call. ODE45 will call myodefunction with two inputs, and that call will proceed without error to the ODE45 call. This process will repeat until ODE45 has recursively call myodefunction a number of times equal to the root RecursionLimit property, at which point MATLAB will throw an error. To avoid these errors, do not include the call to the ODE solver inside your ODE functio

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123