Save the Values of Variable in a Function to Workspace.
1 回表示 (過去 30 日間)
古いコメントを表示
We need to save the value of vector u in the Workspace
I have the following code, the Function is
function dx = ex3(t,x)
A1=[0 1;17.2941 0];
A2=[0 1;11.0073 0];
B1=[0;-0.1765];
B2=[0;-0.1763];
k1=[-435.7417 -61.7943];
k2=[-400.5752 -61.8642];
mid = [-pi/2 pi/2];
mu1 = tmf(x(1),mid(1),0,mid(2));
mu2 = 1-mu1;
zeta1 = mu1/(mu1 + mu2);
zeta2 = mu2/(mu1 + mu2);
A = (zeta1 * A1 + zeta2 * A2);
b = (zeta1 * B1 + zeta2 * B2);
k = (zeta1 * k1 + zeta2 * k2);
u =-k*x
dx = A*x+b*u;
end
and am using ODE45 to solve it, the code is
x0=[1;0];
tspan=[0:0.1:5];
[t,x]=ode45(@ex3,tspan,x0);
figure
plot(t,x)
0 件のコメント
回答 (1 件)
kausalya lakshmanan
2018 年 5 月 17 日
use function [u dx] instead of function dx the value will save in workspace
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!