What is happening to num and den in this C++ code for Stieltjes polynomials?

In summary, the conversation discusses the implementation of Stieltjes polynomials in C++ and how the variables "num" and "den" are used in the code. It is suggested to refer to the paper by Patterson for a better understanding. The code follows the notation in the paper and uses the variables for the recursive definition of the polynomials. The function "stielt" is used to solve for the coefficients of the polynomials and it is mentioned that translating the code to another language should be simple. The conversation also mentions an alternative method of using equations (6) and (4) to obtain the coefficients through a system of simultaneous equations. However, it is considered tedious and the use of equation (12) is preferred, but
  • #1
Vick
105
11
TL;DR Summary
need help with C++ code
I'm not at all C++ literate, but I need to understand what a C++ code is doing for a math problem regarding the Stieltjes polynomials.
Especially, I want to know what is happening to the "num" and "den" in the code; the code is in this link:

Stieltjes
 
Technology news on Phys.org
  • #2
Do you have the reference that it mentions in a comment at the top? In another comment, it says that it is trying to follow the exact notation in the reference. That might help you.
 
  • #3
FactChecker said:
Do you have the reference that it mentions in a comment at the top? In another comment, it says that it is trying to follow the exact notation in the reference. That might help you.
It refers to this paper: Patterson but I don't quite understand how the num and den are being used in order to yield

$$
E_{m}(x) = \frac{num}{den} * ??
$$
 
  • #4
Have you read the comments in the code? It is an implementation of eq. (12) in the article, and a pretty straightforward one at that.
 
  • #5
DrClaude said:
Have you read the comments in the code? It is an implementation of eq. (12) in the article, and a pretty straightforward one at that.
I don't understand the C++ code and once the num and den are obtained, I just don't understand what is happening to them ...can you help me please?

The num/den are coefficients, but what do we do with them and to which degree of the Legendre polynomial, do we multiply them with in order to obtain an evaluation of the Stieltjes polynomials?
 
  • #6
The variables num and den stand for numerator and denominator, as they are the numerator and denominator of the RHS of eq. (12) that multiply ##S_{i-1,k}/S{r-k,k}##. Note that the definition of ##S_{i,k}/S{r-k,k}## is recursive, so the variable ratio keeps the current value of ##S_{i-1,k}/S{r-k,k}## to be kept for the next iteration.

The variable m_a appears to be the ##a## in eq. (11). The use of -= implements the subtraction of terms in eq. (11).
 
  • Like
Likes sysprog
  • #7
DrClaude said:
The variables num and den stand for numerator and denominator, as they are the numerator and denominator of the RHS of eq. (12) that multiply ##S_{i-1,k}/S{r-k,k}##. Note that the definition of ##S_{i,k}/S{r-k,k}## is recursive, so the variable ratio keeps the current value of ##S_{i-1,k}/S{r-k,k}## to be kept for the next iteration.

The variable m_a appears to be the ##a## in eq. (11). The use of -= implements the subtraction of terms in eq. (11).
I'm trying to code them in VBA. For example for ##m=5## I obtain the following num/den: ##140/176##, ##180/440## and ##720/936##.

How do I multiply these coefficients with ##\frac{S_{i-1,k}}{S_{r-k,k}}##?
Does that mean, I must multiply by eq.(7) and integrate as well or just the ##P_{2i-1-q}(x)##?

VBA code for Stieltjes:
Function stielt(x, m)
n = m - 1
If n Mod 2 <> 0 Then
q = 1
r = (n - 1) / 2 + 2
Else
q = 0
r = n / 2 + 1
End If

t = 0
For k = 1 To r - 1
For i = r + 1 - k To r
ii = i - 1
iii = r - k
num = (n - q + 2 * (i + k - 1)) * (n + q + 2 * (k - i + 1)) * (n - 1 - q + 2 * (i - k)) * (2 * (k + i - 1) - 1 - q - n)
den = (n - q + 2 * (i - k)) * (2 * (k + i - 1) - q - n) * (n + 1 + q + 2 * (k - i)) * (n - 1 - q + 2 * (i + k))
t = t - (num / den * legpoly(x, 2 * ii - 1 - q) / legpoly(x, 2 * iii - 1 - q))
MsgBox " " & num & vbCrLf & " " & den & vbCrLf & "k=" & k & vbCrLf & "i=" & i & vbCrLf & " " & t
Next
Next
stielt = t
End Function
 
  • #8
