# How can I use ODE45 output to evaluate on each time a function inside a the Odefun

3 visualizzazioni (ultimi 30 giorni)
Juan Luis Chacon il 16 Mag 2016
Risposto: Bob il 27 Ott 2016
Hello to everybody
Actually I already have my Quarter vehicle model done using a second Order differential equation f(x, y, xdot, ydot). And it works very good. Let me show you this.
function yp=comportamiento(t,y)
x=f(t)
yp = zeros(4,1);
yp(1)=y(2);
yp(2)= (-((ks+kt)/mw)*y(1)) -((bs/mw)*y(2)) +((ks/mw)*y(3)) + ((bs/mw)*y(4)) + ((kt/mw)*x);
yp(3)=y(4);
yp(4)= ((ks/mb)*y(1)) +((bs/mb)*y(2)) - ((ks/mb)*y(3)) - ((bs/mb)*y(4));
Applying my ode45 fun
tspan=[0:0.001:10];
y0=zeros(4,1);
[t, y] = ode45('comportamiento',tspan,y0);
Results are good. But now, problem is that I need to use a new function. One that looks like f(x, y, xdot, ydot, m(xdot,ydot)). During the calculation each xdot and ydot correspond to y(i1) and y(i2) generated from ODE45, I will need to call another function m(xdot,ydot) using as input every y(i). In others words I don't know how get those y(i) and how to use the to eval my f(x, y,xdot,ydot, m(xdot,ydot)).
I am sure I will need to open a new fun
function odefun=(y(i1),y(i2))
where do I have to indicate that
y(i1)= xdot;
y(i2)=ydot;
mf=m(xdot,ydot)
end
Regards
J.L
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (2)

Juan Luis Chacon il 9 Giu 2016
Finally I got it!!!
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Bob il 27 Ott 2016
Dear Juan Luis Chacon,
Yours sincerely, Xaris
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Ordinary Differential Equations in Help Center e File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by