Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7839593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:29:04+00:00 2026-06-02T15:29:04+00:00

I’ve got a program that is supposed to find the roots for the **th

  • 0

I’ve got a program that is supposed to find the roots for the **th hermite polynomial by using Newton’s method, but it’s taking a long time to run the program. I’m pretty new to C, so I can’t figure out where my bug is or if this is just the nature of brute forcing this problem. I’m also having issues getting accurate roots, but so far, it’s hard to find that bug because I can only run a test case every 5-10 minutes

CODE REMOVED

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T15:29:07+00:00Added an answer on June 2, 2026 at 3:29 pm

    I’m 100% sure there’s no good reason for Newton-Raphson to take so much time. In some cases it may be problematic, because this method isn’t guaranteed to converge. But in your specific case – there should be no problem.

    One thing that is clear is that you monstrously overuse recursion. Just calculating your hermite with n=37 is a recursion with complexity somewhat as summing 37 Fibonacci numbers, which is about 40 millions.

    Now, think that your newton method should invoke the hermite repeatedly, as well as h_deriv (which is of the same order of magnitude of recursion), up until in converges up to 10^-12. Sounds like tens of interations.

    And, not enough all this, you also manage to implement newton recursively! There is really no reason in the world to so this. (was lisp/scheme your first programming language?)

    This is what you should do to improve the performance:

    1. Fix your hermite. You should calculate the 37 coefficients, this may be done recursively. Once this is done – you should use them to calculate the the value of the polynomial in a normal time.

    2. Same regarding the derivative. Just calculate the 36 coefficients.

    3. Optionally fix your newton. As far as I can see – you’ll not gain much of the performance: your “recursion” is an awkward loop nevertheless. However it’ll look better, and consume much less stack.

    Edit:

    After reading the comments I took time and tried to build & run this. And, I must admit, I underestimated the problem complexity.

    As turns out, the coefficients calculated by the recursive relation grow rapidly, and the round-off error seems to dominate. So that solving this problem by brute-force has unavoidable implications, and it’s not obvious that using the pre-calculated coefficients (and summing them in the straight order) yields the same result.

    Nevertheless there’s a way to get rid of the ridiculous recursion without changing the calculation logic:

    const int N = 37;
    
    double g_pHermiteValues[N+1];
    
    void CalcHermiteAt(double x)
    {
        double x2 = x*2;
    
        g_pHermiteValues[0] = 1.;
        g_pHermiteValues[1] = x2;
    
        for (int n = 2; n <= N; n++)
            g_pHermiteValues[n] =
                g_pHermiteValues[n - 1] * x2 - 
                g_pHermiteValues[n - 2] * 2*(n - 1);
    }
    
    double CalcHermiteDerivAt()
    {
        return g_pHermiteValues[N - 1] * 2*N;
    }
    
    double newton(double x_0)
    {
        const double tolerance = 1E-12;
    
        while (true)
        {
            CalcHermiteAt(x_0);
    
            if (abs(g_pHermiteValues[N]) < tolerance)
                return x_0;
    
            x_0 -= g_pHermiteValues[N] / CalcHermiteDerivAt();
        }
    }
    

    That is, we use the same recursive relation. It’s just in order to calculate the value of the Hermite polynomial at a given point we calculate it for all the polynomials up to n=37 iteratively, and store the results in the global array. Then its top element holds the needed result, and the derivative is also deduced from the 2nd array element from the end.

    Since in Newton-Raphson algorithm at each step we need both the value and the derivative at the same point – this is done effectively.

    P.S. However so far I could not come to the solution. The Newton-Raphson just doesn’t converge for the points I’ve tried to start from.

    I believe for such a question a more robust method may be used, such as a median search.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.