Error with Loop Martix formation

조회 수: 2 (최근 30일)
Cameron Paterson
Cameron Paterson 2021년 11월 26일
답변: Rishabh Singh 2021년 11월 29일
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

채택된 답변

Rishabh Singh
Rishabh Singh 2021년 11월 29일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by