Latest Post

Ads

Optimization: Exhaustive Search Method

Exhaustive Search Method Opimization Algorithm in C

#include<stdio.h>
#include<conio.h>
double myFun(double x);
int main()
{
 double a, b, N, y, x, x1, x2, x3, fx1, fx2, fx3, D,i=0;
 printf("Enter a:");
 scanf("%lf",&a);
 printf("Enter b:");
 scanf("%lf",&b);
 printf("Enter no. of N:");
 scanf("%lf",&N);

 D = (b-a)/N;
 printf("D = %.2lf",D);
 x1=a;
 x2=x1+D;
 x3=x2+D;
 jump:
 if (i < 300)
 {
  printf("\n\nx1 = %.2lf",x1);
  printf("\nx2 = %.2lf",x2);
  printf("\nx3 = %.2lf",x3);
  fx1 = myFun(x1);
  printf("\nf(x1) = %.2lf",fx1);
  fx2 = myFun(x2);
  printf("\nf(x2) = %.2lf",fx2);
  fx3 = myFun(x3);
  printf("\nf(x3) = %.2lf",fx3);
  if (fx1 >= fx2 && fx2<= fx3)
  {
   printf("\nCondition met");
   goto end;
  }
  else
  {
   printf("\nCondition not met.");
   x1 = x2;
   x2 = x1 + D;
   x3 = x2 + D;
   i = i + 1;
   goto jump;
  }
 }
 else
 {
  goto end;
 }
 end:
 return 0;
}
 double myFun(double x)         // function definition  
{
    double y;
    y = ((x*x)+(54/x));
    return y;                  // return statement
}

Output:
Image of Exhaustive Search Algorithm
Exhaustive Search Algorithm

Comments

Ads

Popular posts from this blog

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

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

VLSI: 4-1 MUX Dataflow Modelling with Testbench

VLSI: Half Subtractor and Full Subtractor Gate Level Modelling

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