Iteration repeat several times

4 views (last 30 days)
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 Comments
Ismail Faruk DENIZ
Ismail Faruk DENIZ on 29 Jul 2022
Disksayisi mean number of disc. ı forget to change its language.

Sign in to comment.

Accepted Answer

Jan
Jan on 29 Jul 2022
Edited: Jan on 29 Jul 2022
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 Comments
Ismail Faruk DENIZ
Ismail Faruk DENIZ on 30 Jul 2022
Edited: Ismail Faruk DENIZ on 30 Jul 2022
W means natural frequency for vibrations and TT mean torque. The code should find to Wn value that makes TT5, TT4 or TT3 to zero or in range. Wn is minumum value, WnF is maximum value. I define because ı wanna to know what happens in the specific values range. Briefly, The code give me to Wn value to makes Total Torque(3,4,5) to zero. Zero is best answer for code but Torque can be near zero such as -10000< TT<10000.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!