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

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

Accepted Answer

Paul
Paul on 11 Dec 2025
Edited: Paul on 11 Dec 2025
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')

More Answers (0)

Categories

Find more on Just for fun in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!