How to find trajectory of an internal variable while solving a diff equation using an ODE solver? (pls read details)
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
For example I have a differential equation where the forcing function is a function of the states.
x is a variable, p, xd,K1 are constants, t is time
tau= (xd-x)*K1;
dx/dt + px = tau
To find the trajectory of this I can wrap this up in a function and call an ode solver and it would return me an array of X and T .
function xdot=trajectory(t,X)
tau= K1(xd-x);
xdot=tau-p*x;
end
Now to call an ode solver.
[T,X]= ode45(@trajectory,[0 10],[0]) ;
What if I want to find to plot tau and T ?
One method is I can find tau using the values of X and T returned. Is there any simpler way where in I can get tau also as the output( as an array) along with X and T .
0 commentaires
Réponses (1)
Star Strider
le 24 Mai 2015
Your function should be:
function xdot=trajectory(t,x,K1,xd,p)
tau = K1.*(xd-x);
xdot = tau-p.*x;
end
and your ode45 call becomes:
[T,X]= ode45(@(t,x)trajectory(t,x,K1,xd,p),[0 10],[0]) ;
assuming that ‘K1’, ‘xd’, and ‘p’ are scalars and exist in your workspace.
After you have solved your ODE, you have ‘X’, ‘T’, ‘xd’, ‘K1’, and ‘p’ in your workspace, so calculating ‘tau’ is simply:
tau = K1.*(xd-X);
that you can do outside your ODE function.
0 commentaires
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!