Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Numerical MethodsRSS Feeds

Program of FALSE POSITION METHOD

Posted By: Volker Fischer     Category: C Programming     Views: 28982

Write a program of FALSE POSITION METHOD.

Code for Program of FALSE POSITION METHOD in C Programming

#include<stdio.h>
#include<conio.h>
#include<math.h>
#define ESP 0.0001
#define F(x) 3*(x) - 1 - cos(x)
void main()
{
  float x0,x1,x2,f1,f2,f0;
  int count=0;
  clrscr();
  do
  {
  printf("\nEnter the value of x0: ");
  scanf("%f",&x0);
  }while(F(x0) > 0);
  do
  {
  printf("\nEnter the value of x1: ");
  scanf("%f",&x1);
  }while(F(x1) < 0);
  printf("\n__________________________________________________________\n");
  printf("\n    x0\t       x1\t x2\t   f0\t   f1\t   f2");
  printf("\n__________________________________________________________\n");
  do
  {
  f0=F(x0);
  f1=F(x1);
  x2=x0-((f0*(x1-x0))/(f1-f0));
  f2=F(x2);
  printf("\n%f %f %f %f %f %f",x0,x1,x2,f0,f1,f2);
  if(f0*f2<0)
   {
    x1=x2;
   }
   else
   {
    x0 = x2;
   }
  }while(fabs(f2)>ESP);
printf("\n__________________________________________________________\n");
printf("\n\nApp.root = %f",x2);
getch();
}

/*
OUT PUT
---------



Enter the value of x0: -1

Enter the value of x1: 1

__________________________________________________________

x0 x1 x2 f0 f1 f2
__________________________________________________________

-1.000000 1.000000 0.513434 -4.540302 1.459698 -0.330761
0.513434 1.000000 0.603320 -0.330761 1.459698 -0.013497
0.603320 1.000000 0.606954 -0.013497 1.459698 -0.000527
0.606954 1.000000 0.607096 -0.000527 1.459698 -0.000021
__________________________________________________________


App.root = 0.607096

*/
  
Share: 


Didn't find what you were looking for? Find more on Program of FALSE POSITION METHOD Or get search suggestion and latest updates.

Volker Fischer
Volker Fischer author of Program of FALSE POSITION METHOD is from Frankfurt, Germany.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!