Answer to Question #18221 in C++ for wanu

Question #18221
Please, help me about the bisection method in C +?
Obtain the local minimize of the function f(x) = X^5-5X^3-20*X+5 on [-3,O] and [0,3] by bisection method >> and run it in a loop

help me++++
1
Expert's answer
2012-11-08T09:06:35-0500
#include "conio.h"
#include "iostream"
#include "math.h"
using namespace std;
&
& double f (double x)
{
double y;
y=pow(x,5)-5*pow(x,3)-20*x+5;

&
return(y);
}
&
&
int main()
{





& double a;
& double b;
& double e=0.000001;
& double x;
& double y,i,k;
& k=0.000000001;
& e=1;
& a=-3;
& b=0;
& while(fabs(e)>k){
& if(f(a)<f(b))
& b=(b+a)/2;
& else
& a=(b+a)/2; &
& e=(b-a) ;
& }
cout<<"[-3;0]\n"<<"Min& Y= "<<f(a)<<"& X= "<<a<<endl;
&
& a=0;
& b=3.0;
&
&
& for(;;)
& {
double x1=(a+b)/2-e/2;
double x2=(a+b)/2+e/2;
& if(f(x2)>f(x1))
b=x2;
& else
a=x1;
& double l=b-a;
& if(l<0.002)
break;
}
x=(a+b)/2;
double min=f(x);
cout<<"[0;3]\n"<<"Min& Y= "<<f(x)<<"& X= "<<x<<endl;


& _getch();
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

wanu
08.11.12, 17:13

can you tell me about ,how to if I want to show all of value, and next i choose minimun value from all>>> i want see all of value that program analyte+!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS