1 / 40

Selected Algebraic System Examples from Lectures

Selected Algebraic System Examples from Lectures. Matlab Examples. 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 Matrix multiplication >> C=[2 3; -1 2; 4 -3]; >> E=A*C E = 7 3 20 -1.

conroy
Download Presentation

Selected Algebraic System Examples from Lectures

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Selected Algebraic System Examples from Lectures

  2. Matlab Examples • 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 • Matrix multiplication >> C=[2 3; -1 2; 4 -3]; >> E=A*C E = 7 3 20 -1

  3. Gaussian Elimination Example • Form augmented matrix • Eliminate x1 from second and third equations

  4. Gaussian Elimination Example • Eliminate x2 from third equation • Solve triangular system

  5. Matlab Example Ax = b x = A-1b (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 • By hand • 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 • Eliminate x2 entry from third row • Make the diagonal elements unity

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

  9. Gauss-Jordan Elimination cont. • 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 1.0000

  11. Ill-Conditioned Matrix Example • Example • e represents measurement error in b2 • Two rows (columns) are nearly linearly dependent • Analytical solution • 10% error (e = 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: k(A) = ||A||||A-1|| • A “large” condition number indicates an ill-conditioned matrix • Well conditioned matrix • Ill-conditioned matrix

  15. Condition Number cont. • Effect of data errors • Small data errors can lead to large solution errors • Bound can be very conservative • 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. • Normal equations: (ATA)x = ATb • Solution: x = (ATA)-1ATb • ATA must be nonsingular • (ATA)-1AT is called the left inverse matrix • Example

  18. Underdetermined Systems cont. • 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 = -1.0000 17.0000 >> A=[1 2 -2; 2 -1 -1]; >> b=[25 -25]'; >> x = linsolve(A,b) x = x = -5.0000 -7 15.0000 not equal to 13.5 0 2.5

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

  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 -1.0000 2.0000

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

  24. Distinct Real Eigenvalue Example • Characteristic matrix • Characteristic equation • Eigenvalues: l1 = -5, l2 = 2

  25. Distinct Real Eigenvector Example • Eigenvalues • Determine eigenvectors: Ax = lx • Eigenvector for l1 = -5 • Eigenvector for l1 = 2

  26. Repeated Real Eigenvalue Example • Characteristic matrix • Characteristic equation • Eigenvalues: l1 = 2, l2 = 2

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

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

  29. Complex Eigenvalue Example • Characteristic matrix • Characteristic equation • Eigenvalues: l1 = -1+i, l2 = -1-i

  30. Complex Eigenvector Example • Eigenvalues • Determine eigenvectors: Ax = lx • Eigenvector for l = -1+i • Eigenvector for l = -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. Exit Gas Flow Fresh Media Feed (substrates) Agitator Exit Liquid Flow (cells & products) Continuous Bioreactor Example • ODE model

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

  36. Bioreactor: Newton-Raphson Solution • Iterative equation • Function • Derivative

  37. Bioreactor: Secant Solution • Iterative equation • Function • Initialization:

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

  39. Matlab Example #2 • Solution of biomass equation • Parameter values: D=0.04 h-1, mm=0.48 h-1, Km=1.2 g/L, Ki=22 g/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. • Guess solution and call function fzero >> xo=0; >> fzero('substrate',xo) >> ans = 0.1091 (meaningful) • Solution obtained depends on initial guess >> xo=10; >> fzero('substrate',xo) >> ans = -20.7263 (not meaningful)

More Related