Iteration repeat several times
1 次查看(过去 30 天)
显示 更早的评论
numberofdisc= input(' Please enter number of disc at your system =');
x = input(' Please enter lower limit for total torque =');
y = input(' Please enter Higer Limit for total torque =');% limit for total torque is recomended zero but if you choose range, The programme can easily calculate.
if disksayisi==3
J1 = input('Please enter first disc of polar moment of inertia(kgm^2)=');
J2 = input ('Please enter second disc of polar moment of inertia (kgm^2)=');
J3 = input ('Please enter third disc of polar moment of inertia (kgm^2)=');
K1 = input ('Please enter first disc of torsional rigidity (Nm/rad)=');
K2 = input ('Please enter second disc of torsional rigidity (Nm/rad)=');
Wn = input (' Please enter beginning frequency value to calculate natural frequency (rad/s)=');
Wnf = input ('Please enter differences between iterasion values=');
Wns = input ('Please enter last value that used in iteration=');
O1 = 1;
O2 = (O1)-(((Wn^2)*(J1)*(O1)/(K1)));
O3 = (O2)-(Wn^2*((J1*O1)+(J2*O2))/K2);
T1 = (J1)*(O1)*(Wn^2);
T2 = (J2)*(O2)*(Wn^2);
T3 = (J3)*(O3)*(Wn^2);
TT1 = T1;
TT2 = TT1 + T2;
TT3 = TT2 + T3;
for K = Wn:Wnf:Wns
if x <= TT3 <= y
for K = Wn:Wnf:Wns
plot(Wn:Wnf:Wns,TT3,'b-')
fprintf(' Result in rad/s = %i\n ',K);
end
end
end
elseif disksayisi==4
J1 = input('Please enter first disc of polar moment of inertia (kgm^2)=');
J2 = input ('Please enter second disc of polar moment of inertia (kgm^2)=');
J3 = input ('Please enter third disc of polar moment of inertia (kgm^2)=');
J4 = input ('Please enter forth disc of polar moment of inertia (kgm^2)=');
K1 = input ('Please enter fisrt disc of torsional rigidity (Nm/rad)=');
K2 = input ('Please enter second disc of torsional rigidity (Nm/rad)=');
K3 = input ('Please enter third disc of torsional rigidity (Nm/rad)=');
Wn = input (' Please enter beginning frequency value to calculate natural frequency (rad/s)=');
Wnf = input ('Please enter differences between iterasion values=');
Wns = input ('Please enter last value that used in iteration=');
O1 = 1;
O2 = (O1)-(((Wn^2)*(J1)*(O1)/(K1)));
O3 = (O2)-(Wn^2*((J1*O1)+(J2*O2))/K2);
T1 = (J1)*(O1)*(Wn^2);
T2 = (J2)*(O2)*(Wn^2);
T3 = (J3)*(O3)*(Wn^2);
T4 = (J4)*(O4)*(Wn^2);O4 = (O3)-((Wn^2/K3)*(J1*O1)+(J2*O2)+(J3*O3));
TT1 = T1;
TT2 = TT1 + T2;
TT3 = TT2 + T3;
TT4 = TT3 + T4;
for K = Wn:Wnf:Wns
if x <= TT4 <= y
for K = Wn:Wnf:Wns
plot(Wn:Wnf:Wns,TT4,'b-')
fprintf(' Result in rad/s = %i\n ',K);
end
end
end
elseif disksayisi==5
J1 = input('Please enter first disc of polar moment of inertia (kgm^2)=');
J2 = input ('Please enter second disc of polar moment of inertia (kgm^2)=');
J3 = input ('Please enter third disc of polar moment of inertia (kgm^2)=');
J4 = input ('Please enter forth disc of polar moment of inertia (kgm^2)=');
J5 = input ('Please enter fifth disc of polar moment of inertia (kgm^2)=');
K1 = input ('Please enter first disc of torsional rigidity (Nm/rad)=');
K2 = input ('Please enter second disc of torsional rigidity (Nm/rad)=');
K3 = input ('Please enter third disc of torsional rigidity (Nm/rad)=');
K4 = input ('Please enter forth disc of torsional rigidity (Nm/rad)=');
Wn = input ('Please enter beginning frequency value to calculate natural frequency (rad/s)=');
Wnf = input ('Please enter differences between iterasion values=');
Wns = input ('Please enter last value that used in iteration=');
O1 = 1;
O2 = (O1)-(((Wn^2)*(J1)*(O1)/(K1)));
O3 = (O2)-(Wn^2*((J1*O1)+(J2*O2))/K2);
O4 = (O3)-((Wn^2/K3)*(J1*O1)+(J2*O2)+(J3*O3));
O5 = (O4)-((Wn^2/K4)*(J1*O1)+(J2*O2)+(J3*O3)+ (J4*O4));
T1 = (J1)*(O1)*(Wn^2);
T2 = (J2)*(O2)*(Wn^2);
T3 = (J3)*(O3)*(Wn^2);
T4 = (J4)*(O4)*(Wn^2);
T5 = (J5)*(O5)*(Wn^2);
TT1 = T1;
TT2 = TT1 + T2;
TT3 = TT2 + T3;
TT4 = TT3 + T4;
TT5 = TT4 + T5;
for K = Wn:Wnf:Wns
if x <= TT5 <= y
for K = Wn:Wnf:Wns
plot(Wn:Wnf:Wns,TT5,'b*')
fprintf(' Result in rad/s = %i\n ',K);
end
end
end
end
BELOW is not code
Please enter number of disc at your system =3
Please enter lower limit for total torque =-9999999
Please enter Higer Limit for total torque =99999999
Please enter first disc of polar moment of inertia(kgm^2)=8
Please enter second disc of polar moment of inertia (kgm^2)=6
Please enter third disc of polar moment of inertia (kgm^2)=4
Please enter first disc of torsional rigidity (Nm/rad)=4000000
Please enter second disc of torsional rigidity (Nm/rad)=2000000
Please enter beginning frequency value to calculate natural frequency (rad/s)=500
Please enter differences between iterasion values=15
Please enter last value that used in iteration=1000
Hi everyone, I am new user of Matlab. I write some codes for project but ı have some problems. If you can help. I am really appreciate. If you enter this value you can show the problem. I am not sure how many times it repeat itself. Also, end of the calculations ı wanna to graph of iteration value but graph is empty.
2 个评论
采纳的回答
Jan
2022-7-29
编辑:Jan
2022-7-29
Avoid including each variable in parentheses. This reduces the readability.
Matlab processes terme from left to right. Then:
if x <= TT4 <= y
performs x <= TT4 are first. This is false or true, which are converted to 0 or 1. In the next setp one of these relations is calculated:
if 1 <= y
% or
if 0 <= y
You mean:
if x <= TT4 && TT4 <= y
It is meaningless, to write nested loops with the same loop counter:
for K = Wn:Wnf:Wns
if x <= TT5 <= y % See above
for K = Wn:Wnf:Wns % Why a 2nd loop?
plot(Wn:Wnf:Wns,TT5,'b*') % And why is this repeated?
fprintf(' Result in rad/s = %i\n ',K);
end
end
end
A simplification with the same result:
plot(Wn:Wnf:Wns, TT5, 'b*')
fprintf(' Result in rad/s = %i\n ', Wn:Wnf:Wns);
3 个评论
Jan
2022-7-30
I do not know, what the code should achieve. Some meaningful comments would be useful.
A pile of input commands makes it much harder to get reproducible results. Prefer to define input values by code instead. Then it is trivial to modify on value or repeat the same calculations again without the need to type all parameters again.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Bodies 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!