promotion image of download ymail app
Promoted
失敗情人 發問時間: 社會與文化語言 · 1 0 年前

那位大大能用MATLAB 幫我解開這個數值分析 很急20點

Determine the positive real root of ln(x^2)=0.7

(a)graphically

(b)useing three interations of the bisection method,

with initial guesses of Xl=0.5 and Xu=2

(c)ueing three interations of the false-position method with

the same initil guesses as in (b)

1 個解答

評分
  • 老師
    Lv 7
    1 0 年前
    最佳解答

    (a)

    >> clear

    >> f=@(x) log(x^2)-0.7;

    >> fplot(f,[0.1,10])

    >> grid on

    (b)

    >> x=bisection(f,0.5,2)

    x =

    1.4191

    (c)

    >> x2=falsi(f,0.5,2)

    falsi method has converged

    x2 =

    1.4191

    ------------------------------------

    bisection 程式 (二分法)

    function root = bisection(func,xl,xu,es,maxit)

    % root = bisection(func,xl,xu,es,maxit):

    % uses bisection method to find the root of a function

    % input:

    % func = name of function

    % xl, xu = lower and upper guesses

    % es = (optional) stopping criterion (%)

    % maxit = (optional) maximum allowable iterations

    % output:

    % root = real root

    if func(xl)*func(xu)>0 %if guesses do not bracket a sign change

    disp('no bracket') %display an error message

    return %and terminate

    end

    % if necessary, assign default values

    if nargin<5, maxit=50; end %if maxit blank set to 50

    if nargin<4, es=0.001; end %if es blank set to 0.001

    % bisection

    iter = 0;

    if abs(xl)==abs(xu)

    xu=xu+0.01;

    end

    xr = xl;

    while (1)

    xrold = xr;

    xr = (xl + xu)/2;

    iter = iter + 1;

    if xr ~= 0, ea = abs((xr - xrold)/xr) * 100; end

    test = func(xl)*func(xr);

    if test < 0

    xu = xr;

    elseif test > 0

    xl = xr;

    else

    ea = 0;

    end

    if ea <= es | iter >= maxit, break, end

    end

    root = xr;

    -------------------------------------------

    2007-11-14 09:38:01 補充:

    試位法程式貼不下

    所以沒有貼上

    二分法 試位法 牛頓法 正割法都不是內建指令

    • Commenter avatar登入以對解答發表意見
還有問題?馬上發問,尋求解答。