Results 1 to 2 of 2

Math Help - MATLAB "bisection" method

  1. #1
    Newbie
    Joined
    Jan 2009
    Posts
    3

    MATLAB "bisection" method

    How to create a MATLAB function that uses the bisection method to find the value of the interest rate "r" implicit in a loan that specifies the borrowed amount 'L", the monthly payment "C", the number of years "T", and the number of capitalizations per year "n" ???


    I got the formula, but don't know what to do....

    C = L0 { r/n + (r/n)/[(1+ r/n)^Tn]-1] }
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Member
    Joined
    Mar 2007
    Posts
    206
    Awards
    1
    Im not sure if I deciphered your equation correctly but this code might help you out a little bit.



    Code:
    clear
    clc
    % http://en.wikipedia.org/wiki/Bisection_method
    
    L = 400000;       %Loan amount
    n = 12;         %monthly compounds
    T = 30;         %years
    C = 2400;       %Rate 
    
    epsilon = 0.0000001; %Error to exit on
    
    
    
    
    %Bounds for r
    ri = 0.05; % lower bound
    rj = 0.15;   %upper bound
    
    i = 0; %start counter
    
    while abs(rj-ri) > 2*epsilon;
        i = i +1; %keep track of iterations
        
        rm = (rj+ri)/2; %mid point
        
        Si = L *( ri/n + (ri/n)/((1+ ri/n)^((T*n)-1))) - C; %evaluate function at lower bound
        Sj = L *( rj/n + (rj/n)/((1+ rj/n)^((T*n)-1))) - C;%evaluate function at upper bound
        Sm = L *( rm/n + (rm/n)/((1+ rm/n)^((T*n)-1))) - C;%evaluate function at midpoint
        
        if Si*Sm > 0    
            ri = rm;
        else
            rj = rm;
        end
    end
    r = (ri+rj)/2;
    disp(['Solution found in ' num2str(i) ' iterations'])
    disp(['r = ' num2str(r)]);
    disp(['Evaluateing S @ r, S = ' num2str(L*(r/n + (r/n)/((1+ r/n)^((T*n)-1))) - C)])
    You should get a output in the comand window that looks something like this

    Code:
    Solution found in 19 iterations
    r = 0.06229
    Evaluateing S @ r, S = -0.0006425
    Regards, Elabrto
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 2
    Last Post: April 24th 2011, 08:01 AM
  2. Replies: 1
    Last Post: October 25th 2010, 05:45 AM
  3. Plotting "Continuous" Histograms in Octave/Matlab
    Posted in the Math Software Forum
    Replies: 6
    Last Post: August 13th 2010, 11:46 PM
  4. Replies: 1
    Last Post: June 4th 2010, 11:26 PM
  5. Matlab Split vectors,if statements, and "for loop"
    Posted in the Math Software Forum
    Replies: 5
    Last Post: February 27th 2010, 03:30 AM

Search Tags


/mathhelpforum @mathhelpforum