Linear Transformation

Linear Transformation

Solution 

exercise4.m 

function X=exercise4(v)

r=0.97;

alpha= pi*(v(2)+12)/300;

S=[1 v(4)/5;0 1];

R=[cos(alpha) -sin(alpha);sin(alpha) cos(alpha)];

A=r*S*R*inv(S);

X= [v(5)+1;v(6)];

iter=0;

whilesqrt(X’*X)>0.01

X=A*X;

iter=iter+1;

P(iter,:)=X;

end

fprintf(‘total number of iteration: %d\n’,iter);

figure;

plot(P(:,1),P(:,2),’r-‘);

hold on;

plot(P(1,1),P(1,2),’r*’);

plot(P(end,1),P(end,1),’g*’);

hold off; 

linearAlg.m 

clear all

clc

%% Exercise 1

v=[2 0 1 5 7 7 5];

A=[v(1) v(5);v(2) v(6)-10;v(3) v(7)]*inv([v(1) v(3);v(2) v(4)-10]);

[X Y]=meshgrid(0:100);

Z=A*[X(:)’; Y(:)’];

figure;plot3(Z(1,:),Z(2,:),Z(3,:),’r.’);

xlabel(‘x axis’);

ylabel(‘y axis’);

zlabel(‘z axis’);

title(‘transformation for selected v values’);

%% Exercise 2

A = [v(1) v(3) v(5)

v(2) v(4) v(6)

-1 -2 -4

-2 -1 -5

-1 -1 -3

-1 0 -2];

k = rank(A);

%%From paper sol

%%basis B for R6 that consists of k=3 columns of A and an

%%additional collection of vectors in R6.

B = [A];

B(:,4) = [0;0;0;1;0;0];

B(:,5) = [0;0;0;0;1;0];

B(:,6) = [0;0;0;0;0;1];

y = v(1:6)’;

Au = [B y];

P = rref(Au);

coeff = P(:,end);

disp(‘y as a linear combination of vectors in B’)

disp([‘y = ‘,num2str(coeff(1)),’*B(:,1)+’,num2str(coeff(2)),’*B(:,2)+’,num2str(coeff(3)),’*B(:,3)+’, …

num2str(coeff(4)),’*B(:,4)+’,num2str(coeff(5)),’*B(:,5)+’,num2str(coeff(6)),’*B(:,6)’,])

%% Excercise 3

% solution are paper based but there is just small simulation for given v

% vector.

w1=[v(1);v(2);v(3)];

w2=[v(4);v(5);v(6)-10];

w3=[v(7);-1;5];

w4=[0;-12;-28];

A=(-v(3)/v(1) + v(2)/v(1) *(v(6)-10-v(4)*v(3)/v(1))/( v(5)-v(4)*v(2)/v(1)));

B=( v(6)-10-v(4)*v(3)/v(1))/( v(5)-v(4)*v(2)/v(1));

C=(-5/v(7)-7*v(7)/3);

D=(-7/3);

t=[-10:10];

z= t;

y= (A-C)/(B*C-D*A)*t;

y= y/norm(y);

x= (-D+B)/(A*D-C*B)*t;

figure;plot3(x,y,z);

title(‘intersection line for z in [-10 10]’);

%% Excercise 4

X=exercise4(v);

1.

a)

Let’s assume   so

and

If we merge the two equation as in one matrix equation we reach

So to find the A matrix we need to multiply inverse of A’s multiplicand (the matrix consist of v1-v4).

If we calculate the inverse of second matrix and open the matrix equation we reach followings.

a1= (v2*v5)/(10*v1 – v1*v4 + v2*v3) – (v1*(v4 – 10))/(10*v1 – v1*v4 + v2*v3)

a2= (v1*v3)/(10*v1 – v1*v4 + v2*v3) – (v1*v5)/(10*v1 – v1*v4 + v2*v3)

a3= (v2*(v6 – 10))/(10*v1 – v1*v4 + v2*v3) – (v2*(v4 – 10))/(10*v1 – v1*v4 + v2*v3)

a4=(v2*v3)/(10*v1 – v1*v4 + v2*v3) – (v1*(v6 – 10))/(10*v1 – v1*v4 + v2*v3)

a5=(v2*v7)/(10*v1 – v1*v4 + v2*v3) – (v3*(v4 – 10))/(10*v1 – v1*v4 + v2*v3)

a6=v3^2/(10*v1 – v1*v4 + v2*v3) – (v1*v7)/(10*v1 – v1*v4 + v2*v3)

