5

I use ode45 to solve differential equations but the tspan always has to be such that the system runs forward in time. Can I make ode45 run the system backwards to negative t?

The specific problem I have uses a rising exponential function i.e a*exp(at) from t=-infinity to t=0 and the function is zero for all t>0. As you can see, it isn't possibly to translate this function and use the interval t=0 to t=infinity in my problems. So, I would like ode45 to work in negative t.

Thank you!

EDIT: After some thinking, I realize that my question is phrased badly and I had a poor understanding too so let me restate it here.

My ODEs are of the form x'=f(t)x, where f(t)=a*exp(at) from -infinity to 0. The system starts with some intial conditions at t=-infinity. ode45 on the other hand requires tspan to be positive and also requires the initial conditions at t=0. So how can I change both these criteria?

Thank you :)

user1936752
  • 756
  • 1
  • 9
  • 25
  • 5
    Why not substitute `-t` with a new time variable, say `s`, and obtain a new differential equation for `s`, solve it for `s` and then substitute `t` back into the solution? – Eitan T Jan 03 '13 at 16:45
  • No, you see that won't work for the function I have shown. a*exp(-as) from 0 to infinity is not the same as a*exp(at) from -infinity to 0. I don't think it's possible to "translate" this function to the positive t interval. – user1936752 Jan 03 '13 at 18:11
  • 4
    but a*exp(-as) from infinity to 0 is the same as a*exp(at) from -infinity to 0 – Rasman Jan 03 '13 at 18:37
  • Hi Rasman, So, what would tspan be? [infinty:0]? I tried this with ode45. I tried just [2:0] and it gave me an error. What we are trying is essentially trying to run backward in time, isn't it? Unfortunately, it didn't work so could you suggest an alternative? – user1936752 Jan 05 '13 at 09:15
  • not sure if i'm thinking straight, but if you substitute t over [-inf, 0] with s = (-1/t) for s = [0, inf], does that work? – gauteh Jan 21 '13 at 13:55

1 Answers1

0

Use a backwards linspace for generating your t.

For the forward direction (t), use something like t = 0:0.1:2. For the reverse direction (rt), use something like rt = 2:0-.1:0.

JesseBikman
  • 632
  • 1
  • 5
  • 22