help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: simulating dynamical systems with arbitrary external inputs using ls


From: Scott Kuntze
Subject: Re: simulating dynamical systems with arbitrary external inputs using lsode
Date: Fri, 22 Jun 2007 16:43:34 -0400
User-agent: Thunderbird 1.5.0.12 (X11/20070604)

John W. Eaton wrote:
What do you mean by "exact input"?  You have data at points.  You need
to be able to get values at any time T.  What sort of approximation do
you want for the times in between the data points? Zero order hold? Linear interpolation? Polynomial fit? It's up to you. I don't think
it's exceptionally hard to write code for any of these.

By "exact input" I mean the set of data points collected at a known sampling frequency.

Would it have helped if I had written something like

  function retval = u (t)
    ## This is a zero-order hold function.  TVALS are the switching
    ## times, UVALS are the values of U up until the corresponing
    ## element of tval.
    tvals = [5, 10, 15, Inf];
    uvals = [1, -1, 1, 0];
    idx = find (t < tvals, 1, "first");
    retval = uvals (idx);
  endfunction

instead of using if/elseif/else/endif?

I understand what this function does, but lsode doesn't like something about it... I believe that 'find' is causing troubles, otherwise I would have used the solution I suggested in my first posting i.e.

function retval = u(t)
   tvals = some array
   uvals = some array
   idx = find(t == tvals)
   retval = uvals(idx)
endfunction

I'm not sure we're seeing eye-to-eye here -- let me try another example... If my waveform consisted of a sinusoid, I could write

function retval = u(t)
   retval = sin(w*t)
endfunction

and I could call u(t) directly from the function I'm integrating with lsode.

However, the waveform is arbitrary and comes from a datafile, captured with a known sampling frequency...

I'd like to set t equal to the set of times at which the waveform was captured, and pump the waveform into the function integrated by lsode. There is no interpolation necessary if t corresponds to the times at which 'waveform' was captured.

The waveform might contain many thousands of samples and be entirely arbitrary.

In essence, I want

function retval = u(t)
   retval = waveform(index of t)
endfunction

Again, 'find' is problematic here (or at least it appears to be).

Is that more clear?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]