Latest Post
Optimization: Interval Halving Method
- Get link
- X
- Other Apps
1. Interval Halving Method Algorithm in C
#include<stdio.h>
double myFun(double x);
int main()
{
double a, b, y, x, xm, x1, x2, fx1, fx2, fxm, L, t=0.01;
printf("Enter a:");
scanf("%lf",&a); //Upper Bound
printf("Enter b:");
scanf("%lf",&b); //Lower Bound
xm = (a + b)/2;
jump:
L = b-a;
x1 = a + (L/4);
x2 = b - (L/4);
printf("\n\na = %.2lf",a);
printf("\nb = %.2lf",b);
printf("\nx1 = %.2lf",x1);
printf("\nx2 = %.2lf",x2);
printf("\nxm = %.2lf",xm);
printf("\nL = %.2lf",L);
fx1 = myFun(x1);
printf("\nf(x1) = %.2lf",fx1);
fx2 = myFun(x2);
printf("\nf(x2) = %.2lf",fx2);
fxm = myFun(xm);
printf("\nf(xm) = %.2lf",fxm);
if(L > t)
{
if (fx1 < fxm)
{
a = a;
b = xm;
xm = x1;
goto jump;
}
else if (fx2 < fxm)
{
b = b;
a = xm;
xm = x2;
goto jump;
}
else if (fx1 > fxm && fx2 > fxm)
{
a = x1;
b = x2;
xm = (a+b)/2;
goto jump;
}
else
{
goto end;
}
}
else
{
goto end;
}
end:
return 0;
}
double myFun(double x) // function definition
{
double y;
y = ((x*x)+(54/x));
return y; // return statement
}
double myFun(double x);
int main()
{
double a, b, y, x, xm, x1, x2, fx1, fx2, fxm, L, t=0.01;
printf("Enter a:");
scanf("%lf",&a); //Upper Bound
printf("Enter b:");
scanf("%lf",&b); //Lower Bound
xm = (a + b)/2;
jump:
L = b-a;
x1 = a + (L/4);
x2 = b - (L/4);
printf("\n\na = %.2lf",a);
printf("\nb = %.2lf",b);
printf("\nx1 = %.2lf",x1);
printf("\nx2 = %.2lf",x2);
printf("\nxm = %.2lf",xm);
printf("\nL = %.2lf",L);
fx1 = myFun(x1);
printf("\nf(x1) = %.2lf",fx1);
fx2 = myFun(x2);
printf("\nf(x2) = %.2lf",fx2);
fxm = myFun(xm);
printf("\nf(xm) = %.2lf",fxm);
if(L > t)
{
if (fx1 < fxm)
{
a = a;
b = xm;
xm = x1;
goto jump;
}
else if (fx2 < fxm)
{
b = b;
a = xm;
xm = x2;
goto jump;
}
else if (fx1 > fxm && fx2 > fxm)
{
a = x1;
b = x2;
xm = (a+b)/2;
goto jump;
}
else
{
goto end;
}
}
else
{
goto end;
}
end:
return 0;
}
double myFun(double x) // function definition
{
double y;
y = ((x*x)+(54/x));
return y; // return statement
}
Output:
![]() |
| Interval Halving Method Optimization Algorithm |
- Get link
- X
- Other Apps
Comments
Popular posts from this blog
VLSI: 8-3 Encoder Dataflow Modelling with Testbench
Verilog Code for 8-3 Encoder Dataflow Modelling module encoder_8_to_3( input d0, input d1, input d2, input d3, input d4, input d5, input d6, input d7, output q0, output q1, output q2 ); assign q0 = ( d1 | d3 | d5 | d7 ); assign q1 = ( d2 | d3 | d6 | d7 ); assign q2 = ( d4 | d6 | d5 | d7 ); endmodule //Testbench code for 8-3 Encoder Dataflow Modelling initial begin ...
VLSI: 4-1 MUX Dataflow Modelling with Testbench
Verilog Code for 4-1 MUX Dataflow Modelling module m41(out, i0, i1, i2, i3, s0, s1); output out; input i0, i1, i2, i3, s0, s1; assign y0 = (i0 & (~s0) & (~s1)); assign y1 = (i1 & (~s0) & s1); assign y2 = (i2 & s0 & (~s1)); assign y3 = (i3 & s0 & s1); assign out = (y0 | y1 | y2 | y3); endmodule //Testbench code for 4-1 MUX Dataflow Modelling initial begin // Initialize Inputs a = 1;b = 0;c = 0;d = 0;s0 = 0;s1 = 0; ...
VLSI: 1-4 DEMUX (Demultiplexer) Dataflow Modelling with Testbench
Verilog Code for 1-4 DEMUX Dataflow Modelling module demux_1_to_4( input d, input s0, input s1, output y0, output y1, output y2, output y3 ); assign s1n = ~ s1; assign s0n = ~ s0; assign y0 = d& s0n & s1n; assign y1 = d & s0 & s1n; assign y2 = d & s0n & s1; assign y3 = d & s0 & s1; endmodule //Testbench code for 1-4 DEMUX Dataflow Modelling initial begin // Initialize Inputs ...
Verilog: 8 to 1 Multiplexer (8-1 MUX) Dataflow Modelling with Testbench Code
Verilog Code for 8 to 1 Multiplexer Dataflow Modelling module mux_8to1( input a, input b, input c, input D0, input D1, input D2, input D3, input D4, input D5, input D6, input D7, output out, ); module m81( output out, input D0, D1, D2, D3, D4, D5, D6, D7, S0, S1, S2); assign S1bar=~S1; assign S0bar=~S0; assign S2bar=~S2; assign out = (D0 & S2bar & S1bar & S0bar) | (D1 & S2bar & S1bar & S0) | (D2 & S2bar & S1 & S0bar) + (D3 & S2bar & S1 & S0) + (D4 & S2 & S1bar & S0bar) + (D5 & S2 & S1bar & S0) + (D6 & S2 & S1 & S0bar) + (D7 & S2 & S1 & S0); endmodule //Testbench code for 8-1 MUX Dataflow Modelling initial begin // Initialize Inputs a= 0;b = 0;c = 0;D0 = 1;D1 = 0;D2 = 0;D3 = 0;D4 = 0;D5 = 0;D6 = 0;D7 = 0; // Wait 100 ns for global reset to finish #100; // Add stimulus here #100; a = 0;b = 0;c = 1;d0 = ...
Full Subtractor Verilog Code in Behavioral Modelling with Testbench Code
Full Subtractor Verilog Code in Behavioral Modelling module Full_Sub ( input a, b, bin; output diff, borr ); always @(a or b or bin) assign {borr,diff} = (~a) + b + bin; endmodule // test-bench initial begin a=0; b=0; bin=0; #100; //wait 100ns for global reset to finish //add stimulus here #100 a=0; b=1; bin=0; #100 a=1; b=0; bin=0; #100 a=1; b=1; bin=0; end initial begin #100 $ monitor (“a=%b, b=%b, bin=%b, diff=%b, borr=%b”, a, b, bin, diff, borr); end endmodule Xilinx Output: Full Subtractor Verilog Code Behavioral Modelling


Best Python Training in Pune with Placement
ReplyDeletePython Course in Pune
Python Certification Course in Pune
Python Programming Training in Pune
Advanced Python Classes in Pune