方程式の出力の最小値と最大値を得るために.Netにビルトイン関数があるかどうか尋ねたいと思います。たとえば:方程式の出力範囲を取得する
float a,b,c,d,e,f,g;
float result() {
return a*b/c + d/(e-d) + f/g;
} //how to know the possible min and max value of result()?
私が知っているドメイン(A、B、C、D、Eの最小値と最大値、F、G、C、(編)、gが0ではない)、取得する方法result()の出力の範囲? これまでは、 figure: Output range of a function(< - 図を参照してください)のようなプリミティブネストループを手動で実行しようとしました。 しかし、私が望むのは、より高速な計算です(おそらく組み込み関数ですか?)。 そのイメージで結果を生成するコード:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TEST {
class Program {
static void Main(string[] args) {
ThreatRange();
Console.ReadLine();
}
static void ThreatRange() {
int a0 = 1, a1 = 10; // I know the min and max value for each variable
int b0 = 1, b1 = 10;
int c0 = 1, c1 = 10;
int d0 = 1, d1 = 10;
int e0 = 1, e1 = 10;
int f0 = 1, f1 = 10;
int g0 = 1, g1 = 10;
float threat = 0, threatmin = 9999, threatmax = 0;
for (int a = a0; a <= a1; a++) {
for (int b = b0; b <= b1; b++) {
for (int c = c0; c <= c1; c++) {
for (int d = d0; d <= d1; d++) {
for (int e = e0; e <= e1; e++) {
for (int f = f0; f <= f1; f++) {
for (int g = g0; g <= g1; g++) {
threat = a * b/(float)c + d/(float)Math.Max(1, Math.Abs(e - d)) + (d/(float)Math.Max(1, Math.Abs(e - d))) * (f/g);
// I want to know the min and max output from the equation above
if (threat < threatmin) threatmin = threat;
if (threat > threatmax) threatmax = threat;
Console.WriteLine(a + "," + b + "," + c + "," + d + "," + e + "," + f + "," + g);
Console.WriteLine("Min: " + threatmin + ". Max: " + threatmax);
}
}
}
}
}
}
}
}
}
}
恩赦私、私は間違ったキーワードを頼めば、私は英語のネイティブスピーカーじゃないも私の数学は良いです。あなたは私のC#以外の解決策を与えることができます任意のツールを知っている場合:( は、私に教えてください。
のためにもアルゴリズムが存在する場合、それはかなりの挑戦は、任意の関数の最小値と最大値を取得することに注意してくださいご利用くださいもあなたのコード。しかし、私はあなたが 'List'または 'array'を使うことができると信じています。 –
@MohitShrivastavaは、多くのパラメータを持つ方程式の最小値と最大値を知りたいとしましょう。多くのネストされたループを使うのではなく、より良い方法がありますか? –
はい..ネストされたループの代わりにLINQ ...を使用することができます。入力をリストまたは配列に入れた場合は使用できます。私はそれが1つまたは2つのライナーになると信じています。 –