help-octave
[Top][All Lists]
Advanced

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

## Re: LSODE Question - External Inputs?

 From: damian.harty Subject: Re: LSODE Question - External Inputs? Date: Fri, 24 Feb 2012 05:40:47 -0800 (PST)

```I don't mind the code I have now unless there is some particular reason it
isn't preferred?

However, I do have a new quest (same model) which is to pass back some of
the intermediate variables.

I've re-organised the code a bit to give myself a spring preload and a
gravity force, this allows me to branch when the force gets to zero and let
the system go airborne. It works just fine (as I said I am migrating
calculations from another environment so I have a reference solution to
which I can compare) but I would like to be able to retrieve time histories
from inside the function, say for Fk and Fc:

function [x, ISTATE, MSG] = EqMotion (x, t, m, k, c, u, udot, t_vector)
u_now=interp1(t_vector,u,t);
udot_now=interp1(t_vector,udot,t);
xdot(1) = x(2);
preload = m*9.81;
Fk = k*( u_now-x(1) ) + preload;
if (Fk > 0.)
Fc = c*( udot_now-x(2) );
else
Fk = 0;
Fc = 0;
endif
xdot(2) = Fk/m + Fc/m - 9.81;
endfunction

Any suggestions to retrieving Fk & Fc as a function of t from the main
routine (below)?

m =   100; % kg
k = 10000; % N/m
c =   200; % Ns/m
endtime=4.0;
srate=200;
x0 = [0; 0];
t = linspace (0, endtime, srate*endtime)';
t_vector=t;
u=t*0;
u(2:50)=0.3;
udot=diff(u);
udot(srate*endtime)=udot(srate*endtime-1);
udot=udot*srate;
[x, ISTATE, MSG] = lsode (@ (x,t) EqMotion (x,t,m,k,c,u,udot,t_vector), x0,
t);

Obviously I could recalculate them using x but I was hoping to retrieve them
from the integrator, otherwise I have to update the same calculations in two
places, which feels like a bad idea. Unless I use (drum roll) a function
file, I suppose...

Damian

-----
Senior Research Fellow - Vehicle & System Dynamics
Coventry University
United Kingdom
--
View this message in context:
http://octave.1599824.n4.nabble.com/LSODE-Question-External-Inputs-tp4414228p4417207.html
Sent from the Octave - General mailing list archive at Nabble.com.

```

reply via email to

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