Calculation of Area Under a Continuos curve......

A

Abhishek Jha

Hi, I am working on calculating area under a Continuous Curve.. I
have data points...On X axis i have % of Cumulative numbers(Variable
X) and on Y axis i have % of Cumulative numbers(Variable Y). If i
plot a curve by joinig thses points i get a smooth curve. If i have to
calculate the exact area under the curve using Integration Function in
Excel Sheet how should i proceed.

Data points are :
Issuers Defaulters Cum Issuers % Cum Defaulters %
C 3 0 0.287907869 0
B 4 2 0.671785029 7.407407407
BB 35 5 4.030710173 25.92592593
BBB 242 15 27.25527831 81.48148148
A 293 4 55.37428023 96.2962963
AA 315 1 85.60460653 100
AAA 150 0 100 100
1042 27


Want to calculate the total area under the curve formed by joining the
data points : Cum Issuers % and Cum Defaulters %


Regards,
Abhishek
 
H

Hans Terkelsen

Abhishek Jha said:
Hi, I am working on calculating area under a Continuous Curve.. I
have data points...On X axis i have % of Cumulative numbers(Variable
X) and on Y axis i have % of Cumulative numbers(Variable Y). If i
plot a curve by joinig thses points i get a smooth curve. If i have to
calculate the exact area under the curve using Integration Function in
Excel Sheet how should i proceed.

Data points are :
Issuers Defaulters Cum Issuers % Cum Defaulters %
C 3 0 0.287907869 0
B 4 2 0.671785029 7.407407407
BB 35 5 4.030710173 25.92592593
BBB 242 15 27.25527831 81.48148148
A 293 4 55.37428023 96.2962963
AA 315 1 85.60460653 100
AAA 150 0 100 100
1042 27


Want to calculate the total area under the curve formed by joining the
data points : Cum Issuers % and Cum Defaulters %


Regards,
Abhishek

Hi Abhishek.

Integration under a smooth curve or under a broken line,
both are possible in Excel, with a single formula.
In case of the smooth curve, the curve formula and the limits must be known.

Before trying something like that,
is it possible that you are looking for the weighted average of Cum Defaulters % ?

That could be =SUMPRODUCT(D2:D8*E2:E8)/SUM(D2:D8)
if Cum Issuers % are in D2:D8, and Cum Defaulters % are in E2:E8

Hans T.
 
H

Hans Terkelsen

Abhishek Jha said:
Hi, I am working on calculating area under a Continuous Curve..
....

Hi all.

Abhishek seems to have lost interest, but for reference
the following is an easy way to calculate integrals in Excel,
without VBA nescessarily.

Define the names n, x and dx, most easily by running the macro below.

Suppose then we want to calculate (S being the integral sign):

1
S 4/(1+x^2)*dx
0

The result should be close to PI().

In 3 cells next to each other write
0 1 =SUMPRODUCT(4/(1+x^2)*dx)

Like SUMPRODUCT is standing in for the integral sign in the matematical formula.

The result is pi with 15 digits, by good fortune.
Only the 16. hidden digit is wrong.
One can unhide it by subtracting 3.

Hans T.

