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

For each of the problems in this lab assignment, write a separate MATLAB m-file.

ID: 3801480 • Letter: F

Question

For each of the problems in this lab assignment, write a separate MATLAB m-file. The name of each m-file must be exactly as specified in the corresponding problem statemenL Submit your m files by uploading to Blackboard before the due date. A p-file (an encrypted script file) for problems 2, 3 and 4 are available on the Lab page of the course website. You can download these files and run them from the command line to see how your codc should behave. Make the behavior of your code match that of the p-files. 1. Filename: MAF10 30 Tab6 1.m At the end of lesson 7 you were told to draw a flow chart to do the following: Create an ma x n matrix, A, whose entrics are consecutive integer values starting at 0 and counting up along the row. Let m and n be variables defined just aner the start block. For example, if n 2 and n 3, then 3 4 5 Now, implement this algorithm in a MATLAB m-file. 2. Filename: MAF 1090 Lab6 2 A three dimensional vector can be represented in either rectangular coordinates (x,y, z or the spherical coordinates (r,6, p). The relationships betwccn thesc two scts of coordinatcs are given by the following equations: x r COS (p) cos (0) y r cos(p) sin(0) z r sin(b) 0 tan i

Explanation / Answer

1.

m = 2;
n = 3;
count = 0;
A = zeros(m,n);
for i = 1:m
for j = 1:n
A(i, j) = count;
count = count + 1;
end
end
disp(A)

2.

%User input for the x, y, z coordinates
x = input('Enter the value of x coordinate: ');
y = input('Enter the value of y coordinate: ');
z = input('Enter the value of z coordinate: ');

%Convert according to equations given
a = x^2 + y^2 + z^2;
r = sqrt(a);

%Finding the angles%
angle1 = atand(y/x)

angle2 = atand(z/(x^2 + y^2)) // atand is the function to calculate tan inverse in degrees


%Display the same to the user
fprintf('r = %.2f ', r)
fprintf('angle1(theta) = %.2f ',angle1)
fprintf('angle2(phi) = %.2f ',angle2)

3.

%User input for the angles
angle1 = input('Enter the first angle of the spherical coordinates: ');
angle2 = input('Enter the second angle of the spherical coordinates: ');

%User input for r
r = input('Enter the value of "r": ');

%Convert according to equations given
x = r*cos(angle1)*cos(angle2);
y = r*cos(angle1)*sin(angle2);
z = r*sin(angle1);

%Display the same to the user
fprintf('x = %.2f ',x)
fprintf('y = %.2f ',y)
fprintf('z = %.2f ',z)

4.

n=input('Pick the value of n ?');
fib=zeros(1,n);

fib(1)=1;

fib(2)=2;

s=3;

while s<=n

fib(s)=fib(s-2)+fib(s-1);
s=s+1;
end

fprintf('The Fibonacci Sequence to %d terms is ', n);

fprintf('%g ',fib);

fprintf(' ');

valueOffib=zeros(1,n);

for s=1:n

fib=fib(s);
valueOffib(s)=fib;
  
end