In: Mechanical Engineering
This is a Matlab Exercise problem. Please create the Matlab code and figure for the following problem using problem specifications:
Plot x vs y when y=sin(x), y=cos(x), y=sin (2*x), and y=2*sin(x) when x = 1:0.1:10. Use 2 by 2 subplot, sin(x) is in location 1, cos(x) is in location 2, sin(2*x) is in location 3 and 2*sin(x) is in location 4.
The plot should have:
(1) x label = ‘x value’, y label = ‘y value’, legend ‘y=sin(x)’,’ y=cos(x)’,’ y=sin (2*x)’, ‘y= y=2*sin(x)’ and title = ‘x Vs. y’ under Font Name of Times New Roman, and Font Size of 14 pt. for all subplot location.
(2) For sine(x) use red solid line, for cos(x) use blue dashed line, for sin(2*x) use green dash-dot line, and for 2*sin(x) use solid line and RGB [0.5 0.2 0.2]
(3) Create minor grid for all subplot location.
Please attach editor code and the figure in your answer. Thank You!
figure
subplot(2,2,1)
x = 1:0.1:10;
y1 = sin(x);
plot(x,y1,'r')
set(gca,'FontSize',14,'FontName','Times New Roman')
grid(gca,'minor')
grid on
set(gca, 'YMinorTick','on', 'YMinorGrid','on')
xlabel('x value');
ylabel('y value');
legend('y = sin(x)');
title('x Vs. y')
subplot(2,2,2)
y2 = cos(x);
plot(x,y2,'b--')
set(gca,'FontSize',14,'FontName','Times New Roman')
grid(gca,'minor')
grid on
set(gca, 'YMinorTick','on', 'YMinorGrid','on')
xlabel('x value');
ylabel('y value');
legend('y = cos(x)');
title('x Vs. y')
subplot(2,2,3)
y3 = sin(2*x);
plot(x,y3,'g-.')
set(gca,'FontSize',14,'FontName','Times New Roman')
grid(gca,'minor')
grid on
set(gca, 'YMinorTick','on', 'YMinorGrid','on')
xlabel('x value');
ylabel('y value');
legend('y = sin(2x)');
title('x Vs. y')
subplot(2,2,4)
y4 = 2*sin(x);
plot(x,y4,'color',[0.5 0.2 0.2])
set(gca,'FontSize',14,'FontName','Times New Roman')
grid(gca,'minor')
grid on
set(gca, 'YMinorTick','on', 'YMinorGrid','on')
xlabel('x value');
ylabel('y value');
legend('y = 2sin(x)');
title('x Vs. y')