简体   繁体   中英

Elements row sum function. VBA; MS Excel

I need someone to tell me why I get

compile error : Expected array

as soon as I try to use my function and what should be changed to get the result. As much as I understand there's no need in array usage according to task(explained below the code).

Public Function papild(x)
    Dim s As Double, A As Double
    Dim P As Integer
    s = 0.5 + (x - system.Math.Pi) / 1
    A = (x - system.Math.Pi) / 1
    P = 2
    Do While Abs(A) > 0.0001
        A = -A * (x - system.Math.Pi) * (x - system.Math.Pi) / P(P + 1)
        s = s + A
        P = P + 1
    Loop
    papild = s
End Function

----------------------------------------------------------------------------------------------
I'll try my best to explain the task of mine, I hope it would be useful for you to point out what's done wrong.

* Conditions: using ^ operator is forbidden. *
There's : Elements row sum formula - 在此处输入图片说明 and argument variation range - (-π/2) to (π/2) [Step: π/30].

My actions: one column is being used for argument value (first cell(@ Formula bar) =PI()/-2));every next cell is (@Formula bar) ="cell above" + PI()/30.;Writing the code(above) and calling the function in second column, using appropriate column one cell as function argument.
Thanks in advance.

(Sorry for my poor English, especially for math terminology)

as per the comments:

Public Function papild(x)
    Dim s As Double, A As Double
    Dim P As Integer
    s = 0.5 + (x - Application.WorksheetFunction.Pi()) / 1
    A = (x - Application.WorksheetFunction.Pi()) / 1
    P = 2
    Do While Abs(A) > 0.0001
        A = -A * (x - Application.WorksheetFunction.Pi()) * (x - Application.WorksheetFunction.Pi()) / P ^ (P + 1)
        s = s + A
        P = P + 1
    Loop
    papild = s
End Function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM