In: Computer Science
This code is to be written in Matlab.
Write a function that will plot cos(x) for x values ranging from -pi to pi in steps of 0.1, using black *'s. It will do this three times across in one Figure Window, with varying line widths. If no arguments are passed to the function, the line widths will be 1, 2, and 3. If on the other hand, an argument is passed to the function, it is multiplier for these values. (e.g., if 3 is passed, the line widths will be 3, 6, and 9.) The line widths will be printed on these plots.
Program screenshot along with output :-
Output
Code in text format :-
function [output] = plotCos(linewidth)
%PlotCos Summary of this function goes here
x = -pi:0.1:pi;
fn = cos(x);
if nargin == 1
l = linewidth;
else
l = 1;
end
lw1 = l * 1;
lw2 = l * 2;
lw3 = l * 3;
figure;
plot(x,fn,'*','LineWidth',lw1);
title(['Linewidth is ' num2str(lw1)]);
figure;
plot(x,fn,'*','LineWidth',lw2);
title(['Linewidth is ' num2str(lw2)]);
figure;
plot(x,fn,'*','LineWidth',lw3);
title(['Linewidth is ' num2str(lw3)]);
end