Solve ODE in MATLAB: ode23 vs ode23s Comparison | Code Error Fix

  • MATLAB
  • Thread starter becca1989
  • Start date
  • Tags
    Matlab Ode
In summary, the user is trying to solve an ODE in MATLAB using ode23 and ode23s, but is getting an error message when using ode23. They have shared their code and are looking for help in understanding the cause of the error. The expert suggests checking the documentation and code for any mistakes and reaching out to MATLAB support for further assistance.
  • #1
becca1989
3
0
Hi, I want to solve an ODE in MATLAB using ode23 and ode23s to compare results. I've written a code and it seems to work fine for ode23s, I even tried it for ode 23t and ode45 but for some reason when I use ode23 I get an error message.

This is the code I've been using;

function hode23seg

[T,Y]=ode23(@yprime1,[0 20],1);
[T2,Y2]=ode23s(@yprime1,[0 20],1);
semilogy(T,abs(Y),'bo',T2,abs(Y2),'r*');

function dy=yprime1(t,y)
dy=-30*y;

The error message is

? Error using ==> ode23
Too many input arguments.

Error in ==> hode23seg at 3
[T,Y]=ode23(@yprime1,[0 20],1);

Does anyone have any ideas what's going on?

Thanks
 
Physics news on Phys.org
  • #2
for posting your question in the forum. From looking at your code, it seems like the error is occurring because you are passing in too many input arguments to the ode23 function. The ode23 function only takes in three arguments: the function handle, the time interval, and the initial condition.

In your code, you are passing in a fourth argument, which is causing the error. This could be because you are using a different version of MATLAB or a different syntax. I would suggest checking the documentation for the specific version of MATLAB you are using to make sure you are using the correct syntax for the ode23 function.

Additionally, I would recommend checking your code for any typos or errors that could be causing the issue. It's also a good idea to double check the function handle you are passing in to make sure it is correctly defined and matches the function you are trying to solve.

If you are still having trouble, you can try reaching out to the MATLAB support team for further assistance. They may be able to provide more specific guidance based on your code and version of MATLAB. Good luck with your ODE solving!
 

1. What is the difference between ode23 and ode23s in MATLAB?

ode23 and ode23s are both built-in MATLAB functions used to solve ordinary differential equations (ODEs). The main difference between them is that ode23 is a non-stiff solver, meaning it is better suited for ODEs with smooth solutions, while ode23s is a stiff solver, making it more suitable for ODEs with rapid changes or discontinuities in the solution.

2. Which solver should I use for my ODE problem: ode23 or ode23s?

The choice between ode23 and ode23s depends on the characteristics of your ODE problem. If your ODE has a smooth solution, ode23 is likely to be more efficient and accurate. However, if your ODE is stiff, meaning it has abrupt changes or discontinuities in the solution, ode23s may provide better results.

3. How do I use ode23 and ode23s in MATLAB to solve an ODE?

To use ode23 or ode23s in MATLAB, you need to define your ODE as a function and provide the initial conditions and time span. Then, you can call the respective function with the appropriate inputs to solve the ODE. The output will be a vector of time and solution values.

4. Are there any limitations to using ode23 and ode23s in MATLAB?

Like any solver, ode23 and ode23s have their limitations. They may not be suitable for ODE problems with discontinuous solutions or those that require high precision. In addition, ode23 may struggle with stiff problems, while ode23s may not handle non-stiff problems as efficiently.

5. Can I use ode23 and ode23s in MATLAB to solve systems of ODEs?

Yes, both ode23 and ode23s can be used to solve systems of ODEs in MATLAB. You will need to define your system of equations as a function and provide the initial conditions and time span. The output will be a matrix of time and solution values for each equation in the system.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
823
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
993
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
Back
Top