how do I change the abscissa (x -axis) of a cosine wave plot to show degrees

19 vues (au cours des 30 derniers jours)
Sean
Sean le 11 Déc 2025 à 1:18
Commenté : Sean le 11 Déc 2025 à 2:32
this is my current code,
x= 0:pi/100:4*pi;
y1 = cos(x);
A= 3;
B= 1.5;
C = pi/2;
D = -3;
y2 = A*cos(B*x+C)+ D;
D = rad2deg(4*pi)
xlim([0 D])
plot(x,y1,'-r',x,y2,'--b')
xlabel('Angle (θ) [°]')
ylabel('funtion value')
grid
legend('','y = Acos(BΘ + C) + D')
On side note I would be able to prompt the user to imput the varibles A, B, C, ana D,
these are my results:
this is what I want the graph to kinda look like

Réponse acceptée

Paul
Paul le 11 Déc 2025 à 1:27
Modifié(e) : Paul le 11 Déc 2025 à 2:15
Change the plot command so that the independent variables are in deg. Or define x in terms of deg and then use cosd to compute y1 and y2 with B and C modified appropriately. Also, can use tex to get theta in the labels and legend if you think that looks any better. And put the xlim after the plot command.
x= 0:pi/100:4*pi;
y1 = cos(x);
A= 3;
B= 1.5;
C = pi/2;
D = -3;
y2 = A*cos(B*x+C)+ D;
D = rad2deg(4*pi);
%xlim([0 D])
plot(rad2deg(x),y1,'-r',rad2deg(x),y2,'--b')
xlim([0,D])
xlabel('Angle (\theta) [°]')
ylabel('function value')
grid
legend('','y = Acos(B\theta + C) + D')

Plus de réponses (0)

Catégories

En savoir plus sur Just for fun dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by