"""""""""""""""""""""""
Sub DefineNamesForNumericIntegration()

'By default the names n, x, dx.

'For "Definite Integral" calculation in an Excel workbook:
'To calculate (S being the integralsign)
'
'b
'S f(x)dx
'a
'
'The integral from x=a to x=b of f(x) is calculated (using the names defined by the macro) by
'3 cells next to each other
'a | b | Matrix formula {=SUM(f(x)*dx)} or the formula =SUMPRODUCT(f(x)*dx)
'
'Problem example:
'
'pi/2
'S sin(x)*dx (should give 1)
'0
'
'3 cells next to each other
' ______________________________________
'| 0 | =PI()/2 | =SUMPRODUCT(sin(x)*dx) |
' ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
'gives 1.00000000000003

'The names n, x, dx are vectors, calculated from the limits a and b
'a to b is split into intervals, indexed by n
'The intervals are weighted by "Simpsons rule", which approximates with parabola pieces
'Step functions like INT may therefore be uncorrectly rounded near the step points
'A larger number of intervals can improve accuracy. For polynomiums of max 3. degree there is full accuracy.
'For 'nice', smooth, not too steep functions and b-a not too big, the error is at the last digit
'
'NB. Some functions, SUM, MAX, MIN, ...CONCATENATE, BESSEL ,.. can not deliver an array
'Beware of them in the integrand expression
'
'Without this macro the defined names and references might be
'n =ROW(!$1:$1001)-(RAND()<1)
'x =!A1+n*(!B1-!A1)/MAX(n)
'dx =((n>0)+(n<MAX(n))+2*MOD(n,2))*(!B1-!A1)/MAX(n)/3
'IF active cell is C1 while the names are defined
'

Dim intervals&, integrationvariable$
''''''''''
intervals = 1000 'an EVEN number
integrationvariable = "x" 'r and c can't be used
'integrationvariable = "y" 'r and c can't be used
'name for differential of "x" will automatically be "dx"
''''''''''
With ActiveWorkbook

'Uncomment next for own choice of variable name
'integrationvariable = InputBox("Define new integrationvariable?" & vbCr & "Not r or c.", .Name, "x")
If integrationvariable = "" Then Exit Sub

..Names.Add "n", "=ROW(INDIRECT(""1:" & intervals + 1 & """))-1"
'.Names.Add "nn", "=TRANSPOSE(ROW(INDIRECT(""1:" & intervals + 1 & """)))-1"

' Uncomment next if number of intervals is in active sheet R1C1
'.Names.Add "n", "=ROW(INDIRECT(""1:"" & !R1C1+1))-1"
'.Names.Add "nn", "=TRANSPOSE(ROW(INDIRECT(""1:"" & !R1C1+1)))-1"

..Names.Add integrationvariable, "=!RC[-2]+n*(!RC[-1]-!RC[-2])/MAX(n)"
'.Names.Add integrationvariable, "=!RC[-4]+nn*(!RC[-3]-!RC[-4])/MAX(nn)"
..Names.Add "d" + integrationvariable, "=((n>0)+(n<MAX(n))+2*MOD(n,2))*(!RC[-1]-!RC[-2])/MAX(n)/3"
'.Names.Add "d" + integrationvariable, "=((nn>0)+(nn<MAX(nn))+2*MOD(nn,2))*(!RC[-3]-!RC[-4])/MAX(nn)/3"

'On Error Resume Next
'.Names("t").Delete
'.Names("dt").Delete
End With
End Sub

"""""""""""""""""""""""
 
A

Abhishek Jha

Abhishek Jha said:
Hi,  I am working on calculating area under a Continuous Curve..  

...

Hi all.

Abhishek seems to have lost interest, but for reference
the following is an easy way to calculate integrals in Excel,
without VBA nescessarily.

Define the names n, x and dx, most easily by running the macro below.

Suppose then we want to calculate (S being the integral sign):

1
S 4/(1+x^2)*dx
0

The result should be close to PI().

In 3 cells next to each other write
0    1    =SUMPRODUCT(4/(1+x^2)*dx)

Like SUMPRODUCT is standing in for the integral sign in the matematical formula.

The result is pi with 15 digits, by good fortune.
Only the 16. hidden digit is wrong.
One can unhide it by subtracting 3.

Hans T.

"""""""""""""""""""""""
Sub DefineNamesForNumericIntegration()

'By default the names n, x, dx.

'For "Definite Integral" calculation in an Excel workbook:
'To calculate (S being the integralsign)
'
'b
'S f(x)dx
'a
'
'The integral from x=a to x=b of f(x) is calculated (using the names defined by the macro) by
'3 cells next to each other
'a | b | Matrix formula {=SUM(f(x)*dx)} or the formula =SUMPRODUCT(f(x)*dx)
'
'Problem example:
'
'pi/2
'S sin(x)*dx  (should give 1)
'0
'
'3 cells next to each other
' ______________________________________
'| 0 | =PI()/2 | =SUMPRODUCT(sin(x)*dx)         |
' ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
'gives 1.00000000000003

