Friday, October 21, 2022

3-Dimensional Stepwise Descent Method

 //  3-Dimensional Stepwise Descent Method:
#include <iostream>
#include <math.h>
double f(double t, double x, double y)
{
    return (t - 1.111111)* (t - 1.111111) * (x - 2.2222222) * (x - 2.2222222)* (y - 3.3333333) * (y - 3.33333333)+9;
}
int main()
{
    double r=100.,p=100,q=100,step=1., minstep=1./1000.;
    while (step > minstep)  
    {
        while (f(r + step,p,q) < f(r,p,q)) r = r + step;
        while (f(r - step,p,q) < f(r,p,q)) r = r - step;
        while (f(r, p + step, q) < f(r, p, q)) p = p + step;
        while (f(r, p - step, q) < f(r, p, q)) p = p - step;
        while (f(r, p, q+step) < f(r, p, q)) q = q + step;
        while (f(r, p, q-step) < f(r, p, q)) q = q - step;
        step = step / 2;
     }
    std::cout << "Minimum is in x =" << r << " " << p << " " << q << " ";
    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,...