In: Computer Science
please correct the error and fix this code: (i need this work and present 3 graphs):
Sampling_Rate = 0.00004; % which means one data point every
0.001 sec
Total_Time = 0:Sampling_Rate:1; % An array for time from 0 to 1 sec
with 0.01 sec increment
Omega = 49.11; % in [rad/s]
zeta=0.0542; %unitless
Omega_d=49.03; % in [rad/s]
Displacement_Amplitude = 6.009; % in [mm]
Phase_Angle = 1.52; % in [rad]
Total_No_of_Points = length(Total_Time); % equal to the number of
points in the "Total_Time" array
for i = 1: Total_No_of_Points
X(i) = Displacement_Amplitude* exp(-zeta*Omega*Total_Time(i)) *
sin(Omega_d * Total_Time(i) + Phase_Angle); % Position
Equation
V(i) = Displacement_Amplitude* exp(-zeta*Omega*Total_Time(i)) *(
-zeta*Omega*sin(Omega_d * Total_Time(i) + Phase_Angle)+Omega_d *
cos(Omega_d * Total_Time(i) + Phase_Angle)); % Velocity
Equation
A(i) = -1 * Displacement_Amplitude *
exp(-zeta*Omega*Total_Time(i))( zeta^2*Omega^2*sin(Omega_d *
Total_Time(i)) - 2*zeta*Omega*Omega_d cos(Omega_d*Total_Time(i) +
Phase_Angle)-2*Omega_d^2*sin(Omega_d*Total_Time(i) + Phase_Angle));
% Acceleration Equation
end
figure,
subplot (311);
plot (Total_Time,X,'.b');
title('Free Undamped Oscillation');
ylabel ('x(t) [mm]');
subplot (312);
plot (Total_Time,V,'.r');
ylabel ('x^.(t) [mm/s]');
subplot (313);
plot (Total_Time,A,'.k');
xlabel ('t [s]');
ylabel ('x^.^.(t) [mm/s^2]');
Code has been cleaned according to the python compiler .
import matplotlib.pyplot as plt
import math
import numpy as np
Sampling_Rate = 0.00004 #; % which means one data point every 0.001 sec
i=0
Total_Time = []
while(i<=1): #; % An array for time from 0 to 1 sec with 0.01 sec increment
Total_Time.append(i)
i = i + 0.01
Omega = 49.11 #; % in [rad/s]
zeta=0.0542 #; %unitless
Omega_d=49.03 #; % in [rad/s]
Displacement_Amplitude = 6.009 #; % in [mm]
Phase_Angle = 1.52 #; % in [rad]
Total_No_of_Points = len(Total_Time) #; % equal to the number of points in the "Total_Time" array
X = []
V = []
A = []
for i in range(Total_No_of_Points): #= 1: Total_No_of_Points
X.append(Displacement_Amplitude* math.exp(-zeta*Omega*Total_Time[i]) * np.sin(Omega_d * Total_Time[i] + Phase_Angle) ) #; % Position Equation
V.append(Displacement_Amplitude* math.exp(-zeta*Omega*Total_Time[i]) *( -zeta*Omega*np.sin(Omega_d * Total_Time[i] + Phase_Angle)+Omega_d * np.cos(Omega_d * Total_Time[i] + Phase_Angle))) #; % Velocity Equation
A.append((-1) * Displacement_Amplitude * math.exp(-zeta*Omega*Total_Time[i])*( (zeta**2)*(Omega**2)*np.sin(Omega_d * Total_Time[i]) -
2*zeta*Omega*Omega_d *np.cos(Omega_d*Total_Time[i] +
Phase_Angle)-2*(Omega_d**2)*np.sin(Omega_d*Total_Time[i] + Phase_Angle))) #; % Acceleration Equation
fig = plt.figure()
fig.add_subplot (311)
plt.plot(Total_Time,X,'.b')
plt.title('Free Undamped Oscillation')
plt.ylabel ('x(t) [mm]')
fig.add_subplot (312)
plt.plot (Total_Time,V,'.r')
plt.ylabel ('x^.(t) [mm/s]')
fig.add_subplot (313);
plt.plot (Total_Time,A,'.k');
plt.xlabel ('t [s]');
plt.ylabel ('x^.^.(t) [mm/s^2]');