Trying to plot SVAJ curves using Matlab for a double dwell cam

run environmentReset;
%Inputs
beta1 = 60; %rise
beta2 = 120;%dwel
beta3 = 30; %fall
beta4 = 150;%dwell
h1 = 2.5; %rise
h2 = 0; %dwell
h3 = 2.5; %fall
h4 = 0; %dwell
%SCCA constants
b = 0.25;
c = 0.50;
d = 0.25;
ca = 4.8881;
theta1 = beta1;
theta2 = theta1 + beta2;
theta3 = theta2 + beta3;
theta4 = theta3 + beta4;
syms y1(x)
y1(x) = ca*(x*(b/pi) - (b/pi)^2*sin(x*(pi/b)));
syms y1p(x)
y1p(x) = ca*(b/pi) * (1 - cos(x*(pi/b)));
syms y1p2(x)
y1p2(x) = ca*sin(x*(pi/b));
syms y1p3(x)
y1p3(x) = ca*(pi/b)*cos(x*(pi/b));
%Interval 1
for x = 0:b/2
y1(x);
y1p(x);
y1p2(x);
y1p3(x);
end
syms y2(x)
y2(x) = ca*(((x^2)/2) + b*((1/pi) - (1/2))*x + (b^2)*((1/8) - (1/(pi^2))));
syms y2p(x)
y2p(x) = ca*(x + b*((1/pi) - (1/2)));
syms y2p2(x)
y2p2(x) = ca;
syms y2p3(x)
y2p3(x) = 0;
%Interval 2
for x = b/2:(1-d)/2
y2(x);
y2p(x);
y2p2(x);
y2p3(x);
end
syms y3(x)
y3(x) = ca*(((b/pi) + (c/2))*x + ((d/pi)^2) + b^2*((1/8) - (1/pi^2)) - (1-d)^2/8 - (d/pi)^2*cos((pi/d)*(x-(1-d)/2)));
syms y3p(x)
y3p(x) = ca*((b/pi) + (c/2) + (d/pi)*sin((pi/d)*(x - (1-d)/2)));
syms y3p2(x)
y3p2(x) = ca*cos((pi/d)*(x - (1-d)/2));
syms y3p3(x)
y3p3(x) = -ca*(pi/d)*sin((pi/d)*(x - (1-d)/2));
%Interval 3
for x = (1-d)/2:(1+d)/2
y3(x);
y3p(x);
y3p2(x);
y3p3(x);
end
syms y4(x)
y4(x) = ca*((-x.^2/2) + ((b/pi) + (1-b/2)*x + (2*d^2 - b^2)*((1/pi^2) - 1/8) - 1/4));
syms y4p(x)
y4p(x) = ca*(-x + b/pi + 1 - b/2);
syms y4p2(x)
y4p2(x) = -ca;
syms y4p3(x)
y4p3(x) = 0;
%Interval 4
for x = (1+d)/2:1-b/2
y4(x);
y4p(x);
y4p2(x);
y4p3(x);
end
syms y5(x)
y5(x) = ca*((b/pi)*x + 2*(d^2 - b^2)/pi^2 +((1-b^2) - d^2)*4 - (b/pi)^2*sin((pi/b)*(x-1)));
syms y5p(x)
y5p(x) = ca*(b/pi)*(1 - cos((pi/b)*(x-1)));
syms y5p2(x)
y5p2(x) = ca*sin((pi/b)*(x-1));
syms y5p3(x)
y5p3(x) = ca*(pi/b)*cos((pi/b)*(x-1));
%Interval
for x = 1-b/2:1
y5(x);
y5p(x);
y5p2(x);
y5p3(x);
end
syms R(x, x1, x2)
R(x, x1, x2) = [(x > x1) & (x <= x2), 1, 0];
syms s1(x)
s1(x) = h1*(R(x, 0, b/2)*y1(x) + R(x, b/2, (1-d)/2)*y2(x) + R(x, (1-d)/2,(1+d)/2)*y3(x) + R(x, (1+d)/2, 1-b/2)*y4(x) + R(x, 1-b/2, 1)*y5(x));
syms v1(x)
v1(x) = (h1/beta1)*(R(x, 0, b/2)*y1p(x) + R(x, b/2, (1-d)/2)*y2p(x) + R(x, (1-d)/2,(1+d)/2)*y3p(x) + R(x, (1+d)/2, 1 - b/2)*y4p(x) + R(x, 1 - b/2, 1)*y5p(x));
syms a1(x)
a1(x) = (h1/beta1^2)*(R(x, 0, b/2)*y1p2(x) + R(x, b/2, (1-d)/2)*y2p2(x) + R(x, (1-d)/2,(1+d)/2)*y3p2(x) + R(x, (1+d)/2, 1 - b/2)*y4p2(x) + R(x, 1 - b/2, 1)*y5p2(x));
syms j1(x)
j1(x) = (h1/beta1^3)*(R(x, 0, b/2)*y1p3(x) + R(x, b/2, (1-d)/2)*y2p3(x) + R(x, (1-d)/2,(1+d)/2)*y3p3(x) + R(x, (1+d)/2, 1 - b/2)*y4p3(x) + R(x, 1 - b/2, 1)*y5p3(x));
%SVAJ Interval 1
for x = 0:beta1
s1(x);
v1(x);
a1(x);
j1(x);
end
syms s2(x)
s2(x) = h1;
syms v2(x)
v2(x) = 0;
syms a2(x)
a2(x) = 0;
syms j2(x)
j2(x) = 0;
%SVAJ Interval 2
for x = beta1:beta1 + beta2
s2(x);
v2(x);
a2(x);
j2(x);
end
syms s3(x)
s3(x) = h3*(1-R(x, 0, b/2)*y1(x) + R(x, b/2, (1-d)/2)*y2(x) + R(x, (1-d)/2,(1+d)/2)*y3(x) + R(x, (1+d)/2, 1-b/2)*y4(x) + R(x, 1-b/2, 1)*y5(x));
syms v3(x)
v3(x) = (-h3/beta3)*(R(x, 0, b/2)*y1p(x) + R(x, b/2, (1-d)/2)*y2p(x) + R(x, (1-d)/2,(1+d)/2)*y3p(x) + R(x, (1+d)/2, 1 - b/2)*y4p(x) + R(x, 1 - b/2, 1)*y5p(x));
syms a3(x)
a3(x) = (-h3/beta3^2)*(R(x, 0, b/2)*y1p2(x) + R(x, b/2, (1-d)/2)*y2p2(x) + R(x, (1-d)/2,(1+d)/2)*y3p2(x) + R(x, (1+d)/2, 1 - b/2)*y4p2(x) + R(x, 1 - b/2, 1)*y5p2(x));
syms j3(x)
j3(x) = (-h3/beta3^3)*(R(x, 0, b/2)*y1p3(x) + R(x, b/2, (1-d)/2)*y2p3(x) + R(x, (1-d)/2,(1+d)/2)*y3p3(x) + R(x, (1+d)/2, 1 - b/2)*y4p3(x) + R(x, 1 - b/2, 1)*y5p3(x));
%SVAJ Interval 3
for x = beta1 + beta2:beta1 + beta2 + beta3
s3(x);
v3(x);
a3(x);
j3(x);
end
syms s4(x)
s4(x) = 0;
syms v4(x)
v4(x) = 0;
syms a4(x)
a4(x) = 0;
syms j4(x)
j4(x) = 0;
%SVAJ Interval 4
for x = beta1 + beta2 + beta3:beta1 + beta2 + beta3 + beta4
s4(x);
v4(x);
a4(x);
j4(x);
end
syms S(theta)
syms V(theta)
syms A(theta)
syms J(theta)
%Complete global equations for displacement, S, velocity, V, acceleration,
%A, and jerk, J.
S(theta) = s1(theta/theta1) + R(theta, theta1, theta2)*s2((theta - theta1)/(theta2 - theta1)) + R(theta, theta2, theta3)*s3((theta - theta2)/(theta3 - theta2)) + R(theta, theta3, theta4)*s4((theta - theta3)/(theta4 - theta3));
V(theta) = v1(theta/theta1) + R(theta, theta1, theta2)*v2((theta - theta1)/(theta2 - theta1)) + R(theta, theta2, theta3)*v3((theta - theta2)/(theta3 - theta2)) + R(theta, theta3, theta4)*v4((theta - theta3)/(theta4 - theta3));
A(theta) = a1(theta/theta1) + R(theta, theta1, theta2)*a2((theta - theta1)/(theta2 - theta1)) + R(theta, theta2, theta3)*a3((theta - theta2)/(theta3 - theta2)) + R(theta, theta3, theta4)*a4((theta - theta3)/(theta4 - theta3));
J(theta) = j1(theta/theta1) + R(theta, theta1, theta2)*j2((theta - theta1)/(theta2 - theta1)) + R(theta, theta2, theta3)*j3((theta - theta2)/(theta3 - theta2)) + R(theta, theta3, theta4)*j4((theta - theta3)/(theta4 - theta3));
%Plot the global equations over 0 to 360 degrees.
ezplot(S);
Error using symengine
Dimensions do not match.
Error in sym/privBinaryOp (line 1022)
Csym = mupadmex(op,args{1}.s, args{2}.s, varargin{:});
Error in * (line 317)
X = privBinaryOp(A, B, 'symobj::mtimes');
Error in attempt4 (line 177)
S(theta) = s1(theta/theta1) + R(theta, theta1, theta2)*s2((theta - theta1)/(theta2 - theta1)) + R(theta, theta2,
theta3)*s3((theta - theta2)/(theta3 - theta2)) + R(theta, theta3, theta4)*s4((theta - theta3)/(theta4 - theta3));
I know the error in attempt4 will continue with line 178, 179, 180.

Answers (0)

Products

Release

R2019a

Asked:

on 20 Nov 2020

Commented:

on 14 Nov 2021

Community Treasure Hunt

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

Start Hunting!