Login     Register

        Contact Us     Search

XLeratorDB/math Documentation

SQL Server SERIESSUM function


SERIESSUM
 
Updated: 17 August 2010 
Use SERIESSUM to calculate the sum of a power series.
Syntax
SELECT [westclintech].[wct].[SERIESSUM] (
   <@x, float,>
 ,<@n, float,>
 ,<@m, float,>
 ,<@a_TableName, nvarchar(4000),>
 ,<@a_ColumnName, nvarchar(4000),>
 ,<@a_GroupedColumnName, nvarchar(4000),>
 ,<@a_GroupedCoulmnValue, float,>)
Arguments
@x
the base of power series. @x is an expression of type float or of a type that can be implicitly converted to float
@n
the initial power to which x is raised. @n is an expression of type float or of a type that can be implicitly converted to float
@m
the increment to the power for each term in the series. @m is an expression of type float or of a type that can be implicitly converted to float
 
@a_TableName
the name of the table which contains the coefficients. @a_TableName is an expression of character data. @a_TableName must be of a data type that is implicitly convertible to varchar.
 
@a_ColumnName
the name of the column in the table which contains the coefficients. @a_ColumnName is an expression of character data. @a_ColumnName must be of a data type that is implicitly convertible to varchar.
 
@a_GroupedColumnName
the name of the column in the table which in which the results will be grouped. @a_GroupedColumnName is an expression of character data. @a_GroupedColumnName must be of a data type that is implicitly convertible to varchar.
 
