Docsity

Nonlinear Equations MATLAB Implementation-Machine Learning-Lecture Slides, Slides of Machine Learning

Partial preview of the text

Download Nonlinear Equations MATLAB Implementation-Machine Learning-Lecture Slides and more Slides Machine Learning in PDF only on Docsity!

Chapter 5Nonlinear Equations(MATLAB Implementation)

Dr. Muhammad Hanif DuradDepartment of Computer and Information SciencesPakistan Institute Engineering and Applied [email protected]

Most of the codes have been adopted from various books forNumerical Computing using MATLAB their references have beengiven in short on each topic

docsity.com

Dr. Hanif Durad^

2

Lecture Outline (1/2)  Plotting a function in MATLAB  Function Evaluation in MATLAB(Anonymous)  Interval Bisection Method  Fixed-Point Problems  Newton’s Method  Secant Method  Multidimensional Newton’s Method  Multidimensional Broyden’s Method

docsity.com

Function Evaluation inMATLAB (Anonymous)>> f=@(x) x^2-4sin(x)f = @(x)x^2-4sin(x)>> f(1)ans =-2.3659>> format long>> feval(f,1)ans =-2.

Dr. Hanif Durad^

(^4) docsity.com

Interval Bisection Method>> xm =demoBisect1(1,3,10)k a^ xmid^

Dr. Hanif Durad^

Fixed-Point Problems (2/2)

Dr. Hanif Durad^

7

xm =demoFixedPoint(0,-2,2,10 )left hand boundary is

-2.0000 and g`(x) =

right hand boundary is

2.0000 and g`(x) =

k^ x^ g(x)

abs(x(k+1)-x(k)) 0 0.^

0.300000^ 3.00000e- 1 0.^

0.313500^ 1.35000e- 2 0.^

0.315406^ 1.90574e- 3 0.^

0.315688^ 2.82662e- 4 0.^

0.315731^ 4.22170e- 5 0.^

0.315737^ 6.31181e- 6 0.^

0.315738^ 9.43816e- 7 0.^

0.315738^ 1.41134e- 8 0.^

0.315738^ 2.11045e- 9 0.^

0.315738^ 3.15588e- xm =0.

D:\NC\CVEN 302

( )^5

10 3 f^ x^

x^ x  ^

 docsity.com

Newton’s Method -First Prg.>> xm =demoNewton(3,10)k f(x)^ dfdx^

Dr. Hanif Durad^

  • 1 1. b f(xmid)
  • 2.00000000 3.
  • 3.628e-
    • 2 1.
    • 1.50000000 2.
    • -1.740e+
      • 3 1.
      • 1.75000000 2.
      • -8.734e-
        • 4 1.
        • 1.87500000 2.
        • -3.007e-
          • 5 1.
          • 1.93750000 2.
          • 1.985e-
            • 6 1.
            • 1.90625000 1.
            • -1.433e-
              • 7 1.
              • 1.92187500 1.
              • -6.241e-
                • 8 1.
                • 1.92968750 1.
                • -2.145e-
                  • 9 1.
                  • 1.93359375 1.
                  • -8.460e-
                    • 10 1. - 1. - 1.93750000 9.491e- - xm =1. - D:\NC\CVEN - 0 8.436e+ x(k+1) - 9.960e+ - 2. - 1 1.295e+ - 6.506e+ - 1. - 2 1.084e- - 5.404e+ - 1. - 3 1.152e- - 5.289e+ - 1. - 4 1.361e- - 5.288e+ - 1. - 5 2.220e- - 5.288e+ - 1. - 6 -4.441e- - 5.288e+ - 1. - 7 -4.441e- - 5.288e+ - 1. - 8 -4.441e- - 5.288e+ - 1. - 9 -4.441e- - 5.288e+ - 1. - xm =1. - D:\NC\CVEN

Newton’s Method -2nd Prg. (2/2)>> [p1,err,k,y]=newton(f,df,3,10^-6,10^-6,20)p1 =1.933753788557627err =2.177441944430925e-004k = (^4) y =1.360549464202165e-

Dr. Hanif Durad^

10

B4,P-

docsity.com

Secant Method (1/2)>> f=@(x) x^2 -4sin(x)f = @(x)x^2-4sin(x)>> format long

Dr. Hanif Durad^

11

B4,P-

docsity.com

Multidimensional Newton’sMethod (1/3)>> x0 =[1;1]; tol=1e-5; maxiter =10;>> [x,F,iter] = newtonsys(@Ffun,@Jfun ,x0 ,tol ,maxiter )The method converged at iteration 8 with residual 2.235421e-011x =0.4761-0.8794F =2.2354e-011iter = 8

Dr. Hanif Durad^

13

SCMO,P-

docsity.com

Multidimensional Newton’sMethod (2/3)>> [x,F,iter] = newtonsys(@Ffun,@Jfun ,x0 ,tol ,1 )Fails to converge within maximum number of iterations.The iterate returned has relative residual 4.722222e+000x =-0.83331.4167F =4.7222iter = 1

Dr. Hanif Durad^

(^14) docsity.com

Multidimensional Broyden’sMethod>> broyden2(3,[1;2],[2;1])ans =1.89320.0989>> broyden2(5,[1;2],[2;1])ans =2.4093-0.

Dr. Hanif Durad^

16

>> broyden2(10,[1;2],[2;1])ans = 2.0000-0.

B6,P-125 docsity.com

MATLAB Built-in Functions-fzero (1/2)>> f=@(x) x^2-4sin(x)f = @(x)x^2-4sin(x)>> x=fzero(f,[1 3])x =1.

Dr. Hanif Durad^

(^17) docsity.com