Presentation is loading. Please wait.

Presentation is loading. Please wait.

Selected Algebraic System Examples from Lectures.

Similar presentations


Presentation on theme: "Selected Algebraic System Examples from Lectures."— Presentation transcript:

1 Selected Algebraic System Examples from Lectures

2 Matlab Examples l Matrix addition >> A=[1 3 2; 2 4 5]; >> B=[3 -4 6; 1 -2 5]; >> D=A+B D = 4 -1 8 3 2 10 l Matrix multiplication >> C=[2 3; -1 2; 4 -3]; >> E=A*C E = 7 3 20 -1

3 Gaussian Elimination Example l Form augmented matrix l Eliminate x 1 from second and third equations

4 Gaussian Elimination Example l Eliminate x 2 from third equation l Solve triangular system

5 Matlab Example Ax = b  x = A -1 b (discuss next lecture) >> A=[3 -2 2; -5 4 -3; -4 3 -2]; >> rank(A) ans = 3 >> b=[-1; 3; 1]; >> x=inv(A)*b x = 3.0000 3.0000 -2.0000

6 Determinant Examples l By hand l Using Matlab >> A=[1 2; 3 4]; >> det(A) ans = -2 >> A=[1 2 3;4 5 6;7 8 9]; >> det(A) ans = 0

7 Gauss-Jordan Elimination l Eliminate x 2 entry from third row l Make the diagonal elements unity

8 Gauss-Jordan Elimination cont. l Eliminate first two entries in third column l Obtain identity matrix l Matrix inverse

9 Gauss-Jordan Elimination cont. l Verify result

10 Matlab Examples >> A=[-1 1 2; 3 -1 1; -1 3 4]; >> inv(A) ans = -0.7000 0.2000 0.3000 -1.3000 -0.2000 0.7000 0.8000 0.2000 -0.2000 >> A=[1 2; 3 5]; >> b=[1; 2]; >> x=inv(A)*b x = 1.0000

11 Ill-Conditioned Matrix Example l Example »  represents measurement error in b 2 »Two rows (columns) are nearly linearly dependent l Analytical solution 10% error (  = 0.1)

12 Matlab Example >> A=[1 2; 3 5]; >> cond(A) ans = 38.9743 (well conditioned) >> A=[0.9999 -1.0001; 1 -1]; >> cond(A) ans = 2.0000e+004 (poorly conditioned) >> b=[1; 1.1] >> x=inv(A)*b x = 500.5500 499.4500

13 Matlab: Vector and Matrix Norms >> x=[2 -3 0 1 -4]'; >> norm(x,2) ans = 5.4772 >> norm(x,inf) ans = 4 >> A = [5 1 1; 1 4 2; 1 2 4]; >> norm(A,1) ans = 7 >> norm(x,inf) ans = 7 >> norm(A,'fro') ans = 8.3066

14 Condition Number Definition:  (A) = ||A|| ||A -1 || l A “large” condition number indicates an ill-conditioned matrix l Well conditioned matrix l Ill-conditioned matrix

15 Condition Number cont. l Effect of data errors »Small data errors can lead to large solution errors »Bound can be very conservative l Example

16 Matlab: Condition Number >> A = [5 1 1; 1 4 2; 1 2 4]; >> AI = inv(A) AI = 0.2143 -0.0357 -0.0357 -0.0357 0.3393 -0.1607 -0.0357 -0.1607 0.3393 >> norm(A,1)*norm(AI,1) ans = 3.7500 >> cond(A,1) ans = 3.7500 >> norm(A,inf)*norm(AI,inf) ans = 3.7500 >> cond(A,inf) ans = 3.7500

17 Overdetermined Systems cont. l Normal equations: (A T A)x = A T b l Solution: x = (A T A) -1 A T b »A T A must be nonsingular »(A T A) -1 A T is called the left inverse matrix l Example

18 Underdetermined Systems cont. l Example

19 Matlab: Linear Algebraic Systems >> A=[-1 1 2; 3 -1 1; -1 3 4]; >> b=[1 2 3]'; >> x=inv(A)*b x = 0.6000 0.4000 0.6000 >> x = linsolve(A,b) x = 0.6000 0.4000 0.6000 >> x=A\b x = 0.6000 0.4000 0.6000

20 Matlab: Linear Algebraic Systems cont. >> A = [1 2; 2 -1; -2 -1]; >> b = [25 -25 -25]'; >> x = linsolve(A,b) x = 17.0000 >> A=[1 2 -2; 2 -1 -1]; >> b=[25 -25]'; >> x = linsolve(A,b) x = -5.0000-7 15.0000not equal to13.5 02.5

