I am graphing a function, and it is graphing more sin/cos waves then it is supposed to

2 次查看(过去 30 天)
I am working on an assignment for class, and I am supposed to create a function to find x and y based on the input theta from 0 to 180. I am getting outputs, but compared to what it is supposed to look like, there are more than one waves. I believe the problem is with the theta function, and/or theta from 0:180. (I put the function before the graph for screenshot purposes, otherwise it was after the graph code)
Out come I am supposed to have
theta=0:180;
theta = endeffector (theta);
L=1; %in meters
x=L*cos(theta);
y=L*sin(theta);
function theta = endeffector (theta)
theta=0:180;
figure(1)
set(gcf,'color','white')
subplot(3,2,1)
plot(theta,x,'-k','linewidth',2),grid on
xlabel('Theta (deg)','Interpreter','latex','fontsize',10)
ylabel('X (m)','Interpreter','latex','fontsize',10)
xlim([0 180])
ylim([-1 1])
subplot(3,2,2)
plot(theta,y,'-b','linewidth',2),grid on
xlabel('Theta (deg)','Interpreter','latex','fontsize',10)
ylabel('Y (m)','Interpreter','latex','fontsize',10)
xlim([0 180])
ylim([-1 1])
subplot(3,2,3)
plot(theta,y,'-b','linewidth',2),grid on
plot(theta,x,'-k','linewidth',2),grid on
xlabel('Theta (deg)','Interpreter','latex','fontsize',10)
ylabel('X and Y (m)','Interpreter','latex','fontsize',10)
xlim([0 180])
ylim([0 1])
end

采纳的回答

Voss
Voss 2022-4-16
Use cosd and sind when the angle is in degrees. cos and sin are for when the angle is in radians.
theta = 0:180;
L = 1;
x = L*cosd(theta);
y = L*sind(theta);
figure(1)
% subplot(3,2,1)
plot(theta,x,'-k','LineWidth',2); grid on
xlim([0 180])
ylim([-1 1])

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by