Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Submit a printout of your solutions for each problem. Make sure to include all t

ID: 3562049 • Letter: S

Question

Submit a printout of your solutions for each problem. Make sure to include all the plots. 1. Problems (a) Write a MATLAB script. named FromCmToFeetAndInches.m, to prompt the user to enter the height in cm. The code will then compute the height in feet and inches. Recall that 1 foot = 12 inches = 30.48cm. For example, if the user enters 178, the code should compute feet = 5 inches = 10.0787 (b) Write a MATLAB script, named NrDigits.m, to prompt the user to enter an integer and then compute the number of digits. For example. if the user enters 43521. then the code should compute 5. As another example, if the user enters 3219, then the code should compute 4. (c) Recall that the rand function generates a random number in the interval (0, 1). Write a MATLAB script, named RandomPtsInsideRect.m, to prompt the user to enter the width and length of a rectangle and the number of random points. Your code should then generate as many random points as requested by the user, all inside the rectangle with center at (0,0) and width and length as specified by the user. Use the plot function to draw the generated points as red circles.

Explanation / Answer

1.A)

h=input('Enter the height in cm: ');
h1=h*12/30.48;
h_ft=floor(h1/12);
h_in=mod(h1,12);
fprintf('feet= %d ',h_ft)
fprintf('inches= %f ',h_in)

----------------------------------------------------------------------------------------------------

1.B)

num=input('Enter an integer: ');
char=num2str(num);
len=length(char);
fprintf('Number of digits: %d ',len)

---------------------------------------------------------------------------------------------------------------------------

1.C)

w=input('Enter the width of the rectangle:');
l=input('Enter the length of the rectangle:');
n=input('How many random number you want to generate: ');
x1=-l/2;
x2=l/2;
y1=-w/2;
y2=w/2;
rand_x=x1 + (x2-x1).*rand(1,n);
rand_y=y1 + (y2-y1).*rand(1,n);
plot(rand_x,rand_y,'or')