member 657093
What is happening to num and den in this C++ code for Stieltjes polynomials?
- Topic: C/C++
- Thread starter member 657093
- Start date
-
- Tags
- C++ Code Polynomials
Join the discussion
Registration is free. Start your own thread to ask a follow-up.
10 replies · 2K views
Physics news on Phys.org
Discussion
Science Advisor
Homework Helper
- 9,605
- 4,831
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.
member 657093
It refers to this paper: Patterson but I don't quite understand how the num and den are being used in order to yieldFactChecker 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.
$$
E_{m}(x) = \frac{num}{den} * ??
$$
member 657093
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?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.
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?
Mentor
- 8,478
- 5,700
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).
The variable m_a appears to be the ##a## in eq. (11). The use of -= implements the subtraction of terms in eq. (11).
member 657093
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##.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).
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]
member 657093
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)=##DrClaude said:Translating to another language should be trivial. Simply convert the instructions to VBA.
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!
Mentor
- 8,478
- 5,700
That is taken care of here: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!
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
member 657093
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...DrClaude said:That is taken care of here:
It appears to be the same thing you said you were doing, namely taking the coefficients and multiplying by the relevant Legendre polynomial.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
Similar threads
- member 657093
- · Replies 12 ·
- General Math
- Replies
- 12