how to plot values that are used in iteration

2 Ansichten (letzte 30 Tage)
Ismail Faruk DENIZ
Ismail Faruk DENIZ am 9 Aug. 2022
Beantwortet: Ishu am 1 Sep. 2023
numberofdisc= input('please enter number of disc in your system=');
x = input('please enter lower value of total torque=');
y = input('please enter higher value of total torque=');
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=');
if numberofdisc == 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)=');
for K = Wn:Wnf:Wns
O1 = 1;
O2 = O1 - ((K^2/K1)*(J1*O1));
O3 = (O2)- ((K^2/K2)*((J1*O1)+(J2*O2)));
O4 = (O3)-((K^2/K3)*((J1*O1)+(J2*O2)+(J3*O3)));
O5 = (O4)-((K^2/K4)*((J1*O1)+(J2*O2)+(J3*O3)+ (J4*O4)));
T1 = (J1)*(O1)*(K^2);
T2 = (J2)*(O2)*(K^2);
T3 = (J3)*(O3)*(K^2);
T4 = (J4)*(O4)*(K^2);
T5 = (J5)*(O5)*(K^2);
TT1 = T1;
TT2 = TT1 + T2;
TT3 = TT2 + T3;
TT4 = TT3 + T4;
TT5 = TT4 + T5;
if (x<TT5) && (TT5<y)
fprintf('Result Frequency= %d Radian, Total Torque= %d Newtonmeter\n',K,TT5)
end
end
elseif numberofdisc == 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 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)=');
for K = Wn:Wnf:Wns
O1 = 1;
O2 = O1 - ((K^2/K1)*(J1*O1));
O3 = (O2)- ((K^2/K2)*((J1*O1)+(J2*O2)));
O4 = (O3)-((K^2/K3)*((J1*O1)+(J2*O2)+(J3*O3)));
T1 = (J1)*(O1)*(K^2);
T2 = (J2)*(O2)*(K^2);
T3 = (J3)*(O3)*(K^2);
T4 = (J4)*(O4)*(K^2);
TT1 = T1;
TT2 = TT1 + T2;
TT3 = TT2 + T3;
TT4 = TT3 + T4;
if (x<TT4) && (TT4<y)
fprintf('Result Frequency= %d Radian, Total Torque= %d Newtonmeter\n',K,TT4)
end
end
elseif numberofdisc == 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)=');
for K = Wn:Wnf:Wns
O1 = 1;
O2 = O1 - ((K^2/K1)*(J1*O1));
O3 = (O2)- ((K^2/K2)*((J1*O1)+(J2*O2)));
T1 = (J1)*(O1)*(K^2);
T2 = (J2)*(O2)*(K^2);
T3 = (J3)*(O3)*(K^2);
TT1 = T1;
TT2 = TT1 + T2;
TT3 = TT2 + T3;
if (x<TT3) && (TT3<y)
fprintf('Result Frequency= %d Radian, Total Torque= %d Newtonmeter\n',K,TT3)
end
end
end
The below not code:
ı wanna plot my iteration values, for example x axis is Wn and y axis is TT3 or TT4 or TT5 but when ı write plot (Wn:Wnf:Wns,TT3), it doesn't work. this problem can be caused for too many value such as Wn:Wf:Wns=1:0.01:500.
Thanks for helping

Antworten (1)

Ishu
Ishu am 1 Sep. 2023
Hi Ismail,
I understand that you are getting trouble while plotting. But as you can see in your "plot(Wn:Wnf:Wns,TT3)" function, x-axis is a range from 'Wn' to 'Wnf' but y-axis is just a "1*1double". For the "plot()" to perform well you need to provide same size for x-axis and y-axis.
There are two ways to plot a figure in your case:
  1. You can use "plot()" while you are iterating.
%This is just an example on how to use plot(), you can make changes in your
%code accordingly
x = linspace(1,10,10); % creates a vector of size 10
for i = x
y = i^2; % You can replace y values with TT3 TT4 or TT5
plot(i, y, "o")
hold on % holds the figure to plot other results
end
2. If you want to use "plot()" only after completing the whole iteration then you can create "TT3", "TT4" and "TT5" as a vector of same size of "K"and then in every iteration store the results in these vectors.
%This is just an example on how to use plot(), you can make changes in your
%code accordingly
x = linspace(1,10,10); %creates a vector of size 10
y = ones(size(x)); % creates a vector of ones with same size of x
hold on
for i = x
y(i) = i^2; % calculates the values of y
end
plot(x,y, "o");
For more information on "plot()" you can refer to this documentation:
Hope it helps!

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by