Using C programming language. h(x) = x - f(x) f\'(x)/[f\'(x)]^2 - f(x) f\"(x). T
ID: 3928667 • Letter: U
Question
Using C programming language. h(x) = x - f(x) f'(x)/[f'(x)]^2 - f(x) f"(x). The function f(x) = 2cos(5x) + 2cos(4x) + 6cos(3x) + 4cos(2x) + 10cos(x) + 3 has two roots on the interval [0, 3]; one root is near 1 and the other near 2. Use Newton's method x_n+1 = g(x_n) with x_0 = 1 and also with x_0 = 2 to approximate these two roots. Use the fact that the exact roots are pi/3 and 2 pi/3 to compute the error e_n at each iteration for n = 0, 1, ..., 18. Use the method x_n + 1 = h(x_n) with x_0 = 1 and again also with x_0 = 2 to approximate these two roots. Again use the fact that the exact roots are pi/3 and 2 pi/3 to compute the error e_n at each iteration for n = 0, 1, ..., 18. Comment on the rate of convergence and the effects of rounding error in the above two computations.Explanation / Answer
/*
* C program to evaluate a given polynomial by reading its coefficients
* in an array.
* P(x) = AnXn + An-1Xn-1 + An-2Xn-2+... +A1X + A0
*
* The polynomial can be written as:
* P(x) = A0 + X(A1 + X(A2 + X(A3 + X(Q4 + X(...X(An-1 + XAn))))
* and evaluated starting from the inner loop
*/
#include <stdio.h>
#include <stdlib.h>
#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 <= num; i++)
{
scanf("%d", &array[i]);
}
polySum = array[0];
for (i = 1; i <= num; i++)
{
polySum = polySum * x + array[i];
}
power = num;
printf("Given polynomial is: ");
for (i = 0; i <= num; i++)
{
if (power < 0)
{
break;
}
/* printing proper polynomial function */
if (array[i] > 0)
printf(" + ");
else if (array[i] < 0)
printf(" - ");
else
printf(" ");
printf("%dx^%d ", abs(array[i]), power--);
}
printf(" Sum of the polynomial = %6.2f ", polySum);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.