⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rtflsp.cpp

📁 用vc++写的常用的一些数值算法
💻 CPP
字号:
double rtflsp(double x1, double x2, double xacc)
{
	int maxit,j;
	double fl,fh,xl,xh,swap,dx,temp,f,del;
    maxit = 30;
    fl = func(x1);
    fh = func(x2);
    if (fl * fh > 0)
	{
        cout<< "root must be bracketed for false position"<<endl;
    }
    if (fl < 0)
	{
        xl = x1;
        xh = x2;
	}
    else
	{
        xl = x2;
        xh = x1;
        swap = fl;
        fl = fh;
        fh = swap;
    }
    dx = xh - xl;
    for (j = 1; j<=maxit; j++)
	{
        temp = xl + dx * fl / (fl - fh);
        f = func(temp);
        if (f < 0)
		{
            del = xl - temp;
            xl = temp;
            fl = f;
		}
        else
		{
            del = xh - temp;
            xh = temp;
            fh = f;
        }
        dx = xh - xl;
        if ((fabs(del) < xacc) || (f == 0)) break;
    }
	return temp;
    cout<< "rtflsp exceed maximum iterations";
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -