// One-dimensional Stepwise Descent Method:
#include <iostream>
#include <math.h>
double f(double t)
{
return (t - 1.111111)* (t - 1.111111);
}
int main()
{
double x=100.,step=1., minstep=1./1000.;
while (step > minstep)
{
while (f(x + step) < f(x)) x = x + step;
while (f(x - step) < f(x)) x = x - step;
step = step / 2;
}
std::cout << "Minimum is in x =" << x << "\n";
return 0;
}
#include <iostream>
#include <math.h>
double f(double t)
{
return (t - 1.111111)* (t - 1.111111);
}
int main()
{
double x=100.,step=1., minstep=1./1000.;
while (step > minstep)
{
while (f(x + step) < f(x)) x = x + step;
while (f(x - step) < f(x)) x = x - step;
step = step / 2;
}
std::cout << "Minimum is in x =" << x << "\n";
return 0;
}
No comments:
Post a Comment