¢…ˆ²´ …­§³¨§ ¹¯¯œ -...

Download ¢…ˆ²´ …­§³¨§ ¹¯¯Œ - ¨®´ ´´…

If you can't read please download the document

Post on 12-Apr-2017

180 views

Category:

Education

6 download

Embed Size (px)

TRANSCRIPT

  • MATLAB

    faradars.org/fvmth102

    MATLAB

    :

    -

    FaraDars.org

  • : -1

    -) MATLAB ( -2

    Bisection -Regula - Falsi False Position

    ) MATLAB ( -3)Secant( - )Newton-Raphson( - -)Fixed-Point( -

    )Matlab ( -42

    FaraDars.org

  • MATLAB

    faradars.org/fvmth102

    :

    3

    : ) (

    FaraDars.org

  • MATLAB

    faradars.org/fvmth102 x : = f() f()0

    . x x(f( :

    )x(f = )x(1f-)x(2f ) (

    a < x < b .

    : (bisection method) ) 1False position or regula) ) 2 falsi)

    4

    FaraDars.org

  • MATLAB

    faradars.org/fvmth102

    . . :

    .1 .2. .3. .4. *

    5

    FaraDars.org

  • MATLAB

    faradars.org/fvmth102

    )(6

    FaraDars.org

  • MATLAB

    faradars.org/fvmth102 )Bisection(f(x)=0: . : :

    y = f(x) [a,b] .f(a).f(b) < 0

    f (x) 0 :

    7

    FaraDars.org

  • MATLAB

    faradars.org/fvmth102 )Bisection(

    :

    :

    :

    . c :

    8

    FaraDars.org

  • MATLAB

    faradars.org/fvmth102 )Bisection(

    9

    :: . * *

    . *

    FaraDars.org

  • MATLAB

    faradars.org/fvmth102)Bisection( matlab

    10

    FaraDars.org

  • MATLAB

    faradars.org/fvmth102)Bisection( matlab

    11

    function bisect(f,a,b,tol,n)% Bisection method for solving the nonlinear %equation f(x)=0.a0=a;b0=b; iter=0;u=feval(f,a);v=feval(f,b);c=(a+b)*0.5;err=abs(b-a)*0.5;disp('_______________________________________')disp(' iter a b c f(c) |b-a|/2 ')disp('_______________________________________')fprintf('\n')if (u*vtol)&(itern)

    disp(' Method failed to converge')end

    elsedisp(' The method cannot be applied f(a)f(b)>0')

    end% Plot f(x) in the interval [a,b].fplot(f, [a0 b0])xlabel('x');ylabel('f(x)');grid

    FaraDars.org

  • MATLAB

    faradars.org/fvmth102Bisection

    12

    :

    f (a)f (b)

  • MATLAB

    faradars.org/fvmth102Bisection

    ]1 ,2[ 2x-3x)=x(f-1

    13

    >>bisect('f1',1,2,10^(4),40)iter abcf(c)|ba|/2________________________________________________01.00002.00001.5000000.1250000.50000011.00001.50001.2500000.6093750.25000021.25001.50001.3750000.2910160.12500031.37501.50001.4375000.0959470.06250041.43751.50001.4687500.0112000.03125051.43751.46881.4531250.0431940.01562561.45311.46881.4609380.0162030.00781371.46091.46881.4648440.0025540.00390681.46481.46881.4667970.0043100.00195391.46481.46681.4658200.0008750.000977101.46481.46581.4653320.0008400.000488111.46531.46581.4655760.0000170.000244121.46531.46561.4654540.0004110.000122

    FaraDars.org

  • MATLAB

    faradars.org/fvmth102)Bisection(

    14

    ===========================================================================================================================

    FaraDars.org

  • MATLAB

    faradars.org/fvmth102Bisection

    15

    f : (x) . 10-6

    =========================================================================================================

    : n )

    :

    . 10-6 19

    61 1 1 1

    2 1| | ( ) 102 2n n n n n

    b ac b a

    6( 1) log(2) 6 1 19log 2

    n or n

    FaraDars.org

  • MATLAB

    faradars.org/fvmth102 )Bisection(: :

    16

    | |n nn

    a ba

    | |n na b

    FaraDars.org

  • MATLAB

    faradars.org/fvmth102

    f (x) [a,b] .

    False Position Regula Falsi Bisection

    . 3 x :

    False Position

    17

    2 13 2 2

    2 1

    ( )( ) ( )

    x xx x f x

    f x f x

    1 1( , ( ))x f x2 2( , ( ))x f x

    FaraDars.org

  • MATLAB

    faradars.org/fvmth102)False Position(

    :

    :

    :

    . c : 18

    n

    n

    n

    n

    bcbf

    acaf

    nn

    nnnn bfaf

    babfbc

    anbn

    f(an)

    next estimate, c

    f(bn)

    F(c)

    nnn

    nnnn

    bbcaotherwiseaacbafcfif

    11

    11

    ,,0)().(

    2111 ||/|| ceorandabe nnnn

    FaraDars.org

  • MATLAB

    faradars.org/fvmth102 False position

    19

    FaraDars.org

  • MATLAB

    faradars.org/fvmth102 False positionMatlab

    function false(f,a,b,tol,n)

    % False position method for solving the nonlinear

    % equation f(x)=0.

    a0=a;

    b0=b;

    iter=0;

    u=feval(f,a);

    v=feval(f,b);

    c=(v*a-u*b)/(v-u);

    w=feval(f,c);

    disp('_________________________________________')

    disp(' iter a b c f(c) |b-a|')

    disp('_________________________________________')

    fprintf('\n')

    if (u*vtol)&(abs(b-a)>tol)&(itern)

    disp(' Method failed to converge')

    end

    if (v-u==0)

    disp(' Division by zero')

    end

    else

    disp(' The method cannot be applied f(a)f(b)>0')

    end

    % Plot f(x) in the interval [a,b].

    fplot(f,[a0 b0])

    xlabel('x');ylabel('f(x)'); grid

    FaraDars.org

  • MATLAB

    faradars.org/fvmth102 False Position

    21

    11 ba

    :

    ===========================================================================================================================

    FaraDars.org

  • MATLAB

    faradars.org/fvmth102 ]1 ,2[ 2x-3x)=x(f-1

    22

    >>fals('f1',1,2,10^(4),40)________________________________________________iter ab c f(c) |ba|________________________________________________

    01.00002.00001.2500000.6093751.00000011.25002.00001.3766230.2862640.75000021.37662.00001.4309250.1176600.62337731.43092.00001.4524020.0456710.56907541.45242.00001.4606130.0173310.54759851.46062.00001.4637120.0065200.53938761.46372.00001.4648750.0024450.53628871.46492.00001.4653100.0009160.53512581.46532.00001.4654740.0003430.53469091.46552.00001.4655350.0001280.534526101.46552.00001.4655580.0000480.534465

    FaraDars.org

  • MATLAB

    faradars.org/fvmth102 )False Position()False Position(

    23

    1 1

    1 1

    0,1, ...,( ) ( )

    ( ) ( )( ). ( ) 0, ,

    , , .

    n n n n

    n n

    n n n n

    n n n

    for n ITMAXf b a f a b

    cf b f a

    if f a f c set a a b cotherwise set a c b b

    FaraDars.org

  • MATLAB

    faradars.org/fvmth102)Modified False Position(

    0a=0c na(f=F( nb(f=G(: :

    :

    :

    . c : 24

    FG

    FbGabfafbabfbc

    nn

    nnnnn

    ][

    1

    2/,)(,

    2/,)(,0)().(

    1111

    11111

    GGafFbbcaotherwise

    FFbfGcbaacfcfif

    nnnnn

    nnnnnnn

    21111 ||/|| nnnnn ceorandabe

    FaraDars.org

  • MATLAB

    faradars.org/fvmth102Modified False positionMatlab

    function Modified_fals(f,a,b,tol,n)

    % False position method for solving the nonlinear

    % equation f(x)=0.

    a0=a;

    b0=b;

    iter=0;

    F=feval(f,a);

    G=feval(f,b);

    c=(G*a-F*b)/(G-F);

    W=feval(f,c);

    disp('______________________________________________')

    disp(' iter a b c f(c) |b-a|')

    disp('______________________________________________')

    fprintf('\n')

    if (F*Gtol)&(abs(b-a)>tol)&(itern)

    disp(' Method failed to converge')endif (G-F==0)

    disp(' Division by zero')end

    elsedisp(' The method cannot be applied f(a)f(b)>0')

    end % Plot f(x) in the interval [a,b].fplot(f,[a0 b0])xlabel('x');ylabel('f(x)'); grid

    FaraDars.org

  • MATLAB

    faradars.org/fvmth102 Modified False Position

    26

    :

    ===========================================================================================================================

    : ) 3)=0b(f=G 0=(-1a(f=F

    : c -

    : -

    -

    .

    25.1)1(3

    ]1231[][1

    00

    00

    00001

    c

    FGFbGa

    bfafbabfbc

    5.12/,6094.0)(

    25.1,20)()(1&6094.0)(

    11

    110110001

    GGcafF

    cabbcfcfaccf

    tolcf )( 1tolaab

    1

    11 ||

    FaraDars.org

  • MATLAB

    faradars.org/fvmth102 Modified False Position

    27

    - )

    : -

    -

    .

    .

    tolcf )( 2

    4667.1)6094.0(5.1

    )]6094.0(25.125.1[][2

    11

    11

    11112

    c

    FGFbGa

    bfafbabfbc

    00397.0)(,3047.02/

    25.1,4667.10)()(25.1&00397.0)(

    22

    12221212

    cbfGFF

    aacbcfcfccf

    tola

    ab

    1

    11 ||

    FaraDars.org

  • MATLAB

    faradars.org/fvmth102 ]1 ,2[ 2x-3x)=x(f-1

    28

    _________________________________________________iter a b c f(c) |ba|_________________________________________________01.00002.00001.2500000.6093751.00000011.25002.00001.4666670.0038520.75000021.25001.46671.4639620.0056450.21666731.46401.46671.4659790.0014310.00270541.46401.46601.4653000.0009530.00201751.46531.46601.4656870

View more >