Why is my Graph not plotting properly?

6 views (last 30 days)
Kathryn Warner
Kathryn Warner on 22 Apr 2019
Answered: Star Strider on 22 Apr 2019
Below is code for calculating the velocity, acceleration and angular acceleration of a slider crank. Although I got the loop to work correctly for the calculations, I cannot get it to graph properly. Currently it is only plotting a single point. I know this is something to do with my stucture of the fuctions, I just do not know how to fix it.
I need to plot 4 figures. Figure 1 must plot Vbx, Vby and Vpx vs theta on a single figure. Figure 2 must plot Abx, Aby, Apx vs theta on a single figure. Figure 3 should plot Pomega vs theta and figure 4 must plot Palpha vs theta each on their own figure. Any thing helps, thank you.
clear
clc
close all
%%%%%% Defining Variables of Givens %%%%%%
theta = 0; % Rotational arm angle %
while(theta <= 360) % Beinging theta loop for 0 to 360 %
phi = asind(0.03/sind(theta)); % slider arm angle %
r = [0.06*cosd(theta), 0.06*sind(theta), 0]; % Rotational arm vector (m) %
ry = [0, 0.06*sind(theta), 0]; % Rotational arm vector in y direction (m) %
rx = [0.06*cosd(theta), 0, 0]; % Rotational arm vector in x direction (m) %
rxs = 0.06*cosd(theta);
rs = 0.06; % Rotational arm length scalar (m) %
d = [0.18*cosd(phi), -0.18*sind(phi), 0]; % Sliding arm length (m) %
dy = [0, -0.18*sind(phi), 0]; % Sliding arm length in y direction (m) %
dys = -0.18*sind(phi); % Sliding arm length in y direction (m) %
dx = [0.18*cosd(phi),0, 0]; % Sliding arm length (m) %
dxs = 0.18*cosd(phi); % Sliding arm length (m) %
ds = 0.18; % Sliding arm length scalar (m) %
Bomega = [0,0,250]; % Omega AB (Rad/s) %
Bomegas = 250; % Omega AB scalar %
%%%%%% Solved for Variables %%%%%%
Vbys = Bomegas*0.06*cosd(theta); % Velocity of B in the y direction scalar %
Pomegas = -Vbys/0.18; % Omega BP scalar(rad/s) %
Pomega = [0,0,Pomegas]; % Omega BP (rad/s) %
%%%%%% Equations for Velcocity at B %%%%%%
Vb = cross(Bomega, r); % Velocity of point B (m/s) %
Vby = cross(Bomega,rx); % Velocity of B in the y direction %
Vbx = cross(Bomega,ry);
Vbys = Bomegas*0.06*cosd(theta); % Velocity of B in the y direction scalar %
Vbxs = Bomegas*0.06*sind(theta) % Velocity of B in the x direction scalar %
%%%%%% Equations for Acceleration at B %%%%%%
Ab = -(Bomegas^2)*r; % Acceleration of point B (m/s^2) %
Abx = -(Bomegas^2)*rx; % Acceleration of point B in the x direction (m/s^2) %
Abxs = -(Bomegas^2)*rxs; % Scalar acceleration of point B in the x direction (m/s^2) %
Aby = -(Bomegas^2)*ry; % Acceleration of point B in the y direction (m/s^2) %
%%%%%% Equations for point P %%%%%%
Vp = Vb+cross(Pomega, d); % Velocity of point P %
Vpx = Vbx+cross(Pomega, dy); % Velocity of point P as a vector in the x direction %
Vps = -(Vbxs+Pomegas*dys); % Velocity of point P %
Palphas = (Abxs + (Pomegas^2)*(0.18*sind(phi)))/(0.18*cosd(phi)); % Alpha at point P scalar %
Palpha = [0,0,Palphas]; % Vector Alpha at point P %
Ap = Ab + cross(Palpha, dx) - Pomegas^2*(dx); % Acceleration at point P %
theta = theta + 10 % Looping Theta %
end; % end looping %
figure, plot(theta,Vbxs, '*')
xlim([0, 360])
ylim([-16,16])

Answers (1)

Star Strider
Star Strider on 22 Apr 2019
Add a counter.
At the beginning of your while loop:
k1 = 0;
theta = 0; % Rotational arm angle %
while(theta <= 360) % Beinging theta loop for 0 to 360 %
k1 = k1 + 1;
. . .
and subscript the ‘Vbxs’ values to record them:
Vbxs(k1) = Bomegas*0.06*sind(theta) % Velocity of B in the x direction scalar %
then at the end, create a vector ‘thetav’ to record the ‘theta’ values:
. . .
theta = theta + 10 % Looping Theta %
thetav(k1) = theta;
end; % end looping %
and the plot call is then:
figure
plot(thetav,Vbxs, '*')
xlim([0, 360])
ylim([-16,16])

Categories

Find more on Graph and Network Algorithms in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!