Using ode45 in a for Cycle: Adding Parameters to odefun

Click For Summary
SUMMARY

This discussion addresses the implementation of the MATLAB function ode45 within a for loop, specifically focusing on how to pass additional parameters to the odefun. Users typically encounter the limitation that ode45 only accepts time (t) and state (y) as inputs. The solution involves using anonymous functions or nested functions to encapsulate the additional parameters, allowing for dynamic parameterization during each iteration of the loop.

PREREQUISITES
  • Familiarity with MATLAB programming
  • Understanding of differential equations
  • Knowledge of the ode45 function in MATLAB
  • Basic concepts of function handles in MATLAB
NEXT STEPS
  • Explore how to create anonymous functions in MATLAB
  • Learn about nested functions in MATLAB for parameter passing
  • Investigate examples of using ode45 with multiple parameters
  • Review MATLAB documentation on function handles and their applications
USEFUL FOR

MATLAB users, particularly those working with numerical simulations of differential equations, researchers, and engineers looking to enhance their modeling capabilities with dynamic parameters in ode45.

bnsm
Messages
6
Reaction score
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
Anyone?... :smile:
 

Similar threads

  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 4 ·
Replies
4
Views
8K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 7 ·
Replies
7
Views
7K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
7K