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

2. Write a function transform3(A), which, when given a matrix A, returns a new m

ID: 3860926 • Letter: 2

Question

2. Write a function transform3(A), which, when given a matrix A, returns a new matrix that is obtained as follows: If A has more than one row, then interchange the first and second row. Once this is done, square the elements in the first row. Save this file as a script. Test this function by invoking it from matlab. [3.5 marks] 1

3. Write a function transform4(A), which, when given a matrix A, returns a new matrix that is obtained as follows: If A has more than two columns, then interchange the last two columns of A. Once you have done this, take the cube of the elements in the last column. Save this file as a script. Test this function by invoking it from matlab. [3.5 marks]

.4 Let A be a matrix with three rows. Let x, y and z be vectors corresponding to the first, second and third rows, respectively. Write a function transform5(A,theta) that returns three vectors, xnew, ynew and znew, given A and the angle theta in degrees, with the values of xnew, ynew and znew calculated as follows: xnew = xsin(theta) y 3 tan(theta) ynew = x 2 cos(theta) zsin(theta) znew = xcos(theta) + ysin(theta) z 2 tan(theta) Save this file as a script. Test this function by invoking it from matlab.

Explanation / Answer

2.

function a = transform3(A)

b = size(A);

r1 = zeros(b(2));
r2 = zeros(b(2));

if b(1) > 1
for i = 1:b(2)
r1(i) = A(1,i);
r2(i) = A(2,i);
end
r2new = r1;
r1new = r2.^2;
for i = 1:b(2)
A(1,i) = r1new(i);
A(2,i) = r2new(i);
end
end
disp(A)

3.

function a = transform4(A)

b = size(A);

c1 = zeros(b(1),1);
c2 = zeros(b(1),1);

if b(2) > 1
for i = 1:b(1)
c1(i,1) = A(i,1);
c2(i,1) = A(i,2);
end
c2new = c1;
c1new = c2.^3;
for i = 1:b(1)
A(i,1) = c1new(i);
A(i,2) = c2new(i);
end
end
disp(A)

  

4.

function [xnew,ynew,znew] = transform5(A,theta)

b = size(A);


for i = 1:b(2)
x(i) = A(1,i);
y(i) = A(2,i);
z(i) = A(3,i);
end
xnew = x.*sin(theta) + y.^3.*tan(theta);
ynew = x.^2.*cos(theta) - z.*sin(theta);
znew = x.*cos(theta) + y.*sin(theta) - z.^2.*tan(theta);
  
  


  

  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote