• Non ci sono risultati.

EXERCISE 1: GEM by hands

N/A
N/A
Protected

Academic year: 2021

Condividi "EXERCISE 1: GEM by hands"

Copied!
7
0
0

Testo completo

(1)

Using the Gauss elimination method, solve, by pencil and paper, the linear system below; then check by Matlab the solution.

4 0 12

−2 6 −3

1 2 5

 x

1

x

2

x

3

 =

 0 0 1

 Same as before, with

−5 3 4

10 −8 −9

15 1 2

 x

1

x

2

x

3

 =

 1 5 1

 Same as before, with

1 −3 4

−1 5 −3

4 −8 23

 x

1

x

2

x

3

 =

 12

−12 58

(2)

EXERCISE 1: solution 1st system

] - nothing to do i

K' ¥

.tl#tn... I :H¥.H¥n

4 O

I

12 ] - res - In .

€ rz

) - 'zr.no

:÷÷n÷ii:H÷÷÷÷ l

.

therefore Xs - 1

, Xz = -

I

, X

, =

- 3

(3)
(4)

EXERCISE 1: solution 3rd system

(5)

Write a function that, given as input an upper triangular matrix U and a vector b, solves the system Ux = b using the backsubstitution method and test it on the system

3 −1 2

0 1 −5

0 0 2

 x

1

x

2

x

3

 =

 4

−4 2

Write a function that, given as input a matrix A and a vector b, solves the system Ax = b using Gaussian elimination (with and without pivoting) and test it on the system

2 2 0

1 1 −1

3 −2 4

 x

1

x

2

x

3

 =

 4 1 5

Modifying the function above, write a function that, given as input a

matrix A, returns the L and U factors of the LU factorization without

pivoting.

(6)

EXERCISE 3: solving linear systems and more...

Using the LU factorization function above, write a function that returns the inverse of an input matrix.

Modify the above function to compute the determinant of an input matrix A, and test it on the matrices in the previous slide.

Solve a system Ax = f with user-made functions above, where f arbitrary chosen and

A =

2 −1 0 . . . 0

−1 2 −1 . . . 0

0 . .. . .. . .. 0 ..

. −1 2 −1

0 0 . . . −1 2

In particular, compute x with either the GEM/LU methods implemented

above and by explicitly computing x = A

−1

f (i.e., computing A

−1

with

the function above). Using the Matlab commands tic and toc, measure

the time required by the two aproaches to compute the solution. The

matrix size should be chosen large enough so that the time difference is

relevant.

(7)

When the vast majority of a matrix A entries are zero, it is convenient to store only the nonzero values (and their position) in the memory. The Matlab function sparse can convert a non-sparse (dense) matrix into a sparse one.

Let Au = f be the matrix in the previous slide. Using the Matlab command whos, compare the memory usage when A is stored as dense and as sparse, for a large enough matrix size. Compare also the time spent to solve the system (use Matlab LU factorisation, and Matlab solver to invert the trinagular systems).

Consider a similar system Bu = f , where

B =

2 −1 −1 . . . −1

−1 2 0 . . . 0

−1 0 . .. ...

..

. 2 0

−1 0 . . . 0 2

Note that A and B have the same sparisity, i.e. the same number of nonzero entries. Compare again the memory and solution time required when B is stored as sparse or as dense. Do you observe any difference with the previous case? If yes, why? You might want to compare the sparsity pattern (Matlab command spy) of the L U factors.

Riferimenti

Documenti correlati

Pas de discordances doctrinales entre théologiens et humanistes, pas de divergences politiques parmi les quelques lettrés : l'humanisme français ne consistait qu'à revêtir

A similar conclusion regards the vortex core radius, which values at different streamwise locations, for the data affected from wandering, are determined by the 3HFP

between economic development and democracy was weaker in cases where the Human Development Index (HDI), at the same economic level, was used as an indicator

The development of a heater is a significant technological challenge tied with the need of reaching high ignition temperatures (1500-2000 K) minimizing the power

The testing procedure for evaporation process is performed by setting Hot Chamber Deposition Test Rig at 450 °C for furnace room temperature setting (the average

being immediately correlated to the appearance (thus to any perception related phenomenon), the imma- nent temporal objects are additionally described by their

Il decorso di un oggetto temporale, sebbene possa essere posto quasi in antitesi alla metafora della valanga usata da Bergson per sostenere il concetto di tempo della

45 As the first conviction of sexual violence based on command responsibility, this case arguably constituted a realization of the Court’s main objective of ending impunity