I am trying to write an algorithm that finds the Lagrange polynomial given a set of points, in quadratic time.

I don't necessarily want the code to do it, just an explanation on how to write this algorithm in java in quadratic time. I know the equation, its relatively simple, I just have no idea how to represent it in Java.

For example, I know the code must calculate P(x) (for j to N, j != i) = (x - xi)/(xj-xi), and I represent each xi and xj value in an array, but how do I represent the symbol x?

If anyone can provide an explanation on how I can go about this algorithm, or any help whatsoever, it would be greatly appreciated.


Just for clarification, here is a link to the definition of a Lagrange polynomial:

6 Years
Discussion Span
Last Post by NormR1

Break up the equation into simple binary operations and someone can show you the code.
For example to multiply two variables: var1 * var2

how do I represent the symbol x

A variable named: x would be defined by putting a type in front of the x:
<THE TYPE Here> x;
valid types are: int, short, float, double, .....

If you need help writing a program, have you thought of hiring a programmer?

Edited by NormR1: n/a

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.