Question

In: Mechanical Engineering

This is a Matlab Exercise problem. Please create the Matlab code and figure for the following...

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!

Solutions

Expert Solution

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')


Related Solutions

Write the MATLAB code to Create a new figure. Define a theta array such that ?...
Write the MATLAB code to Create a new figure. Define a theta array such that ? 2 ≤ ? ≤ 9? 2 with increment of ? 10 ; Create a sixmember array of ones called r. Create a new polar plot of ? versus r
Use Matlab to do the following (please) : 1. Plot the following signals in one figure...
Use Matlab to do the following (please) : 1. Plot the following signals in one figure window using Matlab commands. Given x (n) = {5,2,1,3,1,4,2} plot x(3n) 2. Plot all transformations of a Gaussian signal in one figure window 3. Plot r(-3t-9).
Matlab Code that does the following: Takes as input 3 frequencies. Create a signal that is...
Matlab Code that does the following: Takes as input 3 frequencies. Create a signal that is a mixture of the 3 signals. Create a bandpass filter that only selects the center frequency. Output the filtered signal which contains only the middle frequency. Plot in time and frequency domain the original signal and the filtered signal. Show the output for filter order 1 and 15. Upload a pdf of the image files. Each figure should have your name in the title...
Use MATLAB to figure out the following problem, if you do not know how to use...
Use MATLAB to figure out the following problem, if you do not know how to use MATLAB then please do not answer. Coding is required for the exercise. For f(x) = arctan(x), find its zeros by implimenting Newtons method and the Secant method in Matlab. (Hint: Use Newtons method to calculate x1 for Secant method) Comment all code please since I would like to learn how to do this correctly in MATLAB. Thank you.
Coding: Use MATLAB to figure out the following problem, if you do not know how to...
Coding: Use MATLAB to figure out the following problem, if you do not know how to use MATLAB then please do not answer. Coding is required for the exercise. For f(x) = arctan(x), find its zeros by implimenting Newtons method and the Secant method in Matlab. (Hint: Use Newtons method to calculate x1 for Secant method) Comment all code please since I would like to learn how to do this correctly in MATLAB. Thank you.
Create a matlab function that converts Miles per hour to feet per second. Please show code...
Create a matlab function that converts Miles per hour to feet per second. Please show code in matlab
MATLAB based problem: Create a motoring model for the engine with the following specifications, and plot...
MATLAB based problem: Create a motoring model for the engine with the following specifications, and plot the in-cylinder pressure against (i) cylinder volume and (ii) crank angle degrees (20 points)  Bore = 107mm, stroke = 124mm, compression ratio = 17.3, Length of connecting rod = 192mm. Assume the ratio of specific heats is 1.4 (constant), atmospheric pressure is 1 bar and ambient temperature is 298 K.
please let me know reference of this MATLAB code. please explain this code line by line....
please let me know reference of this MATLAB code. please explain this code line by line. . . N=256; %% sampling number n=linspace(0,1,N); fs=1/(n(2)-n(1)); x=5*(sin((2*pi*10*n))); %% create signal N=length(x); f=[-fs/2:fs/N:fs/2-fs/N]; subplot(211) plot(f,fftshift(abs(fft(x)))); title('|G(f)|');grid; xlabel('frequency'); ylabel('|G(f)|'); %Zero padding xx=[zeros(1,128) x zeros(1,128)]; N=length(xx); f=[-fs/2:fs/N:fs/2-fs/N]; subplot(212) plot(f,fftshift(abs(fft(xx)))); title('|Gz(f)|');grid; xlabel('frequency'); ylabel('|Gz(f)|');
Create matlab simulink model for dc-dc buck converter with screenshot. Note: provide matlab code for the...
Create matlab simulink model for dc-dc buck converter with screenshot. Note: provide matlab code for the output of dc-dc buck converter if possible.
can someone code this problem please? Introduction Students will create a C++ program that simulates a...
can someone code this problem please? Introduction Students will create a C++ program that simulates a Pokemon battle mainly with the usage of a while loop, classes, structs, functions, pass by reference and arrays. Students will be expected to create the player’s pokemon and enemy pokemon using object-oriented programming (OOP). Scenario You’ve been assigned the role of creating a Pokemon fight simulator between a player’s Pikachu and the enemy CPU’s Mewtwo. You need to create a simple Pokemon battle simulation...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT