Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  fgfg
Language: C/C++
Code:
#include<stdio.h>
#include<conio.h> 
#include<math.h>

double P(double t){
     double p;
     p=100+(5.4*55+286)*(1+exp(-15/81*t))-53*t;
     return p;
};

main(){
     double a,b,x1,x2,xo,temp;
     int h;
     
     printf("Please enter the interval a,bn");
     scanf("%lf,%lf",&a,&b);
     
     printf("Please enter the number of iterationsn");
     scanf("%d",&h);
     x1=a+0.618*(b-a);
     x2=b-0.618*(b-a);
     
     for(int i=1;i<=h;i++){
     if(x1>x2){temp=x1;x1=x2;x2=temp;}
     
     printf("Iteration No1 %d na = %4.3lftx1 = %4.3lf  P(x1)= %4.3lftx2 = %4.3lf  P(x2)= %4.3lftb=%4.3lft",i,a,x1,P(x1),x2,P(x2),b);
     
     if(P(x1)>P(x2)){xo=x1;b=x2;x2=b-0.618*(b-a);}
     else {xo=x2;a=x1;x1=a+0.618*(b-a);}
     
     printf("X opt. = %4.3lfn",xo);
     }
     getch();
}

          
Comments: