#### Read PowerPoint Presentation text version

Solution of Simultaneous Linear Equations

02/27/2006

1

Solution of Simultaneous Linear Equations

· matrix representation of a system of simultaneous linear equations

Ax=b

· most common in physics: "square systems"

2

Solution of Simultaneous Linear Equations

· linear independence of equations

The determinant det(A) give you a measure of closeness to singularity

This material copied from: http://en.wikipedia.org/wiki/determinant

3

Solution of Simultaneous Linear Equations

· Cramer's Rule

This material copied from: http://en.wikipedia.org/wiki/Cramer's_rule

4

Solution of Simultaneous Linear Equations

· Computationally, Cramer's Rule is generally inefficient and thus not used in practical applications which may involve many equations. However, it is of theoretical importance in that it gives an explicit expression for the solution of the system. · We can make a script that implements Cramer's rule · We can make Cramer's rule into a function

x=cramers(A,b)

Some material copied from: http://en.wikipedia.org/wiki/Cramer's_rule

5

Solution of Simultaneous Linear Equations

· MATLAB gives you other ways to solve Ax=b

matrix inversion:

Ax = b A -1Ax = A -1b x = A -1b

in MATLAB: x=inv(A)*b

6

Solution of Simultaneous Linear Equations

· The best way to solve Ax=b in MATLAB is x=A\b

Uses Gaussian elimination somewhat faster than matrix inversion

· we can compare speeds in a little code

warning message if nearly singular error message if singular what happens for an underdetermined system? what happens for an overdetermined system?

7

Solution of Simultaneous Linear Equations

· Over-Determined Systems

#rows > #columns

· not enough variables for all the equations

in physics we often deliberately use over-determined systems in polynomial curve fitting

· reduce the order of the fit to get a smoother curve and to respect the underlying theory

for Over-Determined systems with linearly independent rows, a unique solution can be determined which minimizes the least-squares errors we can see this with a very simple code

8

Solution of Simultaneous Linear Equations

· Under-Determined Systems

#rows < #columns not enough equations for all the variables solution corresponds to an entire subspace: no unique solution in physics this is often the sign of an over-excited theorist

· "you can fit any curve with a 7-parameter fit"

9

Solution of Simultaneous Linear Equations

· Generally the solution of simultaneous linear equations Ax=b in physics using MATLAB is obtained with x=A\b · x=A\b is flexible and intelligent for solving simultaneous linear equations · Assuming the rows of A are linearly independent, it will

for a square system it will seek an exact solution for an Over-Determined system it will find a least squares solution for an Under-Determined system it will find a solution with the number of nonzero components less than or equal to the number of equations

· For a square matrix

a warning message will be issued if the matrix is close to singular an error message will be issued if the matrix is singular

10

Code to Implement Cramer's Rule as a Script

· %cramers.m · %cramer's rule · · · · · · · · · · N=5 A=rand(N) b=rand(N,1) x=zeros(size(b)); for i=1:N numerator=A; numerator(:,i)=b; x(i)=det(numerator)/det(A); end x

11

Code to Compare Speed of Inversion versus Gaussian Elimination

· · · · · · · · · · · · · · · · · · · · · · · %speed_comparison.m %compare the speed of matrix inversion versus Gaussian Elimination N=5 Iterations=10000 A=rand(N) b=rand(N,1) x1=zeros(size(b)); x2=x1; tic for i=1:Iterations x1=inv(A)*b; end toc tic for i=1:Iterations x2=A\b; end toc tic for i=1:Iterations end toc [x1 x2] 12

Code to Graph Results of an Over-Determined System

· · · · · · · · %overdetermined.m %show an overdetermined solution A=rand(8,5) b=rand(8,1) x=A\b n=[1:size(A,1)]' figure;plot(n,b,'o',n,A*x,'+') legend('b','A*x')

13

#### Information

##### PowerPoint Presentation

13 pages

#### Report File (DMCA)

Our content is added by our users. **We aim to remove reported files within 1 working day.** Please use this link to notify us:

Report this file as copyright or inappropriate

650547