How calculate the sum of several functions in vba

BRUCEWAYNE

New Member
Joined
May 15, 2019
Messages
7
HI5 folks, I'd like to know how to calculate the sum of one function that has several values from 1,2,3 .... to n

the function is

z = (((1 + w) ^ 2))l = (((p) ^ (n - 1)))

y = ((z * l)) ^ ((n) / 2)

I'd like to know how to calculate the sum ∑ of y, for example from 1,2,3 .... to 10

when w=0,5 p=
0,993449, n= 10 doing the harder way line per line should return
199,0484.

<tbody>
</tbody>

How do it by writting in vba code the sum ∑ of y in order to get the results in a faster way ?

Please can someone help me with this problem ? many thanks
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
the function is

z = (((1 + w) ^ 2))



l = (((p) ^ (n - 1)))



y = ((z * l)) ^ ((n) / 2)


the
'L' variable is l = (((p) ^ (n - 1)))

I'd like to know how to calculate the sum ∑ of y, for example from 1,2,3 .... to 10

when w=0,5 p=
0,993449, n= 10 doing the harder way line per line should return
199,0484.

<tbody>
</tbody>


How do it by writting in vba code the sum ∑ of y in order to get the results in a faster way ?

many thanks in advance
 
Upvote 0
Maybe I did not understand exactly what you need - I found a different result for n = 10, that is: 138,791

Code:
Function GetSum(w As Double, p As Double, k As Long)
    Dim Z As Double, y As Double, l As Double, n As Long
    Dim dbSum As Double
    
    Z = (((1 + w) ^ 2))
    For n = 1 To k
        l = (((p) ^ (n - 1)))
        y = ((Z * l)) ^ ((n) / 2)
        'Just to check...
        Debug.Print "y(" & n & ") = " & y
        dbSum = dbSum + y
    Next n
    GetSum = dbSum
End Function

Debug.Print produced these results
y(1)=1,5
y(2)=2,23526
y(3)=3,309105
y(4)=4,866744
y(5)=7,110695
y(6)=10,32122
y(7)=14,88319
y(8)=21,32093
y(9)=30,34325
y(10)=42,90062

<tbody>
</tbody>

Formula (; as argument separator in my Excel version)
=getsum(0,5;0,993449;10)

M.
 
Last edited:
Upvote 0
ok. yeah it's a mistake that i made here , when put 11 i gave Result = 199,0484.

I´ve got a doubt : How Can i see
these written results (one by one), (such as in the column B) produced by Debug.Print from n = 1, 2,....11? How do you that?

I would appreciate to hear from you
 
Upvote 0
Alt+F11 to open VBEditor

Menu
View > Immediate window

or Ctrl+G

Debug.Print in my function displays y(1), y(2)....y(n) in the Immediate Window

M.
 
Last edited:
Upvote 0
If you do want to see the results in a worksheet execute the sub Main that calls the sub sGetSum

Code:
Sub Main()
    Dim w As Double, p As Double, k As Long
    
    w = 0.5
    p = 0.993449
    k = 10
    sGetSum w, p, k
End Sub


Code:
Sub sGetSum(w As Double, p As Double, k As Long)
    Dim Z As Double, y As Double, l As Double, n As Long
    Dim dbSum As Double, dbResults() As Double
    
    ReDim dbResults(1 To k, 1 To 2)
    
    Z = (((1 + w) ^ 2))
    
    For n = 1 To k
        l = (((p) ^ (n - 1)))
        y = ((Z * l)) ^ ((n) / 2)
        dbResults(n, 1) = n
        dbResults(n, 2) = y
        dbSum = dbSum + y
    Next n
    
    'Display results
    Columns("B:C").ClearContents
    Range("B1:C1") = Array("y", "Value")
    Range("B2").Resize(k, 2) = dbResults
    Range("B2").Offset(k) = "Result"
    Range("C2").Offset(k) = dbSum
End Sub

M.
 
Upvote 0
Debug.Print produced these results that you mentioned above:
y(1)=1,5
y(2)=2,23526
y(3)=3,309105
y(4)=4,866744
y(5)=7,110695
y(6)=10,32122
y(7)=14,88319
y(8)=21,32093
y(9)=30,34325
y(10)=42,90062

<tbody>
</tbody>
PRODUCT =
1636964555

<tbody>
</tbody>

How can i find in vba the product Π of y(x)= y(1)* y(2)* y(3)* y(4)* y(5)* y(6)* y(7)* y(8)* y(9)* y(10)???****** id="cke_pastebin" style="position: absolute; top: 343px; width: 1px; height: 1px; overflow: hidden; left: -1000px;">
1636964555

<tbody>
</tbody>
</body>
 
Upvote 0
Try

Code:
Function GetProd(w As Double, p As Double, k As Long)
    Dim Z As Double, y As Double, l As Double, n As Long
    Dim dbProd As Double
    
    Z = (((1 + w) ^ 2))
    dbProd = 1
    For n = 1 To k
        l = (((p) ^ (n - 1)))
        y = ((Z * l)) ^ ((n) / 2)
        'Just to check...
        Debug.Print "y(" & n & ") = " & y
        dbProd = dbProd * y
    Next n
    GetProd = dbProd
End Function

Excel

Formula (; as argument separator in my excel version)
=GetProd(0,5;0,993449;10)

M.
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,823
Members
449,049
Latest member
cybersurfer5000

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top