Error with Loop Martix formation

1 view (last 30 days)
I have been trying to alter this code so that if it is a bumpy road 4s or 10s it will form 1x201 martix beginning at t=0 and ends at t=T and them solve the y_R equation
T= both 10s bumpy road and 4s single bump
L= 6;
g=9.81;
V=35;
y_0=10;
w_R=(2.*pi.*V)/L;
yfail=0;
for y=1:3
Road=input('Enter the simulation type as a number (1=bumpy road, 2=single bump)');
if Road==1
fprintf('10s bumpy road\n')
Y_R=y_0.*.5.*sind(w_R.*t);
elseif Road==2
fprintf('4s single bump\n')
Y_R=y_0.*-1;
else
fprintf('Simulation type is not recognized. The program stops.Rerun the program again.\n')
yfail=yfail+1;
end
end

Accepted Answer

Rishabh Singh
Rishabh Singh on 29 Nov 2021
Hey Cameron,
If you wish to generate "1x201" data, by varying the value of t, from t=0 to t=T. I would suggest you to use linespace function.
T= 10;%both 10s bumpy road and 4s single bump
L= 6;
g=9.81;
V=35;
y_0=10;
w_R=(2.*pi.*V)/L;
yfail=0;
for y=1:3
Road=input('Enter the simulation type as a number (1=bumpy road, 2=single bump)');
if Road==1
fprintf('10s bumpy road\n')
t=linspace(0,T,201); %depeding upon the value of T you can solve Y_R for different values of "t".
Y_R=y_0.*.5.*sind(w_R.*t);
elseif Road==2
fprintf('4s single bump\n')
Y_R=y_0.*-1;
else
fprintf('Simulation type is not recognized. The program stops.Rerun the program again.\n')
yfail=yfail+1;
end
end
Hope this helps.

More Answers (0)

Tags

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!