How to find trajectory of an internal variable while solving a diff equation using an ODE solver? (pls read details)
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Star Strider
2015 年 5 月 24 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!