2) (USE MATLAB) Create a function called g that satisfies the following criteria. (Hint: Find function)
For x < -π g(x) = -1
For x ≥ -π and x ≤ π g(x) = cos(x)
For x >π g(x) = -1
Plot your results for values of x from -2p to +2p. Choose your spacing to create a smooth curve.
Matlab Code:
clc;
x = -2*pi:pi/100:-pi;
g = (-1).*x.^(0);
plot(x,g)
hold on
x = -pi:pi/100:pi;
g = cos(x);
plot(x,g)
hold on
x = pi:pi/100:2*pi;
g = (-1).*x.^(0);
plot(x,g)
set(gca,'XTick',-2*pi:pi:2*pi);
set(gca,'XTickLabel',{'-2*pi','-pi','0','pi','2*pi'});
xlabel('x')
ylabel('g(x)')
grid on
Plot:
if you have any doubt please ask in the comment box.
please do like and rate it nicely.
thank you.
Get Answers For Free
Most questions answered within 1 hours.