comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Solving system of ODEs backwards in time?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Solving system of ODEs backwards in time? [message #94632] Sun, 30 July 2017 11:37 Go to next message
BLesht is currently offline  BLesht
Messages: 89
Registered: March 2007
Member
I have a system of ODEs describing how a system with N state variables (C) evolves in time. The basic equation set is dC/dt = (W + A dot C) / V in which C is the state variable vector at time i, V is a vector of constants, W is a known vector (a function of t), and A is a known matrix (similarly time variable). Given an initial condition C[0], I've been using LSODE to solve for the successive time steps, updating the initial condition and values of W and A along the way. This has worked well.

Now I'd like to reverse the problem. That is, if I know the value of the state vector at time i, and the values of W and A at time i-1, I'd like to compute the value of the state vector at time i-1. In essence, I want to know what the initial condition had to be to arrive at the current state of the system given known V, W and A.

Frankly, it's been many, many years since I took an ODE class and I wasn't very adept then. I'd greatly appreciate any advice on how to approach this problem.

Thanks, Barry
Re: Solving system of ODEs backwards in time? [message #94640 is a reply to message #94632] Wed, 02 August 2017 07:58 Go to previous messageGo to next message
Markus Schmassmann is currently offline  Markus Schmassmann
Messages: 129
Registered: April 2016
Senior Member
On 07/30/2017 08:37 PM, Barry Lesht wrote:
> I have a system of ODEs describing how a system with N state
> variables (C) evolves in time. The basic equation set is dC/dt = (W
> + A dot C) / V in which C is the state variable vector at time i, V
> is a vector of constants, W is a known vector (a function of t), and
> A is a known matrix (similarly time variable). Given an initial
> condition C[0], I've been using LSODE to solve for the successive
> time steps, updating the initial condition and values of W and A
> along the way. This has worked well.
>
> Now I'd like to reverse the problem. That is, if I know the value of
> the state vector at time i, and the values of W and A at time i-1,
> I'd like to compute the value of the state vector at time i-1. In
> essence, I want to know what the initial condition had to be to
> arrive at the current state of the system given known V, W and A.
>
> Frankly, it's been many, many years since I took an ODE class and I
> wasn't very adept then. I'd greatly appreciate any advice on how to
> approach this problem.

; example inputs
n=10
tt=100
w=randomu(seed,n,tt-1,/double)
a=randomu(seed,n,n,tt-1,/double)
v=randomu(seed,n,/double)*100
c0=randomu(seed,n,/double)

; run it forward
ca=dblarr(n,tt)
ca[*,0]=c0
for i=0,tt-2 do ca[*,i+1]=ca[*,i]+(w[*,i]+a[*,*,i]#ca[*,i])/v

; run it back
cb=dblarr(n,tt)
cb[*,-1]=ca[*,-1]
diag_v=dblarr(n,n)
diag_v[lindgen(n),lindgen(n)]=v
for i=tt-2,0,-1 do cb[*,i]=invert(diag_v+a[*,*,i])#(cb[*,i+1]*v-w[*,i])

; compare results
print, ca[*,0]
print, cb[*,0]



however, if diag_v+A+a[*,*,i] can't be inverted you get nonsense as
result.
So check it by running the inversion forward again

I hope this helps, Markus
Re: Solving system of ODEs backwards in time? [message #94641 is a reply to message #94632] Wed, 02 August 2017 16:50 Go to previous messageGo to next message
BLesht is currently offline  BLesht
Messages: 89
Registered: March 2007
Member
Markus - thank you very much! That appears to be exactly what I was looking for. It will take me a bit to adapt it to my model, but I will let you know if it works.

I very much appreciate your help.

Barry
Re: Solving system of ODEs backwards in time? [message #94650 is a reply to message #94632] Fri, 04 August 2017 08:25 Go to previous messageGo to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On Sunday, July 30, 2017 at 2:37:48 PM UTC-4, Barry Lesht wrote:
> I have a system of ODEs describing how a system with N state variables (C) evolves in time. The basic equation set is dC/dt = (W + A dot C) / V in which C is the state variable vector at time i, V is a vector of constants, W is a known vector (a function of t), and A is a known matrix (similarly time variable). Given an initial condition C[0], I've been using LSODE to solve for the successive time steps, updating the initial condition and values of W and A along the way. This has worked well.
>
> Now I'd like to reverse the problem. That is, if I know the value of the state vector at time i, and the values of W and A at time i-1, I'd like to compute the value of the state vector at time i-1. In essence, I want to know what the initial condition had to be to arrive at the current state of the system given known V, W and A.
>
> Frankly, it's been many, many years since I took an ODE class and I wasn't very adept then. I'd greatly appreciate any advice on how to approach this problem.
>
> Thanks, Barry

Why can't you just use a negative time step in your call to LSODE?
Re: Solving system of ODEs backwards in time? [message #94651 is a reply to message #94650] Fri, 04 August 2017 13:01 Go to previous messageGo to next message
BLesht is currently offline  BLesht
Messages: 89
Registered: March 2007
Member
Hi Craig,

I'm sorry to seem dense, but I don't see how that applies. Perhaps I haven't explained my problem sufficiently, or perhaps I really don't understand the nuances, or maybe I've been misapplying LSODE (or all the above).

I have a system of 19 coupled ODEs. Let C be the 19 element vector representing the state of the system at time point i. The vector of derivatives is dC(i)/dt = (W(i) + A(i) dot C(i)) / V in which W is a 19-element vector that changes at every point i, A is a 19x19 "transfer" matrix expressing the couplings among the state variables (many zeros) but which also changes at every point i, and V is a 19-element constant vector. Given an initial condition C0, I have been been using LSODE is advance the solution from time i to time i+1 (calculating C(i+1) using a time step of i/4. I repeated those steps for the desired number of i steps.

This seems to work (at least provides answers that agree well with observations) going forward. What I want to do now is start with a known state at time i, and sets of known W vectors and A matrices for times i-1, i-2, ... i-n and find what C(i-n) would have had to be to result in the observed C(i) given that set of W vectors and A matrices.

What confused me when I was trying to set this up myself was that the state at time i, depends on both the state at time i-1 and the derivatives based on the state at time i-1. That is, the derivative at time i-1 can't be computed without knowing the state at time i-1 because of the A dot C term.

Thanks, Barry
Re: Solving system of ODEs backwards in time? [message #94653 is a reply to message #94651] Fri, 04 August 2017 14:33 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On Friday, August 4, 2017 at 4:01:13 PM UTC-4, Barry Lesht wrote:
...
> This seems to work (at least provides answers that agree well with observations) going forward. What I want to do now is start with a known state at time i, and sets of known W vectors and A matrices for times i-1, i-2, ... i-n and find what C(i-n) would have had to be to result in the observed C(i) given that set of W vectors and A matrices.

I'm just saying, LSODE takes a "step" parameter, H, and that parameter can be negative as well as positive. It's just as easy to integrate backward in time as it is to integrate forward in time.

Craig
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: IDL 8.6.1 and ENVI 5.4 SP1 now available
Next Topic: Re: FFT confusion

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 09:14:02 PDT 2025

Total time taken to generate the page: 0.00554 seconds