In: Computer Science
Write as a MatLab script
For X=-2π~2π with intervals of π/100.
a. Plot Y1=sin(X) as a red line. Add a grid. b. Plot Y2=cos(X) as a
black dotted line. Add a grid. c. Plot Y1 and Y2 in the same plot
without using the hold on/off command. d. For Y3= Y1 times Y2, plot
Y1, Y2 and Y3 in the same graph. Y3 will be green line. Add title,
axis label and a legend.
% MATLAB Program to plot multple functions on a same graph X = -2*pi:pi/100:2*pi; % (a) Y1 = sin(X); plot(X,Y1,'r'); grid on; % (b) Y2 = cos(X); plot(X,Y2,'.-k'); grid on; % (c) plot(X,Y1,'r',X,Y2,'.-k'); grid on; % (d) Y3 = Y1 .* Y2; plot(X,Y1,'r'); hold on plot(X,Y2,'.-k'); plot(X,Y3,'g'); hold off grid on; title('Sin(x) & Cos(x)'); xlabel('x-axis'); ylabel('y-axis'); legend('Y1','Y2','Y3');