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)

回答(1 个)

kausalya lakshmanan
use function [u dx] instead of function dx the value will save in workspace

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by