Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Calculate Elapsed Time of calculation

  1. Sep 20, 2011 #1
    Hi experts!
    Here is my program.



    %Bisection Method
    clc
    close all
    clear all
    f=input('Enter any Equation: ','s');
    f=inline(f);
    n=1;
    a=input('Enter 1st guess: ');
    b=input('Enter 2nd guess: ');
    tol=input('Enter tolerance: ');
    m=(a+b)/2;
    while(abs(f(m))>tol)
    n=n+1
    if(f(m)*f(a)<0)
    b=m
    else
    a=m
    end
    m=(a+b)/2;
    end
    fprintf('The root of equation is: %f\nNumber of iterations is: %d',m,n)
    %END



    I want to know how much time this program will take to calculate root of the given equation.
    I tried it to do, i.e. given below,(The program below is with changes made for elapsed time)
    %Bisection Method
    clc
    close all
    clear all
    f=input('Enter any Equation: ','s');
    f=inline(f);
    n=1;
    tic
    a=input('Enter 1st guess: ');
    b=input('Enter 2nd guess: ');
    tol=input('Enter tolerance: ');
    m=(a+b)/2;
    while(abs(f(m))>tol)
    n=n+1
    if(f(m)*f(a)<0)
    b=m
    else
    a=m
    end
    m=(a+b)/2;
    end
    fprintf('The root of equation is: %f\nNumber of iterations is: %d',m,n)
    sec=toc
    fprintf('%f',sec)
    %END


    Is this modified version(using tic toc) correct?
    Does this calculate the correct time? I don't think so.
     
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted



Similar Discussions: Calculate Elapsed Time of calculation
Loading...