我的情节在传说中有问题,传说应该是:-------- 2sin(0.5x)和+ cos(2x)。但我无法做到。 请欣赏我的stackoverflow和matlab。
这是我的代码:
% Create the x-axis
x = 0:pi/30:2*pi;
% Make a vector for 2sin(x/2)
y1 = 2*sin(x/2) ;
% Plot 2sin(x/2) as a solid line in red
plot(y1,'color','r')
% Make a vector for cos(2x)
y2 = cos(2*x);
% Use hold on to add a second plot to the graph
hold on
% Plot cos(2x)
plot(y1,'-r')
plot(y2,'+k')
% Activate a grid
grid on
% Create a legend
legend({'2sin(0.5x)','cos(2x)'})
% Add x and y labels
xlabel('x')
ylabel('2sin(0.5x) , cos(2x)')
% Add a title
title('This is my second MSUM plot')
答案 0 :(得分:0)
% Create the x-axis
x = 0:pi/30:2*pi;
% Make a vector for 2sin(x/2)
y1 = 2*sin(x/2) ;
% Plot 2sin(x/2) as a solid line in red
% Make a vector for cos(2x)
y2 = cos(2*x);
% Use hold on to add a second plot to the graph
hold on
% Plot cos(2x)
plot(y1,'-r')
plot(y2,'+k')
% Activate a grid
grid on
% Create a legend
legend({'2sin(0.5x)','cos(2x)'})
% Add x and y labels
xlabel('x')
ylabel('2sin(0.5x) , cos(2x)')
% Add a title
title('This is my second MSUM plot')