Docsity

Matrix Projections and Line Equations, Assignments of Linear Algebra

Toggle sidebar
bg1
Homework Solutions Section 5.1
>restart:
>with(linalg);
Warning, the protected names norm and trace have been redefined and
unprotected
[BlockDiagonal,GramSchmidt,JordanBlock,LUdecomp,QRdecomp,Wronskian,addcol,
addrow,adj ,adjoint ,angle,augment ,backsub,band,basis,bezout,blockmatrix,
charmat,charpoly ,cholesky,col ,coldim,colspace,colspan,companion,concat,
cond,copyinto,crossprod,curl ,definite,delcols,delrows,det,diag ,diverge,
dotprod,eigenvals,eigenvalues ,eigenvectors,eigenvects,entermatrix ,equal,
exponential,extend ,ffgausselim,fibonacci,forwardsub,frobenius,gausselim ,
gaussjord,geneqns,genmatrix ,grad ,hadamard,hermite,hessian,hilbert,
htranspose,ihermite ,indexfunc,innerprod,intbasis,inverse ,ismith,issimilar ,
iszero,jacobian,jordan,kernel ,laplacian,leastsqrs ,linsolve,matadd ,matrix ,
minor,minpoly,mulcol,mulrow,multiply ,norm,normalize,nullspace,orthog,
permanent,pivot ,potential,randmatrix ,randvector,rank,ratform,row,rowdim ,
rowspace,rowspan,rref ,scalarmul,singularvals,smith ,stackmatrix ,submatrix ,
subvector,sumbasis,swapcol,swaprow ,sylvester,toeplitz ,trace,transpose,
vandermonde,vecpotent,vectdim,vector ,wronskian]
1 Problem 2
Scalar projection of v onto w is given by vTw
√wTw
Vector projection of v onto w is given by w v Tw
wTw
1.1 Problem 2a)
>v := array(1..3,1..1,[[2],[1],[3]]);
>w := array(1..3,1..1,[[6],[3],[9]]);
v:=
2
1
3
w:=
6
3
9
>num := multiply( transpose(v), w)[1,1]:
>den := sqrt(multiply( transpose(w), w )[1,1]):
>alpha := num/den;
α:= √14
>p := scalarmul(w,multiply( transpose(v), w)[1,1]/
>multiply( transpose(w), w)[1,1]);
pf3
pf4
pf5
pf8

Partial preview of the text

Download Matrix Projections and Line Equations and more Assignments Linear Algebra in PDF only on Docsity!

Homework Solutions Section 5.

(^) restart: (^) with(linalg);

Warning, the protected names norm and trace have been redefined and unprotected

[BlockDiagonal , GramSchmidt, JordanBlock , LUdecomp, QRdecomp, Wronskian, addcol ,

addrow , adj , adjoint, angle, augment, backsub, band , basis, bezout, blockmatrix , charmat, charpoly, cholesky, col , coldim, colspace, colspan, companion, concat, cond , copyinto, crossprod , curl , definite, delcols, delrows, det, diag, diverge, dotprod , eigenvals, eigenvalues, eigenvectors, eigenvects, entermatrix , equal ,

exponential , extend , ffgausselim, fibonacci, forwardsub, frobenius, gausselim, gaussjord , geneqns, genmatrix , grad , hadamard , hermite, hessian, hilbert, htranspose, ihermite, indexfunc, innerprod , intbasis, inverse, ismith, issimilar , iszero, jacobian, jordan, kernel , laplacian, leastsqrs, linsolve, matadd , matrix , minor , minpoly, mulcol , mulrow , multiply, norm, normalize, nullspace, orthog, permanent, pivot, potential , randmatrix , randvector , rank , ratform, row , rowdim, rowspace, rowspan, rref , scalarmul, singularvals, smith, stackmatrix , submatrix ,

subvector , sumbasis, swapcol , swaprow , sylvester , toeplitz , trace, transpose, vandermonde, vecpotent, vectdim, vector , wronskian]

1 Problem 2

Scalar projection of v onto w is given by v √T^ w wT^ w Vector projection of v onto w is given by w v

T (^) w wT^ w

1.1 Problem 2a)

(^) v := array(1..3,1..1,[[2],[1],[3]]); (^) w := array(1..3,1..1,[[6],[3],[9]]);

v :=

w :=

(^) num := multiply( transpose(v), w)[1,1]: (^) den := sqrt(multiply( transpose(w), w )[1,1]): (^) alpha := num/den; α :=

(^) p := scalarmul(w,multiply( transpose(v), w)[1,1]/ (^) multiply( transpose(w), w)[1,1]);

p :=

1.2 Problem 2b)

(^) v := array(1..2,1..1,[[2],[-3]]); w := array(1..2,1..1,[[3],[2]]);

v :=

[

]

w :=

[

]

(^) num := multiply( transpose(v), w)[1,1]: (^) den := sqrt(multiply( transpose(w), w )[1,1]): (^) alpha := num/den; α := 0 (^) p := scalarmul(w,multiply( transpose(v), w)[1,1]/ (^) multiply( transpose(w), w)[1,1]);

