Filter löschen
Filter löschen

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.

1 Ansicht (letzte 30 Tage)
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)));

Akzeptierte Antwort

Torsten
Torsten am 5 Feb. 2023
Bearbeitet: Torsten am 5 Feb. 2023
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.

Weitere Antworten (0)

Kategorien

Mehr zu Chemistry finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by