Write a Matlab script that plots the following functions over 0 ≤ x ≤ 5π:
f1(x) = sin2 x − cos x,
f2(x) = −0.1 x 3 + 2 x 2 + 10,
f3(x) = e −x/π ,
f4(x) = sin(x) ln(x + 1).
The plots should be in four separate frames, but all four frames should be in one figure window. To do this you can use the subplot command to create 2 × 2 subfigures.
MATLAB code
close all
clear
clc
x = 0:0.1:5*pi;
f1 = (sin(x)).^2 - cos(x);
f2 = -0.1*x.^3 + 2*x.^2 + 10;
f3 = exp(-x/pi);
f4 = sin(x).*log(x+1);
figure
subplot(221), plot(x,f1), xlabel('x'), ylabel('f_1(x)'),
title('f_1(x) vs. x');
subplot(222), plot(x,f2), xlabel('x'), ylabel('f_2(x)'),
title('f_2(x) vs. x');
subplot(223), plot(x,f3), xlabel('x'), ylabel('f_3(x)'),
title('f_3(x) vs. x');
subplot(224), plot(x,f4), xlabel('x'), ylabel('f_4(x)'),
title('f_4(x) vs. x');
plot
Get Answers For Free
Most questions answered within 1 hours.