Demo entry 6363183

数值计算方法

   

Submitted by suzui961228 on May 12, 2017 at 13:49
Language: Matlab. Code size: 635 Bytes.

clc;clear;
a=0.5;b=1.5;                          %将a、b作为区间两端的参数
fa=exp(a)-2-cos(exp(a)-2);            %将fa、fb作为两端函数值的储存参数
fb=exp(b)-2-cos(exp(b)-2);

while(abs(a-b)>10^(-5))              
    dx=fb*(b-a)/(fb-fa);             
    c=b-dx;                          %get the cross point
    ac=c-a;
    fc=exp(c)-2-cos(exp(c)-2);      % update the target value with the cross point
    if fc==0
        break;
    else if fb*fc >0
        b=c;  
        fb=fc;
    else fa*fc>0
        a=c;
        fa=fc;
        end
    end
    dx=min(abs(dx),ac);
    if abs(dx)<10^(-5),break,end
end
x=c;

x= 0.347296355337284

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).