General formula:
Specifies the function value at point x.
Ideas:
Using the qin Jiushao algorithm
The polynomial is expressed as the following nested pattern:
It can then be converted into programming language ideas :
This can be done through a for loop.
Code implementation:
The C language code is as follows:
#include <stdio.h>/** Function Name: Double ODPF (double array[], int n, double x) * parameter: double array[] coefficient array * int n = n Item * Double x x Value * return value: Compute knot Fruit sum* Description: One dimensional polynomial function polynomial evaluation*/DoubleODPF (DoubleArray[],intNDoublex) { Doublesum; Sum= array[n-1]; for(inti = n-2; I >=0; i--) {sum= SUM * x +Array[i]; } returnsum;}intMain () {Doublearray[ -];Doublex; intN; printf ("Please enter the number of items:"); scanf ("%d",&N); printf ("Please enter a factor (space separated):"); for(inti = n-1; I >=0; i--) {scanf ("%LF",&Array[i]); } while(true) {printf ("Please enter the value of x:"); scanf ("%LF", &x); printf ("x =%5.2LF, p (%5.2lf) =%.2lf\n\n", x, X, ODPF (array, n, x)); }
return 0;}
Test value:
3 1 2 3 2 Results: 11.00 6 2 3 1 4 5 3 3 Results: 810.00
Program Run Result:
After testing, the algorithm is designed correctly.
Algorithm research: one-dimensional polynomial evaluation (Qin Jiushao algorithm)