Friday, October 21, 2022

One-dimensional Stepwise Descent Method

 //  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;
}

No comments:

Post a Comment

N-point Star in Microsoft Visual Studio Console App

#include <windows.h> #include <cmath> #include <iostream> LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,...