p :=

[

]

1.3 Problem 2c)

(^) v := array(1..2,1..1,[[4],[1]]); (^) w := array(1..2,1..1,[[3],[2]]);

v :=

[

]

w :=

[

]

(^) num := multiply( transpose(v), w)[1,1]: (^) den := sqrt(multiply( transpose(w), w )[1,1]): (^) alpha := num/den;

α :=

(^) p := scalarmul(w,multiply( transpose(v), w)[1,1]/ (^) multiply( transpose(w), w)[1,1]);

p :=

1.4 Problem 2d)

(^) v := array(1..3,1..1,[[-2],[3],[1]]); (^) w := array(1..3,1..1,[[1],[2],[4]]);

v :=

x :=

[

]

y :=

[

]

(^) num := multiply( transpose(x), y)[1,1]: (^) den := sqrt(multiply( transpose(y), y )[1,1]): (^) alpha := num/den; α := 4

(^) p := scalarmul(y,multiply( transpose(x), y)[1,1]/ (^) multiply( transpose(y), y)[1,1]);

p :=

[

]

(^) xmp := matadd(x,-p);

xmp :=

[

]

(^) multiply(transpose(p), xmp)[1,1]; 0

2.3 Problem 3c)

(^) x := array(1..3,1..1,[[2],[4],[3]]); (^) y := array(1..3,1..1,[[1],[1],[1]]);

x :=

y :=

(^) num := multiply( transpose(x), y)[1,1]: (^) den := sqrt(multiply( transpose(y), y )[1,1]): (^) alpha := num/den; α := 3

(^) p := scalarmul(y,multiply( transpose(x), y)[1,1]/ (^) multiply( transpose(y), y)[1,1]);

p :=

(^) xmp := matadd(x,-p);

xmp :=

(^) multiply(transpose(p), xmp)[1,1]; 0

2.4 Problem 3d)

(^) x := array(1..3,1..1,[[2],[-5],[4]]); (^) y := array(1..3,1..1,[[1],[2],[-1]]);

x :=

y :=

(^) num := multiply( transpose(x), y)[1,1]: (^) den := sqrt(multiply( transpose(y), y )[1,1]): (^) alpha := num/den; α := − 2

(^) p := scalarmul(y,multiply( transpose(x), y)[1,1]/ (^) multiply( transpose(y), y)[1,1]);

p :=

(^) xmp := matadd(x,-p);

xmp :=

(^) multiply(transpose(p), xmp)[1,1]; 0

3 Problem 4

Since — xT^ y—<=——x—— ——y—— = 6, we can conclude that 0 <= — xT^ y— <= 6

4 Problem 5

The line y=2x points in the direction (1,2)

(^) w := array(1..2,1..1,[[1],[2]]);

w :=

[

]

(^) v := array(1..2,1..1,[[5],[2]]);

v :=

[

]

(^) num := multiply( transpose(v), w)[1,1]: (^) den := sqrt(multiply( transpose(w), w )[1,1]): (^) alpha := num/den;

w :=

[

]

(^) v := array(1..2,1..1,[[1],[2]]);

v :=

[

]

(^) num := multiply( transpose(v), w)[1,1]: (^) den := sqrt(multiply( transpose(w), w )[1,1]): (^) alpha := num/den;

α :=

(^) p := scalarmul(w,multiply( transpose(v), w)[1,1]/ (^) multiply( transpose(w), w)[1,1]);

p :=

(^) Q := evalf(transpose(p)); Q :=

[

]

(^) differ := matadd(v,-p);

differ :=

(^) sqrt(multiply( transpose(differ), differ)[1,1]);

2 5

(^) evalf(%);

. 4000000000

7 Problem 8

7.1 Problem 8a)

(^) P := array(1..3,1..1,[[x],[y],[z]]);

P :=

x y z

(^) P0 := array(1..3,1..1,[[0],[0],[0]]);

P0 :=

(^) N := array(1..3,1..1,[[2],[4],[3]]);

N :=

(^) multiply( transpose(N),matadd(P,-P0))[1,1]=0; 2 x + 4 y + 3 z = 0

7.2 Problem 8b)

(^) P := array(1..3,1..1,[[x],[y],[z]]);

P :=

x y z

(^) P0 := array(1..3,1..1,[[4],[2],[-5]]);

P0 :=

(^) N := array(1..3,1..1,[[-3],[6],[2]]);

N :=

(^) multiply( transpose(N),matadd(P,-P0))[1,1]=0; − 3 x + 10 + 6 y + 2 z = 0

7.3 Problem 8c)

(^) P := array(1..3,1..1,[[x],[y],[z]]);

P :=

x y z

(^) P0 := array(1..3,1..1,[[3],[2],[4]]);

P0 :=

(^) N := array(1..3,1..1,[[0],[0],[1]]);

N :=

(^) multiply( transpose(N),matadd(P,-P0))[1,1]=0; z − 4 = 0