answersLogoWhite

0


Best Answer

#include

#include

#include

/* define prototype for USER-SUPPLIED function f(x) */

double ffunction(double x);

/* EXAMPLE for "ffunction" */

double ffunction(double x)

{

return (x * sin(x) - 1);

}

/* -------------------------------------------------------- */

/* Main program for algorithm 2.3 */

void main()

{

double Delta = 1E-6; /* Closeness for consecutive iterates */

double Epsilon = 1E-6; /* Tolerance for the size of f(C) */

int Max = 199; /* Maximum number of iterations */

int Satisfied = 0; /* Condition for loop termination */

double A, B; /* INPUT endpoints of the interval [A,B] */

double YA, YB; /* Function values at the interval-borders */

int K; /* Loop Counter */

double C, YC; /* new iterate and function value there */

double DX; /* change in iterate */

printf("-----------------------------------------------------\n");

printf("Please enter endpoints A and B of the interval [A,B]\n");

printf("EXAMPLE : A = 0 and B = 2. Type: 0 2 \n");

scanf("%lf %lf", &A, &B);

printf("The interval ranges from %lf to %lf\n", A,B);

YA = ffunction(A); /* compute function values */

YB = ffunction(B);

/* Check to see if YA and YB have same SIGN */

if( ( (YA >= 0) && (YB >=0) ) ( (YA < 0) && (YB < 0) ) ) {

printf("The values ffunction(A) and ffunction(B)\n");

printf("do not differ in sign.\n");

exit(0); /* exit program */

}

for(K = 1; K <= Max ; K++) {

if(Satisfied 0) { /* first 'if' */

Satisfied = 1; /* Exact root is found */

}

else if( ( (YB >= 0) && (YC >=0) ) ( (YB < 0) && (YC < 0) ) ) {

B = C; /* Squeeze from the right */

YB = YC;

}

else {

A = C; /* Squeeze from the left */

YA = YC;

}

if( (fabs(DX) < Delta) && (fabs(YC) < Epsilon) ) Satisfied = 1;

} /* end of 'for'-loop */

printf("----------------------------------------------\n");

printf("The number of performed iterations is : %d\n",K - 1);

printf("----------------------------------------------\n");

printf("The computed root of f(x) = 0 is : %lf \n",C);

printf("----------------------------------------------\n");

printf("Consecutive iterates differ by %lf\n", DX);

printf("----------------------------------------------\n");

printf("The value of the function f(C) is %lf\n",YC);

} /* End of main program */

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

#include
#include
#include
#include
float eq(float);
void falsi(float,float,int);
void main()
{
float x0,x1;
int iter

;
clrscr();
cout<<"Regula Falsi Method Using C++";
cout<cin>>x0;
cin>>x1;
cout<<"Enter number of iterations::";
cin>>iter;
falsi(x0,x1,iter);
getch();
}
float eq(float x)
{
return((x*x*x)-(2*x)-5);
}
void falsi(float x0, float x1, int iter)
{
int i;
float x;
for(i=1;i<=iter;i++)
{
x=x0-((x1-x0)/(eq(x1)-eq(x0)))*eq(x0);
if(eq(x)<0)
{
x0=x;
}
else
if(eq(x)>0)
{
x1=x;
}
cout<}
}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the C plus plus program for regula falsi method?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering
Related questions

How to restart c plus plus program?

Exit the program and relaunch it.


Is there an answer book for the A plus program?

The A Plus Program is an initiative, not a test. So no, there is no answer book.


Can you program games with c plus plus?

Yes, you can program games with C++.


How do you make C plus plus program to draw a straight line using for loop method?

void line(int length) { for(int i=0; i&lt;length; ++i) std::cout&lt;&lt;'_'; std::cout&lt;&lt;std::endl; }


Can you declare a method within a method in c or c plus plus?

C: there are no methods in C. C++: no.


What do you call an object function in c plus plus?

method


Why does sometimes when you run a program it will execute the previous program instead the current open program in C plus plus?

Because you aren't careful enough.


What is the only function all C plus plus programs must contain?

Every C plus plus program that is a main program must have the function 'main'.


A program c plus plus on automorphic numbers or not?

how to write a program that counts automorphic number from 1 to 999


Lint is a compiler b a interactive debugger c a cinterpreter d a tool for analysing c plus plus program?

d a tool for analysing c plus plus program


How do you write a C plus plus program that will display the first 10 positive prime numbers?

By learning how to program on C+.


How does algorithm and c plus plus program get along?

They are bosom-friends.