Question

In: Computer Science

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 (i.e.,going from one point in the spiral to the next), the angle about the origin and the distance from the origin should increase by a constant increment as defined by the function's inputs.

Solutions

Expert Solution

`Hey,

Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

clc
clear all
close all
drawSpiral
function drawSpiral(n,nturns,R)
if(nargin<1)
n=1000;
R=5;
nturns=4;
elseif(nargin<2)
nturns=4;
R=5;
elseif(nargin<3)
R=5;
end
% given values
pos = [0 0 ] ; % endpoint
% engine
phi = linspace(0, nturns*2*pi, n) ; % 10000 = resolution
r = linspace(0, R, numel(phi)) ;
x = pos(1,1) + r .* cos(phi) ;
y = pos(1,2) + r .* sin(phi) ;
plot(x,y,'b-',pos(:,1),pos(:,2),'ro-') ; % nturns crossings, including end point
end

Kindly revert for any queries

Thanks.


Related Solutions

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...
Plot the original data and the regression “line” ************USING Matlab************. "Submit plot" USING MATLAB! USING MATLAB!...
Plot the original data and the regression “line” ************USING Matlab************. "Submit plot" USING MATLAB! USING MATLAB! USING MATLAB! ONLY BY USING MATLAB!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 14.9 The concentration of E. coli bacteria in a swimming area is monitored after a storm: t (hr)                     4           8         12        16    20 24 c (CFU/100 mL) 1600     1320   1000     890 650 560 The time is measured in hours following the end of the storm and the unit CFU is a .colony forming unit.. Use this data to estimate (a)...
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....
Using matlab a) Find the transfer function of a fourth order Butterworth filter and plot the...
Using matlab a) Find the transfer function of a fourth order Butterworth filter and plot the magnitude response. b) Find the poles.
Write a simple code for a simple connect the dots game in plain C coding.
Write a simple code for a simple connect the dots game in plain C coding.
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 a MATLAB script file to integrate  using trapezoid method (do not use trapz command for this...
Write a MATLAB script file to integrate  using trapezoid method (do not use trapz command for this part, write your own script). Consider x=-0.5 to 3 with Δt=0.01, and compare your result with using “integral” and "trapz" commands (all in one file).
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.
Write a Matlab program to create specialized plot animation with 16 frames by using fast Fourier...
Write a Matlab program to create specialized plot animation with 16 frames by using fast Fourier transforms of complex matrices
write a Matlab function file to solve system Ax=b by using the output of the function...
write a Matlab function file to solve system Ax=b by using the output of the function lufac2a your function should have inputs f=matrix return from lufac2a, piv=array return by lufac2a and b=right hand side of your system.the only output for your system should be x guideline 1.use the column access for the matrix entries 2. do not create any other matrix in your function-get your data directly from the matrix passed into your function 3.do not use Matlab command designed...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT