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

  • Context: C/C++ 
  • Thread starter Thread starter member 657093
  • Start date Start date
  • Tags Tags
    C++ Code Polynomials
Click For Summary

Discussion Overview

The discussion revolves around understanding a C++ code implementation related to Stieltjes polynomials, specifically focusing on the roles of the variables "num" and "den" in the code. Participants seek clarification on how these variables are used in the context of the mathematical formulation presented in a referenced paper.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • Some participants express a lack of familiarity with C++ and seek to understand the functionality of "num" and "den" in the code related to Stieltjes polynomials.
  • Others mention that the code is an implementation of a specific equation from a referenced paper, suggesting that reading the comments in the code may provide clarity.
  • A participant questions how to utilize the coefficients obtained from "num" and "den" in conjunction with Legendre polynomials to evaluate Stieltjes polynomials.
  • Some participants clarify that "num" and "den" represent the numerator and denominator of a mathematical expression, indicating a recursive relationship in their definitions.
  • There are discussions about translating the code into VBA and the challenges faced in obtaining the correct results when applying the coefficients to Legendre polynomials.
  • A participant notes that the coefficients derived from the code provide a more straightforward approach compared to solving simultaneous equations, yet expresses confusion about their application.

Areas of Agreement / Disagreement

Participants generally agree that "num" and "den" are crucial for evaluating Stieltjes polynomials, but there is no consensus on the exact method to apply these coefficients or on the results obtained from their application. Multiple competing views on the implementation and interpretation of the code remain unresolved.

Contextual Notes

Participants mention various equations and their relationships, but there are limitations in understanding how to integrate the coefficients with Legendre polynomials, leading to unresolved mathematical steps and dependencies on specific definitions from the referenced paper.

member 657093
TL;DR
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
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.
 
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} * ??
$$
 
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.
 
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?
 
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   Reactions: sysprog
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)##?

[CODE title="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[/CODE]
 
Translating to another language should be trivial. Simply convert the instructions to VBA.
 
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...
 

Similar threads

  • · Replies 22 ·
Replies
22
Views
4K
Replies
1
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
Replies
1
Views
2K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 15 ·
Replies
15
Views
8K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
Replies
1
Views
7K
  • · Replies 2 ·
Replies
2
Views
3K