Forum Stats

  • 3,875,419 Users
  • 2,266,914 Discussions
  • 7,912,203 Comments

Discussions

We have polynomial equation: y=ax^3+bx^2+cx+d. We have the values of x and y; need to find a,b,c,d.

User_JEK6V
User_JEK6V Member Posts: 1 Green Ribbon
edited Nov 2, 2022 5:17AM in Java Programming

We have polynomial equation: y=ax^3+bx^2+cx+d.

We have the array of values of x and y.

Need to find the values of a, b, c, d in java.

Can someone help me in finding the values of a, b, c, d using java or related polynomial libraries.


Eg.:

x={0, 1, 2, 3, 4, 5}, y={1.1, -5.2, -3.1, 8.5, 6.2}

degree=3.

Need polynomial equation as output in below format:

y=ax^3+bx^2+cx+d with values of a, b, c, d.

Answers

  • justsomeone
    justsomeone Member Posts: 40 Red Ribbon

    Hello @User_JEK6V


    first think of it as math problem then find how you solve it in math then code that into java

    x={0, 1, 2, 3, 4, 5}, y={1.1, -5.2, -3.1, 8.5, 6.2}

    for example using those values

    x =0 and y = 1.1 and apply it to the equation

    y=ax^3+bx^2+cx+d

    1.1=a*0^3+b*0^2+c*0+d which become

    1.1 = d

    using the next value of x and y

    -5.2 = a + b + c +1.1 i used the value of d from the previous result

    now we can get c from this one as

    c = -5.2 - 1.1 - a -b

    using the next value of x and y

    -3.1 = 8a + 4 b + 2c + d

    -3.1 = 8a + 4 b + 2*(-5.2 - 1.1 - a -b) + 1.1

    do your math and get b from this last equations and so on

    so what i am doing that i get the value of one variable based on the remaining variable

    now change that pattern to code and you will get it


    hope that help and have a nice day :)