Question

In: Computer Science

This code is to be written in Matlab. Write a function that will plot cos(x) for...

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.

Solutions

Expert Solution

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


Related Solutions

Please show MATLAB code to plot below function from x = −3 to x = 12:...
Please show MATLAB code to plot below function from x = −3 to x = 12: function f = piecewise(x) % implements piecewise function using if statements if x < 0     f = -x^3 - 2*x^2 + 3*x; elseif x <= 8     f = (12/pi) * sin(pi*x/4); else     f = (600*exp(x-8))/(7*(14 + 6*exp(x-8))) -30/7; end
Write a matlab code for given task Use your ‘sin’ or ‘cos’ function to generate a...
Write a matlab code for given task Use your ‘sin’ or ‘cos’ function to generate a sinusoid wave having two components as f1 = 3kHz and f2 = 5kHz and then sample it with fs = 10kHz. Calculate its fft with zero frequency component in the middle. Plot it on a properly scaled w-axis. Specify if there is aliasing or not? If there is aliasing specify which component is casing the aliasing
MATLAB Question Write a script to plot the function 'x times sine-squared of x' over a...
MATLAB Question Write a script to plot the function 'x times sine-squared of x' over a user-specified interval. It should prompt the user to enter the starting and stopping values of x, perform the calculation, and plot the result. Test the script using start/stop values 28 and 42.
write the MATLAB code for: Let ? = sin2 (?) and ? = sin(?) cos(?). Let...
write the MATLAB code for: Let ? = sin2 (?) and ? = sin(?) cos(?). Let x vary from 0 to 10? in increments of 0.1?. Plot two figures part a & b. This panel has rows, one figure per row. a. Plot x versus y. This plot is on the top of panel and the next figure (part b) is at bottom of panel. i. Give a meaningful title to this figure. ii. x-axis is time with unit of...
The cos(x) function can be represented in a Taylor series shown below: Write a Matlab program,...
The cos(x) function can be represented in a Taylor series shown below: Write a Matlab program, and use a while loop, to calculate cos(150) (the input is in degrees) by adding terms of the series and stopping when the absolute value of the term that was added last is smaller than 0.0001. Make sure to make the required degree <-> radian conversions. Use fprintf to print the cos(150) (up to 2 decimal places) and the number of terms used to...
Practice for Matlab. You can create own f(x). a. Write code to find and plot a...
Practice for Matlab. You can create own f(x). a. Write code to find and plot a root using the modified secant method b. Find the roots using the roots command - identify and plot root of interest c. Use polyder and roots to find and plot the minimum value d. use fminbnd to find and plot minimum value Thank you!
Write a MATLAB function that uses my_sine(x,n) to plot the approximation of the sinefunction from−3π/2 to...
Write a MATLAB function that uses my_sine(x,n) to plot the approximation of the sinefunction from−3π/2 to 3π/2 with increments equal to Δx,where Δx and n(the number ofterms used in the series approximation) should be input arguments of the function andshould be specified by the user.
Please use MATLAB. Write a program to plot the piecewise function using IF statements and a...
Please use MATLAB. Write a program to plot the piecewise function using IF statements and a FOR loop in MatLab. Use x as the input vector. Plot from -20<=x<=20, increment of 1.   y =   4 x + 10 ,             ? ≥ 9,                   y =      5? + 5,                   0 ≤ ? < 9,                    y =     ?2 + 6? + 8, ? < 0 Plot each segment of the fn with different shaped points and a different color, for...
Write a MATLAB *function* that draws a spiral by using the plot() command to connect-the-dots of...
Write a MATLAB *function* that draws a spiral by using the plot() command to connect-the-dots of a set of points along the spiral's trajectory. The function should have three input arguments: the number of points along the trajectory, the number of rotations of the spiral, and the final radius of the spiral. The function does not need any output arguments. Use nargin to provide default values for the input arguments. The spiral should begin at the origin. At each step...
The following code must be written using matlab and must be using a for-loop. NOTE! Write...
The following code must be written using matlab and must be using a for-loop. NOTE! Write a computer program that assigns random integers for each entry and generates a row vector. Different random integers should be drawn from different intervals for position 1, position 2, position3 and position 4 of the array. After these first 4 positions are drawn. The whole thing should start over where position5 drawn from same interval as positions 1, position6 drawn from same interval as...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT