I defined a function that should give me an array with 3 elements, but when I use it it's giving me a lot more than 3.

2 次查看(过去 30 天)
function [t,x,N] = lab1(V0,mu,tf) %V0=10 mu=0.4 tf=1
W=1;
g=32.2;
r=5;
tspan=linspace(0,tf,1000);
x0=[0;V0/r];
param=g/r;
[t,x]=ode45(@EOM,tspan,x0,[],param,mu);
% replace 0 below by the expression of N
N=W*r*x(2) + W*g*cos(x(1));
function g=EOM(t,x,param,mu)
% replace 0 below by the expression of G2
g(1,1)=x(2);
g(2,1)=-mu*x(2)^2 + param*(mu*cos(x(1)) - sin(x(1)));

采纳的回答

Torsten
Torsten 2023-2-5
编辑:Torsten 2023-2-5
Maybe you mean
V0=10;
mu=0.4 ;
tf=1;
[t,x,N] = lab1(V0,mu,tf);
hold on
plot(t,x)
plot(t,N)
hold off
grid on
function [t,x,N] = lab1(V0,mu,tf) %V0=10 mu=0.4 tf=1
W=1;
g=32.2;
r=5;
tspan=linspace(0,tf,1000);
x0=[0;V0/r];
param=g/r;
[t,x]=ode45(@(t,x)EOM(t,x,param,mu),tspan,x0);
% replace 0 below by the expression of N
N=W*r*x(:,2) + W*g*cos(x(:,1));
end
function g=EOM(t,x,param,mu)
% replace 0 below by the expression of G2
g(1,1)=x(2);
g(2,1)=-mu*x(2)^2 + param*(mu*cos(x(1)) - sin(x(1)));
end
If not, you will have to tell us which 3 elements you want to get.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Chemistry 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by