This question sounds much like homework to me, thus I will only give you hints at what to look for:
- Define what polynomial division is.
- Every Polynom can be written in two standard forms (at least if you also allow imaginary numbers, which won't be necessary for our case). Identify those two forms.
- Are those two forms of a given polynomial unique? Why? Why not?
- You are looking for a f(X) which satisfies f(Xi) = Yi for all i between 1 and the length of your data column.
- Start with the easy cases of i=0, i=1 and i=2.
- Can you extend a solution for i=1 to i=2?
- Can you extend a solution for i=n to i=n+1?
perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The
$d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider
($c = $d->accept())->get_request(); $c->send_response( new #in the
HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web
| [reply] [d/l] |
| [reply] |
The question is not vague. The man has a set of n (x,y) coordinates that he wants to plot a polynomial of the nth order through.
Let's say our polynomial looks like this:
y = a0 + a1 x + a2 x2 + a3 x3 + ... + an xn
If we fill in the (x,y) pairs in this equation, we get n equations and since we have n unknowns (a0 .. an) we can solve the equations. This is usually done in matrix form.
| [reply] |
Have a look at these two modules:
| [reply] |
You want Y=f(X) where f is polynomial, right? Lagrange interpolation will give you algebraic equality, but watch out for numerical problems if you want to use f. Your interpolant will have one less degree than the length of your list. If you are happy with approximate equality using a lower degree, you need a regression routine.
If you look at PDL::Fit::Polynomial, you can do it either way (because the degree of the approximating polynomial is input by the user). PDL also provides a gateway to standard numerical routines written in C. | [reply] |
If it's non-linear, it would also be worth considering PDL::Opt::NonLinear, though that's for optimisation, not fitting.
| [reply] |
do { my $homework; } while ( $i->sleep() );
:-)
BCE --Your punctuation skills are insufficient!
| [reply] |