Logo 
Search:

C Programming Articles

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

FALSE POSITION METHOD USING x1-exp(-x1)

Posted By: Luther Fischer     Category: C Programming     Views: 4767

Write a program of FALSE POSITION METHOD USING x1-exp(-x1).

Code for FALSE POSITION METHOD USING x1-exp(-x1) in C Programming

#include<stdio.h>
#include<conio.h>
#include<math.h>
#define epsil 0.00001

int p,c[10];

void appro();
voidfalse(float,float,float,float);

void main()
{
clrscr();
appro();
getch();
}

voidfalse(float x1,float x2,float fx1,float fx2)
{
float x3,fx3,temp;
int n=1;
if(fx1<0&&fx2>0||fx1>0&&fx2<0)
{
printf("******************************************************************\n");
printf("\nIt   x1        fx1        x2         fx2        x3         fx3\n");
printf("******************************************************************\n");
         do
         {
         temp=x3;
         x3=(((x1*fx2)-(x2*fx1))/(fx2-fx1));
         fx3=x3-exp(-x3);
         if(fx3==0)
         {
        break;
         }
         if((fx1*fx3)>0)
         {
         x1=x3;
         fx1=fx3;
         }
         else
         {
         x2=x3;
         fx2=fx3;
         }
         printf("%d   %.4f    %.4f     %.4f    %.4f    %.4f     %.4f\n",n,x1,fx1,x2,fx2,x3,fx3);
         n=n+1;
         }while((fabs(temp-x3)>epsil)&&(fx3!=0));
printf("\n\t\t********************\n");
printf("\n\t\tThe root is %.4f\n",x3);
printf("\t\t********************\n");
}
else
{
clrscr();

printf("\nError in the Initial approximation\n ");
printf("\nPlease enter right approximation\n\n");
appro();
}
}
void appro()
{
float x1,x2,x3,fx1,fx2,fx3;
printf("\nPlease Enter first approximation: ");
scanf("%f",&x1);
printf("\nPlease Enter second approximation: ");
scanf("%f",&x2);
fx1=x1-exp(-x1);
fx2=x2-exp(-x2);
false(x1,x2,fx1,fx2);
}
  
Share: 


Didn't find what you were looking for? Find more on FALSE POSITION METHOD USING x1-exp(-x1) Or get search suggestion and latest updates.

Luther Fischer
Luther Fischer author of FALSE POSITION METHOD USING x1-exp(-x1) is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

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

 
Turi Ismo from United States Comment on: Mar 30
send me c++ programm that do false position method

View All Comments