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 Center および File ExchangeMRI についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by