Im trying to write a golden section optimization search program. I have written it to this point and im getting 25 errors in it and i do not know how to fix them. I am new to programming and did do research on the errors and am still unsure.
I still have to add a few more steps to the end including a way to print the results at the end.
any help is greatly appreciated.
#include <stdio.h>
#include <math.h>
#include <iostream>
using namespace std;
#define a 1.61803;
//Function to be analyzed
double F(double x) {
return x*x-20*x+100;
}
double xi, xu, xmax, fu, fi, f1, x1, f2, x2;
xi=0;
xu=100;
xmax=1000;
fu=F(xu);
fi=F(xu);
{ do {
int x1=xu;
int f1=fu;
xu=x1*(1+a)-xi*a;
if {
(xu>xmax);
break;
}
fu=F(xu);
if {
(fu>f1);
return 0;
}
else {
xi=x1;
fi=f1;
}
} while (fu>fi);
return 0;
}
double N=13;
double t=.381966;
int x1=(1-t)*xi+t*xu;
int f1=F(x1);
int x2=t*xi+(1-t)*xu;
int f2=F(x2);
double k=3;
E:
k = k+1;
if {
(k>N);
return 0;
}
else {
if {
(f1>f2);
xi=x1;
fi=f1;
x1=x2;
f1=f2;
x2=t*xi+(1-t)*xu;
f2=F(x2);
goto E;
}
else {
xu=x2;
fu=f2;
x2=x1;
f2=f1;
x1=(1-t)*xi+t*xu;
f1=F(x1);
goto E;
}
}
}