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

Post on 12-Apr-2017

180 views

Category:

## Education

Embed Size (px)

TRANSCRIPT

• MATLAB

MATLAB

:

-

• : -1

-) MATLAB ( -2

Bisection -Regula - Falsi False Position

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

)Matlab ( -42

• MATLAB

:

3

: ) (

• 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

• MATLAB

. . :

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

5

• MATLAB

)(6

• MATLAB

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

f (x) 0 :

7

• MATLAB

:

:

:

. c :

8

• MATLAB

9

:: . * *

. *

• MATLAB

10

• 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

• MATLAB

12

:

f (a)f (b)

• MATLAB

]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

• MATLAB

14

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

• MATLAB

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

• MATLAB

16

| |n nn

a ba

| |n na b

• MATLAB

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

• MATLAB

:

:

:

. 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

• MATLAB

19

• MATLAB

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

• MATLAB

21

11 ba

:

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

• MATLAB

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

• MATLAB

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

• MATLAB

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

• MATLAB

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

• MATLAB

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 ||

• MATLAB

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 ||