Clear Filters
Clear Filters

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

2 views (last 30 days)
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

Accepted Answer

Voss
Voss on 16 Apr 2022
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])

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!