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 views (last 30 days)
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)));

Accepted Answer

Torsten
Torsten on 5 Feb 2023
Edited: Torsten on 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.

More Answers (0)

Categories

Find more on Chemistry in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!