Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MatLab: Your help is Needed Evaluating a polynomial can be an \"expensive\" thin

ID: 3768379 • Letter: M

Question

MatLab: Your help is Needed

Evaluating a polynomial can be an "expensive" thing for a computer. The "cheapest" way to evaluate a polynomial is to use a recursive algorithm. For example if p_4(x) = 3 - 2x + x^2 + 5x^3 + x^4, begin by rewriting it in a modified expanded form as follows: p_4(x) = 3 + x (-2 + x (1 + x (-5 + x))). Then p_4(x) = 3 + xp_3(x), where p_3(x) = -2 + xp_2(x), p_2(x) = 1 + xp_1(x), and p_1(x) = -5 + x. To evaluate p_4(2) we calculate as follows: Write a recursive program to calculate the value of any polynomial function given a list of its coefficients (in ascending order) and a value of x.

Explanation / Answer

#include #include #define MAXSIZE 10 void main() { int array[MAXSIZE]; int i, num, power; float x, polySum; printf("Enter the order of the polynomial "); scanf("%d", &num); printf("Enter the value of x "); scanf("%f", &x); /* Read the coefficients into an array */ printf("Enter %d coefficients ", num + 1); for (i = 0; i