Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Voss
Voss el 16 de Abr. de 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])

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by