MATLAB Using ode45 in a for Cycle: Adding Parameters to odefun

Click For Summary
To run a for loop with ode45 in MATLAB while varying parameters in each iteration, it is necessary to pass additional input parameters to the odefun function. The standard ode function typically only accepts time (t) and state variables (y) as inputs. To include more parameters, one approach is to create a wrapper function that captures the additional parameters using nested functions or anonymous functions. This allows the odefun to access the varying parameters during each iteration of the loop, enabling the solution of the differential equation with different parameter values effectively.
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