[RESOLVED] How to Find R in formula??-VBForums
Results 1 to 4 of 4

Thread: [RESOLVED] How to Find R in formula??

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2012
    Posts
    60

    Resolved [RESOLVED] How to Find R in formula??

    hi all,

    am using DAO in VB6 and MS-Access as back hand.

    now, i have a formula, u can find out EMI for Loan with that formula. formula is as below.

    EMI = P * R * (1 + R)^N / ((1 + R)^N - 1) ----> Plz Note "R" = R/1200

    Now i can find EMI through above formula in vb6.

    now i want to find "R" from that.
    eg. If P = 100000, N = 36 Months, EMI = 3227, R = ??
    its Answer is 10 ( R = 10%)
    but how can i calculate through vb6 coding.

    plz. HELP me on this if possible.

    thanks a lot in advance.

    kaushal

  2. #2
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,390

    Re: How to Find R in formula??

    There is no "nice" formula for R in terms of the remaining variables, however you can numerically compute R pretty easily using a method called "quadrature", where I'm assuming a solution exists somewhere, and the EMI function constantly increases. Hopefully these are reasonable assumptions. The following VB.NET (sorry, I don't have access to VB6 anymore) code gives R=0.008338... on your input, which agrees with the results of a numerical solver. (You said the answer should be R=10%=0.1, but I don't believe you since plugging this in directly doesn't give equality. Maybe you haven't listed some unit conversion somewhere or your numbers aren't right.)
    .
    VB Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    4.         MessageBox.Show(FindR(3227, 100000, 36))
    5.     End Sub
    6.  
    7.     Private Function FindR(EMI As Double, P As Double, N As Double) As Double
    8.         'Use "quadrature" to find the solution
    9.         Dim MinR As Double
    10.         Dim MaxR As Double
    11.         Dim MidR As Double
    12.         MinR = 0
    13.         MaxR = 1
    14.         Do Until Math.Abs(MaxR - MinR) < 0.000001
    15.             Dim TestVal As Double
    16.  
    17.             MidR = (MaxR + MinR) / 2
    18.             TestVal = P * MidR * (1 + MidR) ^ N / ((1 + MidR) ^ N - 1)
    19.             If TestVal < EMI Then
    20.                 MinR = MidR
    21.             Else
    22.                 MaxR = MidR
    23.             End If
    24.         Loop
    25.  
    26.         Return MidR
    27.     End Function
    28. End Class
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2012
    Posts
    60

    Re: How to Find R in formula??

    hi Jemidiah,

    thanks a lot for ur reply and help. i solve my problem with ur suggestion.

    if u read my question carefully then u find that i clearly mention there that value of "R" in formula is "R" = R / 1200. so here in ur suggestion u find R = 0.008338.
    now u just have to multiply it with 1200. eg. R = 0.008338 * 1200 = "10.0056" which i mention in my question.

    anyway, thanks a lot for your Help.

    kaushal

  4. #4
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,390

    Re: [RESOLVED] How to Find R in formula??

    Cool, glad it worked out.

    While I suppose it doesn't matter, for the unit conversion you had said, "Plz Note "R" = R/1200", which I do not find at all "clear". Given your most recent post, by "R" on the left you actually meant the R which appears in your formula, and by R on the right you meant an R which does not appear in your formula. I thought you were defining a new variable "R" and not using it later, which is not the case. To be honest, this point is stupid and needlessly confusing. You should probably have just ignored the unit conversion entirely since it's irrelevant to the problem.
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.