Results 1 to 5 of 5

Math Help - Excel/VBA/Simpson's Rule???

  1. #1
    Junior Member
    Joined
    Mar 2008
    From
    Ohio
    Posts
    26

    Exclamation Excel/VBA/Simpson's Rule???

    Hello all,

    I'm trying to figure out a code in Excel's VBA (visual basic, excel's macro programming thing) that will take input from an excel spreadsheet and perform the Simpson's Rule on a quadratic function. Ex: Take a,b,c as input from the spreadsheet (for the quadratic ax^2+bx+c=0) It also has to take the upper limit and lower limits of the integral (A=0, B=5) and the number of integers to use (n=100, etc) from the spreadsheet and give the answer as output on the spreadsheet.

    I know this probably sounds confusing, but I could really really use some help with this, I figured out the traprule already, just have no clue about the Simpson's Rule. Thanks!
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Senior Member
    Joined
    Feb 2008
    From
    Berkeley, Illinois
    Posts
    364
    Quote Originally Posted by UDaytonFlyer View Post
    Hello all,

    I'm trying to figure out a code in Excel's VBA (visual basic, excel's macro programming thing) that will take input from an excel spreadsheet and perform the Simpson's Rule on a quadratic function. Ex: Take a,b,c as input from the spreadsheet (for the quadratic ax^2+bx+c=0) It also has to take the upper limit and lower limits of the integral (A=0, B=5) and the number of integers to use (n=100, etc) from the spreadsheet and give the answer as output on the spreadsheet.

    I know this probably sounds confusing, but I could really really use some help with this, I figured out the traprule already, just have no clue about the Simpson's Rule. Thanks!
    In Excel, custom name a few cells. aval, bval, cval, inthigh, intlow, nval. This will stand for a, b, c, integral high value, integral low value, and integer n value. Now, in VB, do the following:

    Dim a, b, c, ihigh, ilow, simp1, fa, fb, simp2, adb, simpson, As Double
    Dim n as Integer

    ' Validate user input

    ' Inputs
    a = Range("aval").Value
    b = Range("bval").Value
    c = Range("cval").Value
    ihigh = Range("inthigh").Value
    ilow = Range("intlow").Value
    n = Range("nval").Value

    If Len(a) = 0 Or Len(b) = 0 Or Len(c) = 0 Or Len(ihigh) = 0 Or Len(ilow) = 0 Or Len(n) = 0 Then
    ' Alert user that entries have not been filled out
    MsgBox "You need to enter input values before continuing.", vbExclamation, "Warning Message"
    Exit Sub
    End If

    simp1 = (b-a)/6
    fa = (a * aval^2) + (b * aval) + c
    adb = (a + b)/2
    simp2 = 4 * ((a * adb^2) + (b * adb) + c)
    fb = (a * bval^2) + (b * bval) + c

    ' Calculate Simpson value
    simpson = simp1*(fa + simp2 + fb)

    I got that formula from here:

    http://en.wikipedia.org/wiki/Simpson's_Rule

    You'll need to output the simpson value somewhere on the spreadsheet or a message box. Let me know if you need help with that. I put this code together quickly this morning. i'm not sure how much VB/Excel knowledge you have, so if you do have questions, by all means, ask.

    I assume you are doing this in VBA to hide it from others, but it's very easy to do in Excel. I put in a warning message to validate user input, and made it an Exclamation warning to catch the user's eye if they make a mistake on entry points.
    Last edited by mathceleb; March 31st 2008 at 07:50 AM.
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Apr 2008
    Posts
    2

    trap rule

    Hey Flyer I am working on a VB code for the trap rule. You said you already figured it out. Think you could help me out?
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Newbie
    Joined
    Sep 2008
    Posts
    1

    I am working in php I have problem with numerical methods

    Hello,
    I am a MCA student.
    I am developing a site for maths in which I am implementing the numerical methods I have code for trapezoidal,simpsons1/3rd,simpsons3/8th rule in c but I want to convert it into PHP.Can you give me a solution .
    Actually I have written this code in PHP but its not working.I am not getting the proper solution will you please help me.
    Its urgent.
    Thanks and Regards,
    Bye.
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Senior Member
    Joined
    Feb 2008
    From
    Berkeley, Illinois
    Posts
    364
    For the .php conversion, do everything I did for the VB, adding dollar signs in front of the variables.

    Then, you would need to setup entry boxes for any user entry fields on my Excel file which are sent down to php and use the GET method. Are you familiar with that?
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Simpson's rule
    Posted in the Calculus Forum
    Replies: 0
    Last Post: February 10th 2010, 02:37 PM
  2. Replies: 0
    Last Post: October 20th 2008, 07:12 PM
  3. simpson's rule
    Posted in the Calculus Forum
    Replies: 2
    Last Post: May 17th 2008, 09:18 AM
  4. Trapezoid Rule/Simpson's Rule
    Posted in the Calculus Forum
    Replies: 1
    Last Post: May 16th 2007, 06:52 PM
  5. Replies: 3
    Last Post: August 31st 2006, 09:08 AM

Search Tags


/mathhelpforum @mathhelpforum