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 6760203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:02:20+00:00 2026-05-26T14:02:20+00:00

If we are given with an array of non-linear equation coefficients and some range,

  • 0

If we are given with an array of non-linear equation coefficients and some range, how can we find that equation’s root within the range given?

E.g.: the equation is

enter image description here

So coefficient array will be the array of a‘s. Let’s say the equation is

enter image description here

Then the coefficient array is { 1, -5, -9, 16 }.

As Google says, first we need to morph function given (the equation actually) to some other function. E.g. if the given equation is y = f(x), we should define other function, x = g(x) and then do the algorithm:

while (fabs(f(x)) > etha)
  x = g(x);

To find out the root.

The question is: how to define that g(x) using coefficient array and the range given only?

The problem is: when i define g(x) like this

enter image description here

or

enter image description here

for the equation given, any start value for x will lead me to the second equation’s root. And no one of ’em would give me the other two (roots are { -2.5, 1.18, 6.05 } and my code gives 1.18 only).

My code is something like this:

float a[] = { 1.f, -5.f, -9.f, 16.f }, etha = 0.001f;

float f(float x)
{
    return (a[0] * x * x * x) + (a[1] * x * x) + (a[2] * x) + a[3];
}

float phi(float x)
{
    return (a[3] * -1.f) / ((a[0] * x * x) + (a[1] * x) + a[2]);
}

float iterationMethod(float a, float b)
{
    float x = (a + b) / 2.f;

    while (fabs(f(x)) > etha)
    {
        x = phi(x);
    }

    return x;
}

So, calling the iterationMethod() passing ranges { -3, 0 }, { 0, 3 } and { 3, 10 } will provide 1.18 number three times along.

Where am i wrong and how should i act to get it work right?

UPD1: i do not need any third-party libraries.

UPD2: i need “Simple Iteration” algorithm exactly.

  • 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-05-26T14:02:20+00:00Added an answer on May 26, 2026 at 2:02 pm

    The link you posted in your comment explains why you can’t find all the roots with this algorithm – it only converges to a root if |phi'(x)| < 1 around the root. That’s not the case with any of the roots of your polynomial; for most starting points, the iteration will end up bouncing around the middle root, and eventually get close to it by accident; it will almost certainly never get close enough to the other roots, wherever it starts.

    To find all three roots, you need a more stable algorithm such as Newton’s method (which is also described in the tutorial you linked to). This is also an iterative method; you can find a root of f(x) using the iteration x -> x - f(x)/f'(x). This is still not guaranteed to converge, but the convergence condition is much more lenient. For your polynomial, it might look a bit like this:

    #include <iostream>
    #include <cmath>
    
    float a[] = { 1.f, -5.f, -9.f, 16.f }, etha = 0.001f;
    
    float f(float x)
    {
        return (a[0] * x * x * x) + (a[1] * x * x) + (a[2] * x) + a[3];
    }
    
    float df(float x)
    {
        return (3 * a[0] * x * x) + (2 * a[1] * x) + a[2];
    }
    
    float newtonMethod(float a, float b)
    {
        float x = (a + b) / 2.f;
        while (fabs(f(x)) > etha)
        {
            x -= f(x)/df(x);
        }
    
        return x;
    }
    
    int main()
    {
        std::cout << newtonMethod(-5,0) << '\n'; // prints -2.2341
        std::cout << newtonMethod(0,5) << '\n';  // prints  1.18367
        std::cout << newtonMethod(5,10) << '\n'; // prints  6.05043
    }
    

    There are many other algorithms for finding roots; here is a good place to start learning.

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

Sidebar

Related Questions

Given an array like : [0,1,1] How can I elegantly check that: Only one
Find the first covering prefix of a given array. A non-empty zero-indexed array A
We gave a given array which can be in 4 states. array has values
Given an array, A, containing, in some order, all but one of the k-bit
I've got some library code that works on a range of .NET runtimes (regular,
I want to find a nonempty, contiguous subarray for a given input array of
Given this array int [] myArray = {5,-11,2,3,14,5,-14,2}; You are to find the maximum
I have a string. I need to replace all instances of a given array
Given an array of n Objects, let's say it is an array of strings
Given an array of characters which forms a sentence of words, give an efficient

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.