I'm trying to plot a piecewise function that I've created and it keeps giving me an error saying "vectors must be same length." this is what I have. Please help.
theta = linspace(0,2*pi,500);for i=1:numel(theta) if (theta(i) >= 0) && (theta(i) <= (pi/2)) y(i) = 6*(2*theta(i) - 0.5*sin(theta(i))); elseif (theta(i) >= (pi/2)) && (theta(i) <= (2*pi/3)) y(i) = 6; elseif (theta(i) >= (2*pi/3)) && (theta(i) <= (4*pi/3)) y(i) = 6 - 3*(1 - 0.5*cos(3*theta(i) - 2*pi)); elseif (theta(i) >= (4*pi/3)) && (theta(i) <= (3*pi/2)) y(i) = 3; elseif (theta(i) >= (3*pi/2)) && (theta(i) <= (7*pi/4)) y(i) = 3 - 1.5*((theta(i) - (3*pi/2))/(pi/4))^2; elseif (theta(i) >= (2*pi/3)) && (theta(i) <= (4*pi/3)) y(i) = 0.75 - 0.75*(1 - (theta(i) -(7*pi/4))/(pi/4))^2; endendplot(theta,y,'r','linewidth',2)
Best Answer