21 Plotting a Function » x = [0.1:0.1:10]; » y1 = 7*x./(0.6 + x); » y2 = 5*x./ (0.08+x); » plot(x,y1,x,y2) » xlabel('x') » ylabel('y') » legend('y1','y2') » figure » subplot(2,1,1) » plot(x,y1) » ylabel('y1') » subplot(2,1,2) » plot(x,y2) » ylabel('y2')

22 Square Systems >>A=[-1 1 2; 3 -1 1; -1 3 4]; >> b=[2 6 4]'; >> x=inv(A)*b; >> x=A\b; >> x=linsolve(A,b) x = 1.0000 2.0000

23 Non-Square Systems >> A = [1 2; 2 -1; -2 -1]; >> b = [25 -25 -25]'; >> x=A\b x = 17.0000 >> x = linsolve(A,b) x = 17.0000

24 Distinct Real Eigenvalue Example l Characteristic matrix l Characteristic equation Eigenvalues: 1 = -5, 2 = 2

25 Distinct Real Eigenvector Example l Eigenvalues Determine eigenvectors: Ax = x Eigenvector for 1 = -5 Eigenvector for 1 = 2

26 Repeated Real Eigenvalue Example l Characteristic matrix l Characteristic equation Eigenvalues: 1 = 2, 2 = 2

27 Repeated Real Eigenvector Example l Eigenvalues Determine eigenvectors: Ax = x Eigenvectors for = 2 l Eigenvectors are linearly dependent

28 Matlab Example >> A=[2 5; 0 2]; >> e=eig(A) e = 2 >> [X,e]=eig(A) X = 1.0000 -1.0000 0 0.0000 e = 2 0 0 2

29 Complex Eigenvalue Example l Characteristic matrix l Characteristic equation Eigenvalues: 1 = -1+i, 2 = -1-i

30 Complex Eigenvector Example l Eigenvalues Determine eigenvectors: Ax = x Eigenvector for = -1+i Eigenvector for = -1-i

31 Matlab Example >> A=[-1 -1; 1 -1]; >> e=eig(A) e = -1.0000 + 1.0000i -1.0000 - 1.0000i >> [X,e]=eig(A) X = 0.7071 0.7071 0 - 0.7071i 0 + 0.7071i e = -1.0000 + 1.0000i 0 0 -1.0000 - 1.0000i

32 Matrix Diagonalization Example

33 Matlab Example >> A=[-1 2 3; 4 -5 6; 7 8 -9]; >> [X,e]=eig(A) X = -0.5250 -0.6019 -0.1182 -0.5918 0.7045 -0.4929 -0.6116 0.3760 0.8620 e = 4.7494 0 0 0 -5.2152 0 0 0 -14.5343 >> D=inv(X)*A*X D = 4.7494 -0.0000 -0.0000 -0.0000 -5.2152 -0.0000 0.0000 -0.0000 -14.5343

34 Continuous Bioreactor Example l ODE model Fresh Media Feed (substrates) Exit Gas Flow Agitator Exit Liquid Flow (cells & products)

35 Bioreactor: Fixed-Point Solution l Steady-state biomass equation l Iterative equation l Initialization:

36 Bioreactor: Newton-Raphson Solution l Iterative equation l Function l Derivative

37 Bioreactor: Secant Solution l Iterative equation l Function l Initialization:

38 l Solution of a single nonlinear algebraic equation: l Create Matlab m-file function: fun.m: l Call fzero from the Matlab command line to find the solution: l Different initial guesses, xo, give different solutions: Matlab Example #1 >> xo = 0; >> fzero('fun',xo) ans = 0.5376 >> fzero('fun',1) ans = 1.2694 >> fzero('fun',4) ans = 3.4015

39 Matlab Example #2 l Solution of biomass equation Parameter values: D=0.04 h -1,  m =0.48 h -1, K m =1.2 g/L, K i =22 g/L l Create Matlab M-file: substrate.m function f = substrate(x) D = 0.04; mm = 0.48; Km = 1.2; Ki = 22; f = -D+mm*x/(Km+x+x^2/Ki);

40 Matlab Example #2 cont. l Guess solution and call function fzero >> xo=0; >> fzero('substrate',xo) >> ans = 0.1091 (meaningful) l Solution obtained depends on initial guess >> xo=10; >> fzero('substrate',xo) >> ans = -20.7263 (not meaningful)


Download ppt "Selected Algebraic System Examples from Lectures."

Similar presentations


Ads by Google