b)

if we select v1=1, v2=5,v3=1,v4=8,v5=-5,v6=12,v7=0, A matrix becomes

–3.2857    0.8571

A=     2.8571    0.4286

0.2857    0.1429

And x in range [0 100] and y in range [0 100] plate become following plate

2.

A matrix is like following when we revert it bottom to up

-1                    0                              -2

-1                    -1                            -3

-2                    -1                            -5

-1                    -2                            -4

v2                   v4                           v6

v1                   v3                           v5

To determine the rank and basis vector,first we multiply -1 to the 1st row itself. Then  we multiply first row with -1,-2,-1,v2,v1 and add 2,3,4,5,6th row respectively. So the matrix becomes

1                      0                              2

0                      -1                            -1

0                      -1                            1

0                      -2                            -2

0                      v3                           v5-2v1

0                      v4                           v6-2v2

Then multiply 2nd row -1 itself, after multiply 2nd row with 1,2,-v3,-v4 and add 3,4,5,6th row respectively. So matrix becomes

1                      0                              2

0                      1                              1

0                      0                              2

0                      0                              0

0                      0                              v5-2v1-v3

0                      0                              v6-2v2-v4

After we can multiplt 0.5 to the 3th row and we can get zero 5th and 6throw easily. But we could not remove 3th row 3th column.

So, Then we can say rank of A matrix is 3, and the basis rows are [1 0 2],[0 1 1] and [0 0 1].

2b.  The linear combinations are at the last column

V5-2v1-v3=0

V6-2v2-v4=0

3. 

For finding equation of H plane

v1                   v4                           x

v2                   v5                           y

v3                   v6-10                     z

take row 1, multiply –v2/v1 and add 2nr row, and multiply –v3/v1 add 3nd row

v1                   v4                           x

0                      v5-v4v2/v1          y-xv2/v1

0                      v6-10-v4v3/v1   z-xv3/v1

Take second row multiply –( v6-10-v4v3/v1)/( v5-v4v2/v1) and add 3nd row

v1                   v4                           x

0                      v5-v4v2/v1          y-xv2/v1

0                      0                              z-xv3/v1 – (y-xv2/v1).( v6-10-v4v3/v1)/( v5-v4v2/v1)

So the  equation is in the 3 nd row 3th column.

X*(-v3/v1 + v2/v1 *(v6-10-v4*v3/v1)/( v5-v4*v2/v1)) – Y *( v6-10-v4v3/v1)/( v5-v4v2/v1) +Z=0

For finding equation of K plane

v7                   0                              x

-1                    -12                          y

5                      -28                          z

Take 1st row multiple 1/v7 add 2nd row, multiply -5/v7 and add 3nd row

v7                   0                              x

0                      -12                          y+x/v7

0                      -28                          z-5x/v7

Take 2nr row multiply -28/12 and 3th row

v7                   0                              x

0                      -12                          y+x/v7

0                      0                              z-5x/v7 -7/3*( y+x/v7)

The K planes equation is 3row 3th colum

X*(-5/v7-7*v7/3) + Y* (-7/3) + Z=0

To determine the intersection of two plane which is shown with their equations, first we should remove X component .to do this we need to multiply appropriate coefficient both equations.

To do basic let we assume H is X*A+Y*B+Z=0

Where A=(-v3/v1 + v2/v1 *(v6-10-v4*v3/v1)/( v5-v4*v2/v1)), and B=( v6-10-v4v3/v1)/( v5-v4v2/v1)

Let K plane is X*C+Y*D+Z=0, where C=(-5/v7-7*v7/3), D=(-7/3)

Then the equation becomes

X*A+Y*B+Z=0

X*C+Y*D+Z=0

Now we remove X component  with multiply 1st row C, second row A

X*A*C+ Y* B*C+ Z*C=0

X*C*A+Y*D*A+ Z*A=0

Hen we substract each other

(BC-DA)Y = (A-C).Z  then y= (A-C)/(BC-DA)z  this is first equation of intersection

Then we need to remove Y somponent, to do this

X*A*D+Y*B*D+Z*D=0

X*C*B+Y*D*B+Z*B=0

Then substract

X*( AD-CB) = Z*(-D+B)  then x= z*(-D+B)/(AD-CB)

So if we assume z=t then the parametric equation of intersection line become

z=t,

y= (A-C)/(BC-DA)

To get unique y, we divide it by norm :

y = norm(y)

x= (-D+B)/(AD-CB)

4.