Presentation is loading. Please wait.

Presentation is loading. Please wait.

Loop Application: Numerical Methods, Part 1 The power of Matlab Mathematics + Coding.

Similar presentations


Presentation on theme: "Loop Application: Numerical Methods, Part 1 The power of Matlab Mathematics + Coding."— Presentation transcript:

1 Loop Application: Numerical Methods, Part 1 The power of Matlab Mathematics + Coding

2 Numerical Methods We are going to develop some programs in the class of numerical methods. Numerical methods are techniques used to find quantitative solutions to mathematical problems. Many numerical methods are iterative solutions – this means that the technique is applied over and over, gradually getting closer (i.e. converging) on the final answer. Iterative solutions are complete when the answer from the current iteration is not significantly different from the answer of the previous iteration. “Significantly different” is determined by the program – for example, it might mean that there is less than 1% change or it might mean less than 0.00001% change.

3 1. Newton’s Method Prepare a MATLAB program that uses Newton’s Method to find the roots of the equation: y(x) = x 3 + 2x 2 – 300/x Newton’s Method is used to find the roots of an equation – the values of the independent variable that make the dependent variable 0.

4 Newton’s Method f(x) = x 3 + 2x 2 – 300/x What does the answer appear to be?

5 Newton’s Method X is the root we’re trying to find – the value where the function becomes 0 X n is the initial guess X n+1 is the next approximation using the tangent line Credit to: http://en.wikipedia.org/wiki/Newton’s_method

6 The Big Picture (1/4) repeat – repeat – repeat… Credit to: http://en.wikipedia.org/wiki/Newton’s_method 1 st : guess! x n 2 nd : Find the y value for this x- value - go hit the actual curve 3 rd : Using the slope m, the coordinates (X n, Y n ), calculate X n+1 : At this (x n, y n ), calculate the slope of the curve using the derivative: m = f’(x n )

7 The Big Picture (2/4) repeat – repeat – repeat… Credit to: http://en.wikipedia.org/wiki/Newton’s_method 1 st : guess again! 2 nd : find y and m 3 rd : calculate new X intercept TOO FAR

8 The Big Picture (3/4) repeat – repeat – repeat… Credit to: http://en.wikipedia.org/wiki/Newton’s_method 1 st : guess again! 2 nd : find y and m 3 rd : calculate new X intercept TOO FAR

9 The Big Picture (3/4) – Eventually… Stop the loop, when there is not much difference between the guess and the new value! CLOSE ENOUGH! guess X inter- ecept

10 Newton’s Method Algorithm: Provide an initial guess at the answer Find the slope of the tangent line at the point (requires derivative) Using the line’s equation, find the x-intercept Repeat above until close enough, using the x intercept as the new “guess”

11 Newton’s Method % Define initial difference as very large (force loop to start) % Repeat as long as change in x is large enough % Make the “new x” act as the current x % Find slope of tangent line using f’(x) % Compute y-value % Use tangent slope to find the next value: %two points on line are the current point (x, y) % and the x-intercept (x_new, 0) end

12 % Define initial difference as very large % (force loop to start) % Repeat as long as change in x is large enough while (abs(x_np1 – x_n) > 0.0000001) % x_np1 now becomes the new guess x_n = x_np1; % Find slope of tangent line f'(x) at x_n m = 3*x_n^2 + 4*x_n + 300/(x_n^2); % Compute y-value y = x_n^3 + 2*x_n^2 - 300/x_n; % Use tangent slope to find the next value: %two points on line: the current point (x_n, y_n) % and the x-intercept (x_np1, 0) x_np1 = ((0 - y) / m) + x_n; end TOO FAR XnXn X n+1 x_n = 1000; x_np1 = 5; % initial guess

13 Newton’s Method Add fprintf ’s and see the results: x y------------------- 5.000000000000000115.000000000000000 3.925233644859813 14.864224007996924 3.742613907949879 0.279824373263295 3.739045154311932 0.000095471294827 3.739043935883257 0.000000000011084 Root of f(x) = x 3 + 2x 2 – 300/x is approximately 3.7390439

14 End of Presentation


Download ppt "Loop Application: Numerical Methods, Part 1 The power of Matlab Mathematics + Coding."

Similar presentations


Ads by Google