How can I fix this program. I've never used MatLab, but I need to be able to input theta and get a y and x value for it.

13 views (last 30 days)
function [X, Y] = mathModelOfCamAndFollower(theta)
%Initialize the design parameters
theta0 =0;
theta1 = 120;
theta2 = 120.1;
theta3 = 240;
theta4 = 360;
fd = 2; % difference between maximum follower displacement and minimum cam radius
%Convert degree to radian
theta0 =theta0*pi/180;
theta1 =theta1*pi/180;
theta2 =theta2*pi/180;
theta3 =theta3*pi/180;
theta4 =theta4*pi/180;
%Initialize the parameters for the displacement diagram
D = 12;
d1 = D*(theta1 - theta0)/(theta4-theta0);
d2 = D*(theta2 - theta1)/(theta4-theta0);
d3 = D*(theta3 - theta2)/(theta4-theta0);
d4 = D*(theta4 - theta3)/(theta4-theta0);
phi1 = atan(fd/d1);
phi2 = atan(fd/d3);
if theta <theta1
%formula during rise
X = d1*(theta1-theta)/(theta1 -theta0);
Y = tan(phi1)*X;
else % Executes only when theta is not less than theta1
if theta <theta2
%formula during dwell
X = d1+d2*(theta-theta1)/(theta2-theta1);
Y = fd;
else
if theta <theta3
%formula during fall
X = d1+d2+d3*(theta-theta2)/(theta3-theta2);
Y = tan(phi2)*(1-X);
else
if theta <theta4
%formula during dwell2
X = d1+d2+d3+d4*(theta-theta3)/(theta4-theta3);
Y = 0;
end
end
end
end

Answers (2)

Geoff Hayes
Geoff Hayes on 18 Nov 2014
Don - what is wrong with the code that it needs to be fixed? The theta input is a positive angle in radians. To get the x and y output, just call the function as
theta = 5*pi/180; % convert theta from degrees to radians
[x,y] = mathModelOfCamAndFollower(theta);

Image Analyst
Image Analyst on 18 Nov 2014
I didn't study or run the code but I do see you assigning x and y in there, like you asked for. What's wrong? Do you know that there are "d" versions of the trig functions where you can pass in degrees instead of radians, like atan2d() instead of atan2()?

Categories

Find more on Data Types 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!