@a_GroupedColumnValue
the value in the Grouped Column that is to be used for aggregating the results. @a_GroupedColumnValue is an expression of character data. @a_GroupedColumnValue must be of a data type that is implicitly convertible to varchar.
Return Types
float
Remarks
·          The number of terms in a power series is dependent on the number of terms in the coefficient table. If there are 5 rows in the coefficient table, then SERIESSUM will evaluate the power series for those 5 coefficients.
·         Many power series are meant to be evaluated to infinity, so much of the time SERRIESSUM can be used to arrive at good approximations of those series.
Example
This example will calculate 'e' which is the same as EXP(1)
Create the following table
CREATE TABLE [dbo].[COEFFICIENTS](
      [factor_name] [varchar](50) NOT NULL,
      [seqno] [float] NOT NULL,
      [factor] [float] NOT NULL,
 CONSTRAINT [PK_COEFFICIENTS] PRIMARY KEY CLUSTERED
(
      [factor_name] ASC,
      [seqno] ASC
)
Insert these values into the table
 
INSERT INTO COEFFICIENTS VALUES('e',1,1)
INSERT INTO COEFFICIENTS VALUES('e',2,1/wct.fact(1))
INSERT INTO COEFFICIENTS VALUES('e',3,1/wct.fact(2))
INSERT INTO COEFFICIENTS VALUES('e',4,1/wct.fact(3))
INSERT INTO COEFFICIENTS VALUES('e',5,1/wct.fact(4))
INSERT INTO COEFFICIENTS VALUES('e',6,1/wct.fact(5))
INSERT INTO COEFFICIENTS VALUES('e',7,1/wct.fact(6))
INSERT INTO COEFFICIENTS VALUES('e',8,1/wct.fact(7))
INSERT INTO COEFFICIENTS VALUES('e',9,1/wct.fact(8))
INSERT INTO COEFFICIENTS VALUES('e',10,1/wct.fact(9))
INSERT INTO COEFFICIENTS VALUES('e',11,1/wct.fact(10))
INSERT INTO COEFFICIENTS VALUES('e',12,1/wct.fact(11))
INSERT INTO COEFFICIENTS VALUES('e',13,1/wct.fact(12))
INSERT INTO COEFFICIENTS VALUES('e',14,1/wct.fact(13))
INSERT INTO COEFFICIENTS VALUES('e',15,1/wct.fact(14))
INSERT INTO COEFFICIENTS VALUES('e',16,1/wct.fact(15))
INSERT INTO COEFFICIENTS VALUES('e',17,1/wct.fact(16))
INSERT INTO COEFFICIENTS VALUES('e',18,1/wct.fact(17))
INSERT INTO COEFFICIENTS VALUES('e',19,1/wct.fact(18))
INSERT INTO COEFFICIENTS VALUES('e',20,1/wct.fact(19))
INSERT INTO COEFFICIENTS VALUES('e',21,1/wct.fact(20))
INSERT INTO COEFFICIENTS VALUES('e',22,1/wct.fact(21))
INSERT INTO COEFFICIENTS VALUES('e',23,1/wct.fact(22))
INSERT INTO COEFFICIENTS VALUES('e',24,1/wct.fact(23))
INSERT INTO COEFFICIENTS VALUES('e',25,1/wct.fact(24))
INSERT INTO COEFFICIENTS VALUES('e',26,1/wct.fact(25))
INSERT INTO COEFFICIENTS VALUES('e',27,1/wct.fact(26))
INSERT INTO COEFFICIENTS VALUES('e',28,1/wct.fact(27))
INSERT INTO COEFFICIENTS VALUES('e',29,1/wct.fact(28))
INSERT INTO COEFFICIENTS VALUES('e',30,1/wct.fact(29))
INSERT INTO COEFFICIENTS VALUES('e',31,1/wct.fact(30))
INSERT INTO COEFFICIENTS VALUES('e',32,1/wct.fact(31))
INSERT INTO COEFFICIENTS VALUES('e',33,1/wct.fact(32))
INSERT INTO COEFFICIENTS VALUES('e',34,1/wct.fact(33))
INSERT INTO COEFFICIENTS VALUES('e',35,1/wct.fact(34))
INSERT INTO COEFFICIENTS VALUES('e',36,1/wct.fact(35))
INSERT INTO COEFFICIENTS VALUES('e',37,1/wct.fact(36))
INSERT INTO COEFFICIENTS VALUES('e',38,1/wct.fact(37))
INSERT INTO COEFFICIENTS VALUES('e',39,1/wct.fact(38))
INSERT INTO COEFFICIENTS VALUES('e',40,1/wct.fact(39))
INSERT INTO COEFFICIENTS VALUES('e',41,1/wct.fact(40))
INSERT INTO COEFFICIENTS VALUES('e',42,1/wct.fact(41))
INSERT INTO COEFFICIENTS VALUES('e',43,1/wct.fact(42))
INSERT INTO COEFFICIENTS VALUES('e',44,1/wct.fact(43))
INSERT INTO COEFFICIENTS VALUES('e',45,1/wct.fact(44))
INSERT INTO COEFFICIENTS VALUES('e',46,1/wct.fact(45))
INSERT INTO COEFFICIENTS VALUES('e',47,1/wct.fact(46))
INSERT INTO COEFFICIENTS VALUES('e',48,1/wct.fact(47))
INSERT INTO COEFFICIENTS VALUES('e',49,1/wct.fact(48))
INSERT INTO COEFFICIENTS VALUES('e',50,1/wct.fact(49))
INSERT INTO COEFFICIENTS VALUES('e',51,1/wct.fact(50))
INSERT INTO COEFFICIENTS VALUES('e',52,1/wct.fact(51))
INSERT INTO COEFFICIENTS VALUES('e',53,1/wct.fact(52))
INSERT INTO COEFFICIENTS VALUES('e',54,1/wct.fact(53))
INSERT INTO COEFFICIENTS VALUES('e',55,1/wct.fact(54))
INSERT INTO COEFFICIENTS VALUES('e',56,1/wct.fact(55))
INSERT INTO COEFFICIENTS VALUES('e',57,1/wct.fact(56))
INSERT INTO COEFFICIENTS VALUES('e',58,1/wct.fact(57))
INSERT INTO COEFFICIENTS VALUES('e',59,1/wct.fact(58))
INSERT INTO COEFFICIENTS VALUES('e',60,1/wct.fact(59))
INSERT INTO COEFFICIENTS VALUES('e',61,1/wct.fact(60))
INSERT INTO COEFFICIENTS VALUES('e',62,1/wct.fact(61))
INSERT INTO COEFFICIENTS VALUES('e',63,1/wct.fact(62))
INSERT INTO COEFFICIENTS VALUES('e',64,1/wct.fact(63))
INSERT INTO COEFFICIENTS VALUES('e',65,1/wct.fact(64))
INSERT INTO COEFFICIENTS VALUES('e',66,1/wct.fact(65))
INSERT INTO COEFFICIENTS VALUES('e',67,1/wct.fact(66))
INSERT INTO COEFFICIENTS VALUES('e',68,1/wct.fact(67))
INSERT INTO COEFFICIENTS VALUES('e',69,1/wct.fact(68))
INSERT INTO COEFFICIENTS VALUES('e',70,1/wct.fact(69))
INSERT INTO COEFFICIENTS VALUES('e',71,1/wct.fact(70))
INSERT INTO COEFFICIENTS VALUES('e',72,1/wct.fact(71))
INSERT INTO COEFFICIENTS VALUES('e',73,1/wct.fact(72))
INSERT INTO COEFFICIENTS VALUES('e',74,1/wct.fact(73))
INSERT INTO COEFFICIENTS VALUES('e',75,1/wct.fact(74))
INSERT INTO COEFFICIENTS VALUES('e',76,1/wct.fact(75))
INSERT INTO COEFFICIENTS VALUES('e',77,1/wct.fact(76))
INSERT INTO COEFFICIENTS VALUES('e',78,1/wct.fact(77))
INSERT INTO COEFFICIENTS VALUES('e',79,1/wct.fact(78))
INSERT INTO COEFFICIENTS VALUES('e',80,1/wct.fact(79))
INSERT INTO COEFFICIENTS VALUES('e',81,1/wct.fact(80))
INSERT INTO COEFFICIENTS VALUES('e',82,1/wct.fact(81))
INSERT INTO COEFFICIENTS VALUES('e',83,1/wct.fact(82))
INSERT INTO COEFFICIENTS VALUES('e',84,1/wct.fact(83))
INSERT INTO COEFFICIENTS VALUES('e',85,1/wct.fact(84))
INSERT INTO COEFFICIENTS VALUES('e',86,1/wct.fact(85))
INSERT INTO COEFFICIENTS VALUES('e',87,1/wct.fact(86))
INSERT INTO COEFFICIENTS VALUES('e',88,1/wct.fact(87))
INSERT INTO COEFFICIENTS VALUES('e',89,1/wct.fact(88))
INSERT INTO COEFFICIENTS VALUES('e',90,1/wct.fact(89))
INSERT INTO COEFFICIENTS VALUES('e',91,1/wct.fact(90))
INSERT INTO COEFFICIENTS VALUES('e',92,1/wct.fact(91))
INSERT INTO COEFFICIENTS VALUES('e',93,1/wct.fact(92))
INSERT INTO COEFFICIENTS VALUES('e',94,1/wct.fact(93))
INSERT INTO COEFFICIENTS VALUES('e',95,1/wct.fact(94))
INSERT INTO COEFFICIENTS VALUES('e',96,1/wct.fact(95))
INSERT INTO COEFFICIENTS VALUES('e',97,1/wct.fact(96))
INSERT INTO COEFFICIENTS VALUES('e',98,1/wct.fact(97))
INSERT INTO COEFFICIENTS VALUES('e',99,1/wct.fact(98))
INSERT INTO COEFFICIENTS VALUES('e',100,1/wct.fact(99))
INSERT INTO COEFFICIENTS VALUES('e',101,1/wct.fact(100))
INSERT INTO COEFFICIENTS VALUES('e',102,1/wct.fact(101))
INSERT INTO COEFFICIENTS VALUES('e',103,1/wct.fact(102))
INSERT INTO COEFFICIENTS VALUES('e',104,1/wct.fact(103))
INSERT INTO COEFFICIENTS VALUES('e',105,1/wct.fact(104))
INSERT INTO COEFFICIENTS VALUES('e',106,1/wct.fact(105))
INSERT INTO COEFFICIENTS VALUES('e',107,1/wct.fact(106))
INSERT INTO COEFFICIENTS VALUES('e',108,1/wct.fact(107))
INSERT INTO COEFFICIENTS VALUES('e',109,1/wct.fact(108))
INSERT INTO COEFFICIENTS VALUES('e',110,1/wct.fact(109))
INSERT INTO COEFFICIENTS VALUES('e',111,1/wct.fact(110))
INSERT INTO COEFFICIENTS VALUES('e',112,1/wct.fact(111))
INSERT INTO COEFFICIENTS VALUES('e',113,1/wct.fact(112))
INSERT INTO COEFFICIENTS VALUES('e',114,1/wct.fact(113))
INSERT INTO COEFFICIENTS VALUES('e',115,1/wct.fact(114))
INSERT INTO COEFFICIENTS VALUES('e',116,1/wct.fact(115))
INSERT INTO COEFFICIENTS VALUES('e',117,1/wct.fact(116))
INSERT INTO COEFFICIENTS VALUES('e',118,1/wct.fact(117))
INSERT INTO COEFFICIENTS VALUES('e',119,1/wct.fact(118))
INSERT INTO COEFFICIENTS VALUES('e',120,1/wct.fact(119))
INSERT INTO COEFFICIENTS VALUES('e',121,1/wct.fact(120))
INSERT INTO COEFFICIENTS VALUES('e',122,1/wct.fact(121))
INSERT INTO COEFFICIENTS VALUES('e',123,1/wct.fact(122))
INSERT INTO COEFFICIENTS VALUES('e',124,1/wct.fact(123))
INSERT INTO COEFFICIENTS VALUES('e',125,1/wct.fact(124))
INSERT INTO COEFFICIENTS VALUES('e',126,1/wct.fact(125))
INSERT INTO COEFFICIENTS VALUES('e',127,1/wct.fact(126))
INSERT INTO COEFFICIENTS VALUES('e',128,1/wct.fact(127))
INSERT INTO COEFFICIENTS VALUES('e',129,1/wct.fact(128))
INSERT INTO COEFFICIENTS VALUES('e',130,1/wct.fact(129))
INSERT INTO COEFFICIENTS VALUES('e',131,1/wct.fact(130))
INSERT INTO COEFFICIENTS VALUES('e',132,1/wct.fact(131))
INSERT INTO COEFFICIENTS VALUES('e',133,1/wct.fact(132))
INSERT INTO COEFFICIENTS VALUES('e',134,1/wct.fact(133))
INSERT INTO COEFFICIENTS VALUES('e',135,1/wct.fact(134))
INSERT INTO COEFFICIENTS VALUES('e',136,1/wct.fact(135))
INSERT INTO COEFFICIENTS VALUES('e',137,1/wct.fact(136))
INSERT INTO COEFFICIENTS VALUES('e',138,1/wct.fact(137))
INSERT INTO COEFFICIENTS VALUES('e',139,1/wct.fact(138))
INSERT INTO COEFFICIENTS VALUES('e',140,1/wct.fact(139))
INSERT INTO COEFFICIENTS VALUES('e',141,1/wct.fact(140))
INSERT INTO COEFFICIENTS VALUES('e',142,1/wct.fact(141))
INSERT INTO COEFFICIENTS VALUES('e',143,1/wct.fact(142))
INSERT INTO COEFFICIENTS VALUES('e',144,1/wct.fact(143))
INSERT INTO COEFFICIENTS VALUES('e',145,1/wct.fact(144))
INSERT INTO COEFFICIENTS VALUES('e',146,1/wct.fact(145))
INSERT INTO COEFFICIENTS VALUES('e',147,1/wct.fact(146))
INSERT INTO COEFFICIENTS VALUES('e',148,1/wct.fact(147))
INSERT INTO COEFFICIENTS VALUES('e',149,1/wct.fact(148))
INSERT INTO COEFFICIENTS VALUES('e',150,1/wct.fact(149))
INSERT INTO COEFFICIENTS VALUES('e',151,1/wct.fact(150))
INSERT INTO COEFFICIENTS VALUES('e',152,1/wct.fact(151))
INSERT INTO COEFFICIENTS VALUES('e',153,1/wct.fact(152))
INSERT INTO COEFFICIENTS VALUES('e',154,1/wct.fact(153))
INSERT INTO COEFFICIENTS VALUES('e',155,1/wct.fact(154))
INSERT INTO COEFFICIENTS VALUES('e',156,1/wct.fact(155))
INSERT INTO COEFFICIENTS VALUES('e',157,1/wct.fact(156))
INSERT INTO COEFFICIENTS VALUES('e',158,1/wct.fact(157))
INSERT INTO COEFFICIENTS VALUES('e',159,1/wct.fact(158))
INSERT INTO COEFFICIENTS VALUES('e',160,1/wct.fact(159))
INSERT INTO COEFFICIENTS VALUES('e',161,1/wct.fact(160))
INSERT INTO COEFFICIENTS VALUES('e',162,1/wct.fact(161))
INSERT INTO COEFFICIENTS VALUES('e',163,1/wct.fact(162))
INSERT INTO COEFFICIENTS VALUES('e',164,1/wct.fact(163))
INSERT INTO COEFFICIENTS VALUES('e',165,1/wct.fact(164))
INSERT INTO COEFFICIENTS VALUES('e',166,1/wct.fact(165))
INSERT INTO COEFFICIENTS VALUES('e',167,1/wct.fact(166))
INSERT INTO COEFFICIENTS VALUES('e',168,1/wct.fact(167))
INSERT INTO COEFFICIENTS VALUES('e',169,1/wct.fact(168))
INSERT INTO COEFFICIENTS VALUES('e',170,1/wct.fact(169))
INSERT INTO COEFFICIENTS VALUES('e',171,1/wct.fact(170))
 
Run the following SELECT
 
select
wct.SERIESSUM(1,0,1,'coefficients','factor','factor_name','e')
from e_fact
where f_name = 'e'
group by f_name
Here is the result set
----------------------
2.71828182845905
 
(1 row(s) affected)
 
You could calculate EXP(2) with the following SELECT
select
wct.SERIESSUM(2,0,1,'coefficients','factor','factor_name','e')
from e_fact
where f_name = 'e'
group by f_name
 
Here is the result set
----------------------
7.38905609893065
 
(1 row(s) affected)


Copyright 2008-2024 Westclintech LLC         Privacy Policy        Terms of Service