help-octave
[Top][All Lists]
Advanced

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

Re: LSODE Question - External Inputs?


From: Olaf Till
Subject: Re: LSODE Question - External Inputs?
Date: Fri, 24 Feb 2012 22:05:27 +0100
User-agent: Mutt/1.5.20 (2009-06-14)

On Fri, Feb 24, 2012 at 06:43:42AM -0800, damian.harty wrote:
> Hmm, I'm becoming baffled with the included code not being there thing. I
> just pasted it in as plain text last time, and I could see it in my e-mail
> and from inside Nabble...
> 
> Anyway, I think you are understanding what I'm trying to do and I get the
> non-constant calling interval with lsode. 
> 
> In principle I thought it wouldn't be any bother to get my function to
> return more than one variable but what with the anonymous function and
> ISTAGE and MSG variables I can't really work out what the syntax is to
> actually achieve it.
> 
> Inside the file EqMotion.m I have
> 
> function [xdot, ISTATE, MSG] = EqMotion (x,t,m,k,c,u,udot,t_vector)
>  ...
>  Fx=k*(u_now-x(1))+preload
>  ...
> endfunction
> 
> If I add xdot(3)=Fk into it then lsode protests about a dimensional
> mismatch.
> 
> And inside one_dof.m I have
> 
> [x, ISTATE,MSG] = lsode (@ (x,t) EqMotion ((x,t,m,k,c,u,udot,t_vector), x0,
> t);
> 
> So how do I modify the function definition and call to pass back Fk? I want
> to put it on the left hand side but lsode protests again...
> 
> Thanks in advance,
> 
> Damian

Forgive me when I do not dive into the specifities of your example but
try to give a general explanation. First point: EqMotion is supposed
(by lsode) to return only 'xdot', not 'ISTATE' or 'MSG'. But though
lsode only uses 'xdot', you can return additional variables, e.g.:

function [xdot, Fx] = EqMotion (x, t, m, k, c, u, udot, t_vector)

...

Fx = ...;
...
xdot(1) = ...;
xdot(2) = ...;

endfunction

[X, ISTATE, MSG] = \
lsode (@ (x, t) EqMotion (x, t, m, k, c, u, udot, t_vector), x0, T);

Then, call

[xdot_not_needed_now, Fx] = EqMotion (X.', T, m, k, c, u, udot, t_vector);

to get the intermediate result Fx. For this to work, EqMotion must
be able to handle matrices of X and vectors of T. Otherwise,
you must use an ugly loop:

Fx = zeros (size (T));
for id = 1 : length (T)
  [xdot_not_needed_now, Fx(id)] = \
    EqMotion (X(id, :).', T(id), m, k, c, u, udot, t_vector);
endfor

Olaf

-- 
public key id EAFE0591, e.g. on x-hkp://pool.sks-keyservers.net

Attachment: signature.asc
Description: Digital signature


reply via email to

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