I am graphing a function, and it is graphing more sin/cos waves then it is supposed to
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/966700/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/966705/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/966710/image.png)
Out come I am supposed to have ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/966715/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/966715/image.png)
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 Commenti
Risposta accettata
Voss
il 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])
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Graph and Network Algorithms in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!