sample5_9.cs

来自「用于矩阵的各种运算」· CS 代码 · 共 46 行

CS
46
字号
/*
 * 示例程序Sample5_9: NLEquations类的求非线性方程组一组实根的拟牛顿法
 */

using System;
using CSharpAlgorithm.Algorithm;

namespace CSharpAlgorithm.Sample
{
	class Class1
	{
        // 建立NLEquation的子类,在其中重载函数func
        class NLEq : NLEquations
        {
            protected override double Func(double[] x, double[] y)
            {
                y[0]=x[0]*x[0]+x[1]*x[1]+x[2]*x[2]-1.0;
                y[1]=2.0*x[0]*x[0]+x[1]*x[1]-4.0*x[2];
                y[2]=3.0*x[0]*x[0]-4.0*x[1]+x[2]*x[2];

                return 0.0;
            }
        }
        
        [STAThread]
		static void Main(string[] args)
		{
            // 求解
            NLEq nleq = new NLEq();
            double[] x={1.0,1.0,1.0};
            double t=0.1; 
            double h=0.1;
            double eps = 0.0000001;
            if (nleq.GetRootsetNewton(3, x, t, h, 100, eps))
            {
                for (int i=0; i<3; ++i)
                {
                    Console.WriteLine(x[i]);
                }
            }
            else
                Console.WriteLine("求解失败");
        }
	}
}

⌨️ 快捷键说明

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