roots findings 1

Upload: jintao

Post on 07-Jul-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/19/2019 Roots Findings 1

    1/18

    ROOTS FINDINGSMuhammad Arslan

  • 8/19/2019 Roots Findings 1

    2/18

    Overview

    • Introduction

    • Plotting

    • Fixed Point Iteration

    • Bisection Method

    • Newton Raphson Method

    • Secant Method

  • 8/19/2019 Roots Findings 1

    3/18

    Introduction

  • 8/19/2019 Roots Findings 1

    4/18

    Plotting

  • 8/19/2019 Roots Findings 1

    5/18

  • 8/19/2019 Roots Findings 1

    6/18

  • 8/19/2019 Roots Findings 1

    7/18

    Fixed Point Iteration

    clear allxinit=input(‘Enter the initial value of x’); 

    f=@(x)2*sin(x.^2);

    xnext=f(xinit);

    while(abs(xnext-xinit)>1e-4)

    xinit=xnext;

    xnext=f(xinit);end

    disp([‘ Root is ‘ num2str(xnext)]);

  • 8/19/2019 Roots Findings 1

    8/18

  • 8/19/2019 Roots Findings 1

    9/18

  • 8/19/2019 Roots Findings 1

    10/18

    Bisection

  • 8/19/2019 Roots Findings 1

    11/18

  • 8/19/2019 Roots Findings 1

    12/18

  • 8/19/2019 Roots Findings 1

    13/18

  • 8/19/2019 Roots Findings 1

    14/18

    Newton Raphson Method

  • 8/19/2019 Roots Findings 1

    15/18

    clear all

    x(1)= input(‘ Starting guess ’); 

    f=@(x)exp(x)-exp(-2*x)+1;

    fp=@(x)exp(x)+2*exp(-2*x);

    for i=1:100x(i+1)=x(i)-f(x(i))/fp(x(i));

    if(x(i+1)==x(i))

    break;

    end

    end

    x(end)

  • 8/19/2019 Roots Findings 1

    16/18

    Or Alternatively

  • 8/19/2019 Roots Findings 1

    17/18

    Secant Method

  • 8/19/2019 Roots Findings 1

    18/18

    Clear all

    x(1)= input(‘ Starting guess 1 ’); 

    x(2)= input(‘ Starting guess 2 ’); 

    f=@(x)3*x+sin(x)-exp(x);

    for i=1:100x(i+2)=x(i)-f(x(i))*(x(i+1)-x(i))/(f(x(i+1))-f(x(i)));

    if(x(i+2)==x(i+1))

    break;

    end

    end

    x(end)