Using ode45 in a for Cycle: Adding Parameters to odefun

In summary, ode45 is a function in MATLAB that can be used to numerically solve systems of ordinary differential equations (ODEs). It works by evaluating the ODEs at different time steps and adjusting the step size to maintain accuracy. To use ode45 in a for loop, you need to define the initial conditions and time span for the ODEs, and save the output at each iteration. The parameters that can be added to the ODE function depend on the specific system of equations and can include physical constants, initial conditions, and other variables. The time step for ode45 is automatically adjusted, but you can also specify maximum time step and tolerances for accuracy. While ode45 can be used for stiff systems, it is recommended
  • #1
bnsm
6
0
Hi guys,


I want to run a for cycle with ode45 inside. However, some parameters that I define in odefun (the differential equation in order to dy/dt, for instance) assume different values in each iteration of that cycle.

I find help examples showing odefun only receiving t and y... Is there any way to add more input parameters to odefun?



Thanks!
 
Physics news on Phys.org
  • #2
Anyone?... :smile:
 

What is ode45 and how does it work?

ode45 is a function in MATLAB that can be used to numerically solve systems of ordinary differential equations (ODEs). It is an adaptive Runge-Kutta method that uses a combination of fourth and fifth order formulas to approximate the solution. It works by evaluating the ODEs at different time steps and adjusting the step size to maintain accuracy.

How do I use ode45 in a for loop?

To use ode45 in a for loop, you need to define the initial conditions and the time span for the ODEs. Then, you can use a for loop to iterate through different parameter values and pass them to the ODE function. Make sure to save the output of ode45 at each iteration to analyze the results later.

What are the parameters that can be added to the ODE function?

The parameters that can be added to the ODE function depend on the specific system of equations you are trying to solve. They can include physical constants, initial conditions, and any other variables that affect the behavior of the system. It is important to carefully define and specify these parameters in order to accurately model the system.

How do I choose the appropriate time step for ode45?

The time step for ode45 is automatically adjusted by the function to maintain accuracy. However, you can also specify the maximum time step and the relative and absolute tolerances for the solution. These parameters can be adjusted based on the behavior of the system and the desired level of accuracy.

Can ode45 be used for stiff systems of equations?

Yes, ode45 can be used for stiff systems of equations. However, for better accuracy and efficiency, it is recommended to use a solver specifically designed for stiff systems such as ode15s or ode23s. These solvers use additional techniques to handle the stiffness and may provide more accurate solutions.

Similar threads

  • Programming and Computer Science
Replies
2
Views
896
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • Introductory Physics Homework Help
Replies
5
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
0
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
7
Views
450
  • Atomic and Condensed Matter
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
Replies
7
Views
1K
Back
Top