Translating to another language should be trivial. Simply convert the instructions to VBA.
 
  • #9
DrClaude said:
Translating to another language should be trivial. Simply convert the instructions to VBA.
I already used eq. (6) to obtain a system of simultaneous equations and solved them by Gauss-Jordan Elimination to obtain the coefficients, and once I've done that, I just have to multiply the latter with Legendre polynomials as per eq. (4) and I got my evaluation for Stieltes polynomials in terms of ##E_{m}(x)=##

However using just eqs. (6) and (4) and obtaining system of equations and solving them to obtain coefficients is tedious.

Whereas the eq.(12) num/den is already providing the coefficients without simultaneous equations. But I don't understand what I am to do with the obtained coefficients in this case to evaluate it for the Stieltjes polynomials!
 
  • #10
Vick said:
Whereas the eq.(12) num/den is already providing the coefficients without simultaneous equations. But I don't understand what I am to do with the obtained coefficients in this case to evaluate it for the Stieltjes polynomials!
That is taken care of here:
C++:
    Real operator()(Real x) const
    {
        // Trivial implementation:
        // Em += m_a[i]*legendre_p(2*i - 1, x);  m odd
        // Em += m_a[i]*legendre_p(2*i - 2, x);  m even
It appears to be the same thing you said you were doing, namely taking the coefficients and multiplying by the relevant Legendre polynomial.
 
  • #11
DrClaude said:
That is taken care of here:
C++:
    Real operator()(Real x) const
    {
        // Trivial implementation:
        // Em += m_a[i]*legendre_p(2*i - 1, x);  m odd
        // Em += m_a[i]*legendre_p(2*i - 2, x);  m even
It appears to be the same thing you said you were doing, namely taking the coefficients and multiplying by the relevant Legendre polynomial.
I don't get the required result. The coefficients for m=5 are as above and multiplying by the legendre polynomials as per the formula you posted above does not cut it...
 

1. What are num and den in this C++ code for Stieltjes polynomials?

In this code, num and den refer to the numerator and denominator polynomials, respectively, that are used to calculate the Stieltjes polynomials. These polynomials are named after the mathematician Thomas Joannes Stieltjes and are commonly used in the study of orthogonal polynomials.

2. How are num and den used in this code for Stieltjes polynomials?

In this code, num and den are used to calculate the coefficients of the Stieltjes polynomials. The coefficients are determined through a recursive formula that involves the previous coefficients and the values of the numerator and denominator polynomials at a particular point.

3. What is the significance of Stieltjes polynomials in mathematics?

Stieltjes polynomials have various applications in mathematics, particularly in the study of orthogonal polynomials and approximation theory. They also have connections to other areas of mathematics such as complex analysis and number theory.

4. How is the recursive formula for Stieltjes polynomials implemented in this code?

In this code, the recursive formula for Stieltjes polynomials is implemented using a for loop. The loop calculates the coefficients of the polynomials for each degree, starting from the first degree and ending at the desired degree specified by the user.

5. Can this code for Stieltjes polynomials be adapted for other types of polynomials?

Yes, this code can be adapted for other types of polynomials by changing the values of the numerator and denominator polynomials and adjusting the recursive formula accordingly. However, the code may need to be modified depending on the specific type of polynomial being used.

Similar threads

  • General Math
Replies
12
Views
1K
  • Programming and Computer Science
Replies
14
Views
2K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
1
Views
698
  • Programming and Computer Science
Replies
1
Views
945
  • Programming and Computer Science
Replies
3
Views
320
  • Programming and Computer Science
Replies
15
Views
5K
Replies
13
Views
4K
  • Programming and Computer Science
Replies
1
Views
771
  • Programming and Computer Science
4
Replies
107
Views
5K
Back
Top