Login     Register

        Contact Us     Search

XLeratorDB/math Documentation

SQL Server SERIESSUM function


SERIESSUM_q                     
 
Updated: 17 August 2010 
Use SERIESSUM_q to calculate the sum of a power series.
Syntax
SELECT [westclintech].[wct].[SERIESSUM_q] (
   <@x, float,>
 ,<@n, float,>
 ,<@m, float,>
 ,<@a_RangeQuery, nvarchar(4000),>)
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_RangeQuery
the SELECT statement to use in extracting data for the calculation. @a_RangeQuery 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 cosine which is the same as the COS function
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 ('cos',1,1)
insert into coefficients values ('cos',2,-1/wct.fact(2))
insert into coefficients values ('cos',3,1/wct.fact(4))
insert into coefficients values ('cos',4,-1/wct.fact(6))
insert into coefficients values ('cos',5,1/wct.fact(8))
insert into coefficients values ('cos',6,-1/wct.fact(10))
insert into coefficients values ('cos',7,1/wct.fact(12))
insert into coefficients values ('cos',8,-1/wct.fact(14))
insert into coefficients values ('cos',9,1/wct.fact(16))
insert into coefficients values ('cos',10,-1/wct.fact(18))
insert into coefficients values ('cos',11,1/wct.fact(20))
insert into coefficients values ('cos',12,-1/wct.fact(22))
insert into coefficients values ('cos',13,1/wct.fact(24))
insert into coefficients values ('cos',14,-1/wct.fact(26))
insert into coefficients values ('cos',15,1/wct.fact(28))
insert into coefficients values ('cos',16,-1/wct.fact(30))
insert into coefficients values ('cos',17,1/wct.fact(32))
insert into coefficients values ('cos',18,-1/wct.fact(34))
insert into coefficients values ('cos',19,1/wct.fact(36))
insert into coefficients values ('cos',20,-1/wct.fact(38))
insert into coefficients values ('cos',21,1/wct.fact(40))
insert into coefficients values ('cos',22,-1/wct.fact(42))
insert into coefficients values ('cos',23,1/wct.fact(44))
insert into coefficients values ('cos',24,-1/wct.fact(46))
insert into coefficients values ('cos',25,1/wct.fact(48))
insert into coefficients values ('cos',26,-1/wct.fact(50))
insert into coefficients values ('cos',27,1/wct.fact(52))
insert into coefficients values ('cos',28,-1/wct.fact(54))
insert into coefficients values ('cos',29,1/wct.fact(56))
insert into coefficients values ('cos',30,-1/wct.fact(58))
insert into coefficients values ('cos',31,1/wct.fact(60))
insert into coefficients values ('cos',32,-1/wct.fact(62))
insert into coefficients values ('cos',33,1/wct.fact(64))
insert into coefficients values ('cos',34,-1/wct.fact(66))
insert into coefficients values ('cos',35,1/wct.fact(68))
insert into coefficients values ('cos',36,-1/wct.fact(70))
insert into coefficients values ('cos',37,1/wct.fact(72))
insert into coefficients values ('cos',38,-1/wct.fact(74))
insert into coefficients values ('cos',39,1/wct.fact(76))
insert into coefficients values ('cos',40,-1/wct.fact(78))
insert into coefficients values ('cos',41,1/wct.fact(80))
insert into coefficients values ('cos',42,-1/wct.fact(82))
insert into coefficients values ('cos',43,1/wct.fact(84))
insert into coefficients values ('cos',44,-1/wct.fact(86))
insert into coefficients values ('cos',45,1/wct.fact(88))
insert into coefficients values ('cos',46,-1/wct.fact(90))
insert into coefficients values ('cos',47,1/wct.fact(92))
insert into coefficients values ('cos',48,-1/wct.fact(94))
insert into coefficients values ('cos',49,1/wct.fact(96))
insert into coefficients values ('cos',50,-1/wct.fact(98))
insert into coefficients values ('cos',51,1/wct.fact(100))
insert into coefficients values ('cos',52,-1/wct.fact(102))
insert into coefficients values ('cos',53,1/wct.fact(104))
insert into coefficients values ('cos',54,-1/wct.fact(106))
insert into coefficients values ('cos',55,1/wct.fact(108))
insert into coefficients values ('cos',56,-1/wct.fact(110))
insert into coefficients values ('cos',57,1/wct.fact(112))
insert into coefficients values ('cos',58,-1/wct.fact(114))
insert into coefficients values ('cos',59,1/wct.fact(116))
insert into coefficients values ('cos',60,-1/wct.fact(118))
insert into coefficients values ('cos',61,1/wct.fact(120))
insert into coefficients values ('cos',62,-1/wct.fact(122))
insert into coefficients values ('cos',63,1/wct.fact(124))
insert into coefficients values ('cos',64,-1/wct.fact(126))
insert into coefficients values ('cos',65,1/wct.fact(128))
insert into coefficients values ('cos',66,-1/wct.fact(130))
insert into coefficients values ('cos',67,1/wct.fact(132))
insert into coefficients values ('cos',68,-1/wct.fact(134))
insert into coefficients values ('cos',69,1/wct.fact(136))
insert into coefficients values ('cos',70,-1/wct.fact(138))
insert into coefficients values ('cos',71,1/wct.fact(140))
insert into coefficients values ('cos',72,-1/wct.fact(142))
insert into coefficients values ('cos',73,1/wct.fact(144))
insert into coefficients values ('cos',74,-1/wct.fact(146))
insert into coefficients values ('cos',75,1/wct.fact(148))
insert into coefficients values ('cos',76,-1/wct.fact(150))
insert into coefficients values ('cos',77,1/wct.fact(152))
insert into coefficients values ('cos',78,-1/wct.fact(154))
insert into coefficients values ('cos',79,1/wct.fact(156))
insert into coefficients values ('cos',80,-1/wct.fact(158))
insert into coefficients values ('cos',81,1/wct.fact(160))
insert into coefficients values ('cos',82,-1/wct.fact(162))
insert into coefficients values ('cos',83,1/wct.fact(164))
insert into coefficients values ('cos',84,-1/wct.fact(166))
insert into coefficients values ('cos',85,1/wct.fact(168))
insert into coefficients values ('cos',86,-1/wct.fact(170))
 
You could calculate the cosine of PI by running the following SELECT
 
select wct.seriessum_q(pi()
,0
,2
,'select factor from coefficients where factor_name = ' + char(39) + 'cos' + char(39))
Here is the result set
----------------------
-1
 
(1 row(s) affected)

 



Copyright 2008-2024 Westclintech LLC         Privacy Policy        Terms of Service