Matlab ode45 referencing past value

In summary, the conversation revolved around including a parameter in ode45 that represents the difference between the values of y(3) at time t and time t-30 days. The individual asking the question was able to figure out the solution by using a specific equation.
  • #1
yoshig
2
0
I am using ode45, but have a value that is based upon its own past values. I want to be able to include a parameter that equals (y(3) at time t) - (y(3) at time (t- 30days)). Is there a way to include this using ode45?
Thank you in advance!
 
Physics news on Phys.org
  • #2
Could you post some equations to clarify?
 
  • #3
Thanks rsc42,

I have actually figured out what I was looking for. I used Y(3) = Y(ceil(t),1) - Y(ceil(t-30),1)+Y(ceil(t),2)-Y(ceil(t-30),2)). This is because my steps are in increments of 1, and I wanted to subtract past values of y1 and y2.
 

Related to Matlab ode45 referencing past value

1. What is ode45 in Matlab and how does it work?

ode45 is a function in Matlab that can solve ordinary differential equations (ODEs) numerically. It uses a combination of fourth and fifth order Runge-Kutta methods to approximate the solution of the ODE. It takes in the ODE as an input and returns the numerical solution as an output.

2. How do I use ode45 to reference past values in my ODE?

To reference past values in an ODE, you can use the variable tspan which specifies the time interval over which you want to solve the ODE. The first element of tspan is the initial time and the last element is the final time. You can then use the values of the solution at the previous time steps by indexing the solution vector with the corresponding time step.

3. Can I use ode45 to solve ODEs with multiple variables?

Yes, ode45 can solve ODEs with multiple variables. You can specify the ODE as a system of first-order equations and provide an initial condition for each variable. The output of ode45 will then be a matrix with each column representing the solution for one variable at each time step.

4. How can I improve the accuracy of ode45 for my ODE?

There are a few ways to improve the accuracy of ode45 for your ODE. One way is to decrease the value of the error tolerance, which can be specified as an input to the function. You can also try using a different solver, such as ode23 or ode113, to see if it gives more accurate results. Additionally, you can try adjusting the time step by specifying a finer grid of time points using the tspan variable.

5. Can ode45 handle stiff ODEs?

Yes, ode45 can handle stiff ODEs by using a variable time step. It will automatically adjust the time step size to better capture the behavior of the stiff ODE. However, for highly stiff ODEs, it may be more efficient to use a dedicated stiff solver, such as ode15s or ode23s, which are also available in Matlab.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
723
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Introductory Physics Homework Help
Replies
5
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Back
Top