98 966
Assignments Done
98.9%
Successfully Done
In May 2021

# Answer to Question #18221 in C++ for wanu

Question #18221
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 &gt;&gt; and run it in a loop

help me++++
1
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!