• Non ci sono risultati.

ˆ Solution for Ex 1. Write the function 1

N/A
N/A
Protected

Academic year: 2021

Condividi "ˆ Solution for Ex 1. Write the function 1"

Copied!
2
0
0

Testo completo

(1)

ˆ Solution for Ex 1. Write the function 1

function [L, U] = LUnoPiv(A)

2

% LU factorization without pivoting

3

n = size(A,1); % size of A

4

L = eye(n); % initialize

5

for k = 1:n

1

6

for i = k+1:n

7

% multipliers for gaussian elimination

8

L(i,k) = A(i,k)/A(k,k);

9

for j = k:n

10

% construct A

11

A(i,j) = A(i,j)

L(i,k)*A(k,j);

12

end

13

end

14

end

15

U = A;

and then the following script 1

clear all

2

close all

3

% clc

4

epsilon = 10^(

15);

5

% Define A

6

A = [13 13 0; 2 2

epsilon 4; 1 3 17];

7

% define b

8

xVera = [2;5;7]; b = A*xVera;

9

% compute the solution

10

[L, U] = LUnoPiv(A);

11

y = L\b; xLUnoPiv = U\y;

12

% compute the solution with pivoting

13

[L, U, P] = lu(A);

14

y = L\(P*b); xLUpermut = U\y;

15

% compute the errors

16

format short e

17

ELUgauss = norm(xVera

xLUnoPiv)/norm(xVera)

18

ELUpermut = norm(xVera

xLUpermut)/norm(xVera)

1

(2)

ˆ Solution for Ex 2. At rst write the function 1

function [x,iter,err]=Jacobi(A,b,x0,tol,kmax)

2

% Jacobi's iterative method for the solution of Ax=b

3

% with tolerance 'tol' and maximum number of iteration

4

% 'kmax'

5

D=diag(diag(A)); DI=diag(1./diag(A));

6

J=

DI*(A

D);

7

disp(['Spectral radius of the iteration matrix = ',...

8

num2str(max(abs(eig(J))))]);

9

b1=DI*b; x1=J*x0+b1; k=1;

10

while(norm(x1

x0)>tol*norm(x1) && k<=kmax)

11

x0=x1;

12

x1=J*x0+b1;

13

err(k)=norm(x1

x0,inf);

14

k=k+1;

15

end

16

x=x1; iter=k

1;

Then, the following script 1

% clear all

2

% close all

3

% define the problem

4

v = [4 1 zeros(1,4)];

5

A = toeplitz(v);

6

b = A*2*ones(6,1);

7

% use Jacobi

8

[x,iter1,err1]=Jacobi(A,b,zeros(6,1),1.e

10,200);

2

Riferimenti

Documenti correlati

Indeed, when M increases, the uniform and Lipschitz constants of V M 0 deteriorate and we had to assume a bounded Lipschitz continuous kernel in the Mean Field theory, with

Whitt, Martingale proofs of many-server heavy-tra¢ c limits for Markovian queues, Probability

La
 definizione
 dei
 Costi
 Standard
 per
 l’erogazione
 delle
 prestazioni
 (o
 gruppi
 omogenei


[r]

Disegnare il diagramma degli stati (evidenziando gli stati accettanti) e la tabella delle transizioni che corrispondono all’automa di Moore che riceve in input sequenze di bit (0 e 1)

Recently, starting with the work [14] of Manfredi, Parviainen and Rossi, a great attention has been paid to the so-called asymptotic mean value property (AMVP) and its applications

Dunque se mettiamo entrambi gli elettroni in uno stato con n &gt; 1 (stati eccitati), questi non sono veri e propri stati legati dell’atomo, perché sono stati autoionizzanti, in

L’occorrenza di un nuovo evento puo’ essere considerato un esperimento tipo Bernoulli che genera solo due eventi incompatibili, tipo successo – insuccesso.. (1-p) = probabilità di