'The names n, x, dx are vectors, calculated from the limits a and b
'a to b is split into intervals, indexed by n
'The intervals are weighted by "Simpsons rule", which approximates with parabola pieces
'Step functions like INT may therefore be uncorrectly rounded near the step points
'A larger number of intervals can improve accuracy. For polynomiums of max 3. degree there is full accuracy.
'For 'nice', smooth, not too steep functions and b-a not too big, the error is at the last digit
'
'NB. Some functions, SUM, MAX, MIN, ...CONCATENATE, BESSEL ,.. can not deliver an array
'Beware of them in the integrand expression
'
'Without this macro the defined names and references might be
'n     =ROW(!$1:$1001)-(RAND()<1)
'x     =!A1+n*(!B1-!A1)/MAX(n)
'dx    =((n>0)+(n<MAX(n))+2*MOD(n,2))*(!B1-!A1)/MAX(n)/3
'IF active cell is C1 while the names are defined
'

Dim intervals&, integrationvariable$
''''''''''
intervals = 1000 'an EVEN number
integrationvariable = "x" 'r and c can't be used
'integrationvariable = "y" 'r and c can't be used
'name for differential of "x" will automatically be "dx"
''''''''''
With ActiveWorkbook

'Uncomment next for own choice of variable name
'integrationvariable = InputBox("Define new integrationvariable?" & vbCr & "Not r or c.", .Name, "x")
If integrationvariable = "" Then Exit Sub

.Names.Add "n", "=ROW(INDIRECT(""1:" & intervals + 1 & """))-1"
'.Names.Add "nn", "=TRANSPOSE(ROW(INDIRECT(""1:" & intervals + 1 & """)))-1"

' Uncomment next if number of intervals is in active sheet R1C1
'.Names.Add "n", "=ROW(INDIRECT(""1:"" & !R1C1+1))-1"
'.Names.Add "nn", "=TRANSPOSE(ROW(INDIRECT(""1:"" & !R1C1+1)))-1"

.Names.Add integrationvariable, "=!RC[-2]+n*(!RC[-1]-!RC[-2])/MAX(n)"
'.Names.Add integrationvariable, "=!RC[-4]+nn*(!RC[-3]-!RC[-4])/MAX(nn)"
.Names.Add "d" + integrationvariable, "=((n>0)+(n<MAX(n))+2*MOD(n,2))*(!RC[-1]-!RC[-2])/MAX(n)/3"
'.Names.Add "d" + integrationvariable, "=((nn>0)+(nn<MAX(nn))+2*MOD(nn,2))*(!RC[-3]-!RC[-4])/MAX(nn)/3"

'On Error Resume Next
'.Names("t").Delete
'.Names("dt").Delete
End With
End Sub

"""""""""""""""""""""""

Hi, thanks so much for this great piece of information.....i have just
checked the reply...Will revert with any queries sonn....Thanks a
Lot...Abhishek
 
H

Hans Terkelsen

Salmon Egg said:
I saw the topic on the fly. From time to time, I have had to find
definite integrals, but no lately. This is just a note without detail.

If you have values of the integrand on uniformly spaced points,
Simpson's rule is easy to use and usually more accurate than mere
summing. It is simplest if there are an even number of intervals, and
therefore, an odd number of points. Over every pair of intervals, a
parabola is used to represent the function,

Instead of merely adding these values the are weighted. IIRC, the end
points are weighted by factors of 1/ then the inbetween points are
weight by factors of 4 and 2 alternately. After the weighted sum is
obtained, it is multiplied by interval between points (dx or h in
various notations) and divided by 3. That is the definite integral. Easy
to do on an Excel spreadsheet.

I hope this helps, If not clear, see the article Simpson's rule in
Wikipedia. If still not clear, just ignore this post.

Bill

Hi Bill.

Agreed.
It is exactly the method used.

Since most of the calculation takes place in the names,
only a single cell is used to find the integral,
or the area under the curve.

Though it is possible to define the names manually,
it is much more easy to prepare the sheet for integrals by running that macro,
because the names are a little complicated by the Simpson rule calculation in them.

Hans T.
 
H

Hans Terkelsen

....

Hi, thanks so much for this great piece of information.....i have just
checked the reply...Will revert with any queries sonn....Thanks a
Lot...Abhishek

Good, Abhishek.
Please disregard my first reply to your post.
I could not see the rationale behind, and I made a mistake, I'm afraid.
Hans T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top