{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Review Part 1

# Review Part 1 - Review of Part I Methods and Formulas...

This preview shows pages 1–5. Sign up to view the full content.

Review of Part I Methods and Formulas Solving equations numerically: f ( x ) = 0 — an equation we wish to solve. x — a true solution. x 0 — starting approximation. x n — approximation after n steps. e n = x n x — error of n -th step. r n = y n = f ( x n ) — residual at step n . Often | r n | is sufficient. Newton’s method: x i +1 = x i f ( x i ) f ( x i ) Bisection method: f ( a ) and f ( b ) must have different signs. x = ( a + b ) / 2 Choose a = x or b = x , depending on signs. x is always inside [ a, b ]. e < ( b a ) / 2, current maximum error. Secant method*: x i +1 = x i x i x i 1 y i y i 1 y i Regula Falsi*: x = b b a f ( b ) f ( a ) f ( b ) Choose a = x or b = x , depending on signs. Convergence: Bisection is very slow. Newton is very fast. Secant methods are intermediate in speed. Bisection and Regula Falsi never fail to converge. Newton and Secant can fail if x 0 is not close to x . Locating roots: Use knowledge of the problem to begin with a reasonable domain. Systematically search for sign changes of f ( x ). Choose x 0 between sign changes using bisection or secant. Usage: For Newton’s method one must have formulas for f ( x ) and f ( x ). 23

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
24 LECTURE 7. SYMBOLIC COMPUTATIONS Secant methods are better for experiments and simulations. Matlab Commands: > v = [0 1 2 3] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Make a row vector. > u = [0; 1; 2; 3] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Make a column vector. > w = v’ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Transpose: row vector column vector > x = linspace(0,1,11) . . . . . . . . . . . . . . . . . . . . . . . . . . . Make an evenly spaced vector of length 11. > x = -1:.1:1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Make an evenly spaced vector, with increments 0 . 1. > y = x.^2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Square all entries. > plot(x,y) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . plot y vs. x. > f = inline(’2*x.^2 - 3*x + 1’,’x’) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Make a function. > y = f(x) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A function can act on a vector. > plot(x,y,’*’,’red’) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A plot with options. > Control-c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Stops a computation. Program structures: for ... end Example: for i=1:20 S = S + i; end if ... end Example: if y == 0 disp(’An exact solution has been found’) end while ... end Example: while i <= 20 S = S + i; i = i + 1; end if ... else ... end Example: if c*y>0 a = x; else b = x; end Function Programs: - Begin with the word function . - There are inputs and outputs. - The outputs, name of the function and the inputs must appear in the first line. i.e. function x = mynewton(f,x0,n) - The body of the program must assign values to the outputs.
25 - internal variables are not visible outside the function. Script Programs: - There are no inputs and outputs. - A script program may use and change variables in the current workspace. Symbolic: > syms x y > f = 2*x^2 - sqrt(3*x) > subs(f,sym(pi)) > double(ans) > g = log(abs(y)) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Matlab uses log for natural logarithm. > h(x) = compose(g,f) > k(x,y) = f*g > ezplot(f) > ezplot(g,-10,10) > ezsurf(k) > f1 = diff(f,’x’) > F = int(f,’x’) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . indefinite integral (antiderivative) > int(f,0,2*pi) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . definite integral > poly = x*(x - 3)*(x-2)*(x-1)*(x+1) > polyex = expand(poly) > polysi = simple(polyex) > solve(f) > solve(g) > solve(polyex)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Review of Part II Methods and Formulas Basic Matrix Theory: Identity matrix: AI = A , IA = A , and I v = v Inverse matrix: AA 1 = I and A 1 A = I Norm of a matrix: | A | ≡ max | v | =1 | A v | A matrix may be singular or nonsingular. See Lecture 10.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}