laboratory 4 newton-raphson

2
Gerfel Philip Gonzales BSECE 5 Newton-raphson Method 1 SCINOTE CODE //Gerfel Philip C. Gonzales //BSECE 5 //Laboratory 3 //Simple Fixed-point Method function fixed_point() f = input("Input the rearranged function to be evaluated:","string"); p0 = input("Input initial guess p0:"); es = input("Input your desired stopping criterion:"); maxiter = input("Maximum no. of iterations:"); disp(['Root Error']) for iter = 1:maxiter; x = p0; p = evstr(f); er = abs((p-p0)/(abs(p)+%eps)); printf('%8.4f %f\n',p,er); //evaluation if (er <= es) then break end; if (er == 1) then break end; p0 = p; end if (er == 1) then disp('The algorithm is diverging.'); else printf('\n\nRoot is %f with %f error at %dth iteration',p,er,iter); end endfunction

Upload: gp-gonzales

Post on 11-Nov-2015

216 views

Category:

Documents


3 download

DESCRIPTION

asdfjaslfjladsjf jasl jalf ajf laj alj klajfj adsfljiogo qehgo og wogih woihgkjdnbioh wl vjoe ubho abj klb gl go ewo iohg mg iud h dgjp

TRANSCRIPT

  • Gerfel Philip Gonzales BSECE 5

    Newton-raphson Method

    1 SCINOTE CODE

    //Gerfel Philip C. Gonzales

    //BSECE 5

    //Laboratory 3

    //Simple Fixed-point Method

    function fixed_point()

    f = input("Input the rearranged function to be evaluated:","string");

    p0 = input("Input initial guess p0:");

    es = input("Input your desired stopping criterion:");

    maxiter = input("Maximum no. of iterations:");

    disp(['Root Error'])

    for iter = 1:maxiter;

    x = p0;

    p = evstr(f);

    er = abs((p-p0)/(abs(p)+%eps));

    printf('%8.4f %f\n',p,er);

    //evaluation

    if (er

  • Gerfel Philip Gonzales BSECE 5

    2 SIMULATION

    Find the root of + = with a approximation error of . and maximum number of

    iteration of 100 starting with x = 0.75.

    Rearranged =

    .

    2.1 CHOOSING A GUESS ROOT OF 0 .75