📄 sample5_10.cs
字号:
/*
* 示例程序Sample5_10: NLEquations类的求非线性方程组最小二乘解的广义逆法
*/
using System;
using CSharpAlgorithm.Algorithm;
namespace CSharpAlgorithm.Sample
{
class Class1
{
// 建立NLEquation的子类,在其中重载函数func和funcMJ
class NLEq : NLEquations
{
protected override double Func(double[] x, double[] y)
{
y[0]=x[0]*x[0]+7.0*x[0]*x[1]+3.0*x[1]*x[1]+0.5;
y[1]=x[0]*x[0]-2.0*x[0]*x[1]+x[1]*x[1]-1.0;
y[2]=x[0]+x[1]+1.0;
return 0.0;
}
protected override void FuncMJ(double[] x, double[] p)
{
int n = x.Length;
p[0*n+0]=2.0*x[0]+7.0*x[1];
p[0*n+1]=7.0*x[0]+6.0*x[1];
p[1*n+0]=2.0*x[0]-2.0*x[1];
p[1*n+1]=-2.0*x[0]+2.0*x[1];
p[2*n+0]=1.0;
p[2*n+1]=1.0;
}
}
[STAThread]
static void Main(string[] args)
{
// 求解
NLEq nleq = new NLEq();
double eps1 = 0.000001;
double eps2 = 0.000001;
double[] x={1.0,-1.0};
int m=3;
int n=2;
if (nleq.GetRootsetGinv(m, n, x, eps1, eps2))
{
for (int i=0; i<n; ++i)
{
Console.WriteLine(x[i]);
}
}
else
Console.WriteLine("求解失败");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -