符号が変化せずに収束しません。
どこが間違っているのでしょうか?
分かる方よろしくお願いいたします。
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include"MT.h"
using namespace std;
int main()
{
double x = 0;/*初期化*/
double gradient;
double ipu = 0.001;
double f = 0;
int judge = 1;/*+ or -*/
int new_judge;
gradient = -4 * x + 5;
if (gradient > 0)judge = 1;
else judge = 0;
gradient = 0;
while (1){
gradient = -4 * x + 5;
if (gradient > 0)new_judge = 1;
else new_judge = 0;
if (new_judge != judge)break;
x = x + ipu*gradient;
gradient = 0;
}
f = -2 * x*x + 5 * x + 2;
cout << "x.." << x << ", f(x).." << f << endl;
return 0;
}