Save the Values of Variable in a Function to Workspace.

1 visualizzazione (ultimi 30 giorni)
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)

Risposte (1)

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

Community Treasure Hunt

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

Start Hunting!

Translated by