+ Reply to Thread
Results 1 to 5 of 5

summation

Hybrid View

  1. #1
    Registered User
    Join Date
    04-25-2007
    Posts
    2

    summation

    so i have this complicated function i need to sum (not sum as in add up - sum as in sum a series).
    my formula that needs to be summed:
    (2/(n*pi))*sin(n*pi*z/L)*e^(-(n^2)*pi*pi*k*t/(L^2))

    pi, z, L, k, t are constants, i want sum n from 1 to 10... i looked through all the "sum" functions but i couldnt find a summation in which i could enter a function to be summed.

    help?
    Thanks

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887
    Are you looking for something like:
    Sub sumSeries()
        Dim x As Double, n As Integer
        Const L = 50
        Const pi = 3.14
        Const z = 145
        Const k = 1
        Const e = 2.71
        
        For n = 1 To 10
            x = (2 / (n * pi)) * Sin(n * pi * z / L) * e ^ (-(n ^ 2) * pi * pi * k * t / (L ^ 2))
        Next n
        Sheets("Sheet1").Range("A1").Value = x
    End Sub

  3. #3
    Registered User
    Join Date
    04-25-2007
    Posts
    2
    hmm... yes, that should work.
    Thanks!

  4. #4
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887
    I think one adjustment might be necessary:

    Change:
    x = (2 / (n * pi)) * Sin(n * pi * z / L) * e ^ (-(n ^ 2) * pi * pi * k * t / (L ^ 2))
    to
    x = x + (2 / (n * pi)) * Sin(n * pi * z / L) * e ^ (-(n ^ 2) * pi * pi * k * t / (L ^ 2))
    so that after each iteration it adds the new value to the old. The previous version would just return the last value of x for when n=10, I believe.

  5. #5
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,391
    The only thing I might do differently would be to put in a Function procedure (aka UDF) rather than a Sub procedure. You could then either hard code the constants and n as above, or pass those values to the function as arguments. You could also put the function output wherever you want. It would make it a little more flexible. Because it is used like built in functions, it also fits into Excel's calculation sequence so that it will recalculate automatically (assuming calculation is set to automatic).
    Function sumseries(pi,z,L,k,t,n)
    sumseries=0
    For i=1 to n
    sumseries=sumseries+f(i)
    Next i
    end function
    You would then call the function from a spreadsheet cell as =sumseries(a1,a2,a3,...).
    Last edited by MrShorty; 04-25-2007 at 10:41 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1