?? sample5_10.cs
字號(hào):
/*
* 示例程序Sample5_10: NLEquations類的求非線性方程組最小二乘解的廣義逆法
*/
using System;
using CSharpAlgorithm.Algorithm;
namespace CSharpAlgorithm.Sample
{
class Class1
{
// 建立NLEquation的子類,在其中重載函數(shù)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("求解失敗");
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -