Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

After the cam coordinates are found, the radius is calculated for each point. Because the radius is changing, there is a velocity and acceleration associated with each point that must be calculated. As the radius is found graphically, the velocities and accelerations associated do not have an accompanying equation and must be calculated using numerical differentiation. The loop through the length of the radius vector for velocity and acceleration must be done separately as the end of the velocity vector is needed in the caluclation for the start of the acceleration vector.

Code Block
languagecpppy
titleNumerical Differentiation for finding r_dot
collapsetrue
for i = 1:length(r)
	if i == 1
		r_dm1 = r(length(r));
		r_dp1 = r(i+1);
		ca_dm1 = crank_angle(length(r));
		ca_dp1 = crank_angle(i+1);
	elseif i == length(r)
		r_dm1 = r(i-1);
		r_dp1 = r(1);
		ca_dm1 = crank_angle(i-1);
		ca_cp1 = crank_angle(1);
	else
		r_dm1 = r(i-1);
		r_dp1 = r(i+1);
		ca_dm1 = crank_angle(i-1);
		ca_dp1 = crank_angle(i+1);
	end
	r_d(i) = (r_dp1 - r_dm1)/(ca_dp1 - ca_dm1);
end

...