I am graphing a function, and it is graphing more sin/cos waves then it is supposed to
1 次查看(过去 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
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graph and Network Algorithms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!