C Program To Calculate Values Using Fixed Point Iteration Method

Algorithm

  1. Start
  2. Read values of x0 and e.
    *Here x0 is the initial approximation
    e is the absolute error or the desired degree of accuracy, also the stopping criteria*
  3. Calculate x1 = g(x0)
  4. If [x1 – x0] <= e, goto step 6.
    *Here [ ] refers to the modulus sign*
  5. Else, assign x0 = x1 and goto step 3.
  6. Display x1 as the root.
  7. Stop
#include<stdio.h>
#include<math.h>
#include<conio.h>
#define EST 0.05
#define F(x) exp(-x)-x
#define G(x) exp(-x)
int main()
{
int i=1;
float error,x0,x1,temp;
printf("Enter the initial guess x0:\n");
scanf("%f",&x0);
printf("Iteration x0\t\t x1\t Error\n");
x1=G(x0);
error=fabs((x1-x0)/x1);
printf("%d\t %.4f\t%.4f\t %.4f\n",i,x0,x1,error);
do
{
i++;
temp=x1;
x0=temp;
x1=G(x0);
error=fabs((x1-x0)/x1);
printf("%d\t %.4f\t%.4f\t %.4f\n",i,x0,x1,error);
}while (error>EST);
}

C Program To Calculate Values Using Honors Method 

Pseudo Code

coefficients := [-19, 7, -4, 6] # list coefficients of all x^0..x^n in order
x := 3
accumulator := 0
for i in length(coefficients) down to 1 do
    # Assumes 1-based indexing for arrays
    accumulator := ( accumulator * x ) + coefficients[i]
done
# accumulator now has the answer


#include<stdio.h>


#include<conio.h>


#include<math.h>


//Given Polynomial = F(x) (4*x*x*x*x)+(5*x*x*x)+(6*x*x)+(7*x)+8


int main()


{


int i,x,n;


printf("Enter the degree of the polynomial:\n");


scanf("%d",&n);


int a[n+1],b[n+1];


printf("Enter the cofficient of polynomial starting from the higher degree:\n");


for(i=n;i>=0;i--)


{


scanf("%d",&a[i]);


}


printf("Enter the value at which polynomial has to be evaluated:\n");


scanf("%d",&x);


b[n]=a[n];


for(i=n-1;i>=0;i--)


{


b[i]=a[i]+(b[i+1]*x);


}


printf("The value of given polynomial at X=5 is %d.",b[0]);


}



Share To:

Arogya Thapa Magar

Post A Comment:

0 comments so far,add yours