Latest Post

Ads

Optimization: Bound Phase Method

Bound Phase Method Algorithm in C

#include<stdio.h>
#include<math.h>
double myFun(double x);
int main()
{
 double xw,a,b,fa,fb,fxw,D,y ;
 int k,o,z;
 float x[100],fx[100];
 k = 0;
 start:
 printf("Enter x[0]:");
 scanf("%lf",&xw);
 printf("Enter D:");
 scanf("%lf",&D);

 a = xw + D;
 b = xw - D;
 fxw = myFun(xw);
 printf("\nf(x0) = %.2lf",fxw);
 fa = myFun(a);
 printf("\nf(x0 + D) = %.2lf",fa);
 fb= myFun(b);
 printf("\nf(x0 - D) = %.2lf",fb);
 printf("\nx[%d] = %.2lf",k,xw);
 x[0] = xw;
 fx[k] = fxw;
 o = k+1;

 if (fb <= fxw && fxw <= fa)
 {

  D = -D;
  goto jump1;

 }
 else if (fb >= fxw && fxw >= fa)
 {
  goto jump1;
 }

 else
 {
  printf("\n\n\tChange Initial Guess...\n\n");
  goto start;
 }

  jump1:
  x[o] = (x[k] + (pow(2,k) * D));
  printf("\n\nx[%d] = %.3f",o,x[o]);
  fx[o] = myFun(x[o]);
  printf("\nfx[%d] = %.3f",o,fx[o]);

 if (fx[o] < fxw)
 {


  if (fx[o] < fx[k])
  {
   k = k + 1;
   o = o + 1;
  
   goto jump1;
  }
  else
  {
  printf("\nBounded range: (x(%d),x(%d))",k-1,k+1);
  printf("\nk = %d",k);
  }
 }
 else
 {
  goto end;
 }

 end:
 return 0;
}
 double myFun(double x)         // function definition  
{
    double y;
    y = ((x*x)+(54/x));
    return y;                  // return statement
}

Output:
Bound Phase Method Optimization Algorithm
Bound Phase Method Optimization Algorithm

Comments

Ads

Popular posts from this blog

VLSI: 1-4 DEMUX (Demultiplexer) Dataflow Modelling with Testbench

VLSI: BCD to Excess 3 and Excess 3 to BCD Dataflow Modelling

VLSI: 2 Bit Magnitude Comparator Dataflow Modelling

1 to 4 DEMUX (Demultiplexer) Verilog CodeStructural/Gate Level Modelling with Testbench

Full Subtractor Verilog Code in Structural/Gate Level Modelling with Testbench