【发布时间】:2020-12-13 21:18:29
【问题描述】:
我正在尝试将 VBA 翻译为飞镖,但遇到了麻烦。我相信这与我如何实现我的 xxMap 和 wMap 有关。如何使用具有两个整数的键制作地图,然后如何使用它?我一直在尝试解决此问题,但无法弄清楚。我将非常感谢任何人可以为我提供的任何帮助!真心希望大家有个美好的一天!
这是 VBA 代码:
Public Function CBND(X As Double, y As Double, rho As Double) As Double
Dim i As Integer, ISs As Integer, LG As Integer, NG As Integer
Dim XX(10, 3) As Double, W(10, 3) As Double
Dim h As Double, k As Double, hk As Double, hs As Double, BVN As Double, Ass As Double, asr As Double, sn As Double
Dim A As Double, b As Double, bs As Double, c As Double, d As Double
Dim xs As Double, rs As Double
W(1, 1) = 0.17132449237917
XX(1, 1) = -0.932469514203152
W(2, 1) = 0.360761573048138
XX(2, 1) = -0.661209386466265
W(3, 1) = 0.46791393457269
XX(3, 1) = -0.238619186083197
W(1, 2) = 4.71753363865118E-02
XX(1, 2) = -0.981560634246719
W(2, 2) = 0.106939325995318
XX(2, 2) = -0.904117256370475
W(3, 2) = 0.160078328543346
XX(3, 2) = -0.769902674194305
W(4, 2) = 0.203167426723066
XX(4, 2) = -0.587317954286617
W(5, 2) = 0.233492536538355
XX(5, 2) = -0.36783149899818
W(6, 2) = 0.249147045813403
XX(6, 2) = -0.125233408511469
W(1, 3) = 1.76140071391521E-02
XX(1, 3) = -0.993128599185095
W(2, 3) = 4.06014298003869E-02
XX(2, 3) = -0.963971927277914
W(3, 3) = 6.26720483341091E-02
XX(3, 3) = -0.912234428251326
W(4, 3) = 8.32767415767048E-02
XX(4, 3) = -0.839116971822219
W(5, 3) = 0.10193011981724
XX(5, 3) = -0.746331906460151
W(6, 3) = 0.118194531961518
XX(6, 3) = -0.636053680726515
W(7, 3) = 0.131688638449177
XX(7, 3) = -0.510867001950827
W(8, 3) = 0.142096109318382
XX(8, 3) = -0.37370608871542
W(9, 3) = 0.149172986472604
XX(9, 3) = -0.227785851141645
W(10, 3) = 0.152753387130726
XX(10, 3) = -7.65265211334973E-02
If Abs(rho) < 0.3 Then
NG = 1
LG = 3
ElseIf Abs(rho) < 0.75 Then
NG = 2
LG = 6
Else
NG = 3
LG = 10
End If
h = -X
k = -y
hk = h * k
BVN = 0
If Abs(rho) < 0.925 Then
If Abs(rho) > 0 Then
hs = (h * h + k * k) / 2
asr = ArcSin(rho)
For i = 1 To LG
For ISs = -1 To 1 Step 2
sn = Sin(asr * (ISs * XX(i, NG) + 1) / 2)
BVN = BVN + W(i, NG) * Exp((sn * hk - hs) / (1 - sn * sn))
Next ISs
Next i
BVN = BVN * asr / (4 * Pi)
End If
BVN = BVN + CND(-h) * CND(-k)
Else
If rho < 0 Then
k = -k
hk = -hk
End If
If Abs(rho) < 1 Then
Ass = (1 - rho) * (1 + rho)
A = Sqr(Ass)
bs = (h - k) ^ 2
c = (4 - hk) / 8
d = (12 - hk) / 16
asr = -(bs / Ass + hk) / 2
If asr > -100 Then BVN = A * Exp(asr) * (1 - c * (bs - Ass) * (1 - d * bs / 5) / 3 + c * d * Ass * Ass / 5)
If -hk < 100 Then
b = Sqr(bs)
BVN = BVN - Exp(-hk / 2) * Sqr(2 * Pi) * CND(-b / A) * b * (1 - c * bs * (1 - d * bs / 5) / 3)
End If
A = A / 2
For i = 1 To LG
For ISs = -1 To 1 Step 2
xs = (A * (ISs * XX(i, NG) + 1)) ^ 2
rs = Sqr(1 - xs)
asr = -(bs / xs + hk) / 2
If asr > -100 Then
BVN = BVN + A * W(i, NG) * Exp(asr) * (Exp(-hk * (1 - rs) / (2 * (1 + rs))) / rs - (1 + c * xs * (1 + d * xs)))
End If
Next ISs
Next i
BVN = -BVN / (2 * Pi)
End If
If rho > 0 Then
BVN = BVN + CND(-Max(h, k))
Else
BVN = -BVN
If k > h Then BVN = BVN + CND(k) - CND(h)
End If
End If
CBND = BVN
End Function
这是我的飞镖/颤振翻译:
import 'dart:math';
double cbnd (double X, double y, double rho) {
int i;
int iss;
int lg;
int ng;
double h;
double k;
double hk;
double hs;
double bvn;
double ass;
double asr;
double sn;
double a;
double b;
double bs;
double c;
double d;
double xs;
double rs;
Map<List<int>, double> wMap = {
[1, 1] : 0.17132449237917,
[2, 1] : 0.360761573048138,
[3, 1] : 0.46791393457269,
[1, 2] : 0.0471753363865118,
[2, 2] : 0.106939325995318,
[3, 2] : 0.160078328543346,
[4, 2] : 0.203167426723066,
[5, 2] : 0.233492536538355,
[6, 2] : 0.249147045813403,
[1, 3] : 0.0176140071391521,
[2, 3] : 0.0406014298003869,
[3, 3] : 0.0626720483341091,
[4, 3] : 0.0832767415767048,
[5, 3] : 0.10193011981724,
[6, 3] : 0.118194531961518,
[7, 3] : 0.131688638449177,
[8, 3] : 0.142096109318382,
[9, 3] : 0.149172986472604,
[10, 3] : 0.152753387130726,
};
Map<List<int>, double> xxMap = {
[1, 1] : -0.932469514203152,
[2, 1] : -0.661209386466265,
[3, 1] : -0.238619186083197,
[1, 2] : -0.981560634246719,
[2, 2] : -0.904117256370475,
[3, 2] : -0.769902674194305,
[4, 2] : -0.587317954286617,
[5, 2] : -0.36783149899818,
[6, 2] : -0.125233408511469,
[1, 3] : -0.993128599185095,
[2, 3] : -0.963971927277914,
[3, 3] : -0.912234428251326,
[4, 3] : -0.839116971822219,
[5, 3] : -0.746331906460151,
[6, 3] : -0.636053680726515,
[7, 3] : -0.510867001950827,
[8, 3] : -0.37370608871542,
[9, 3] : -0.227785851141645,
[10, 3] : -0.0765265211334973,
};
if (rho.abs() < 0.3) {
ng = 1;
lg = 3;
}
else if (rho.abs() < 0.75) {
ng = 2;
lg = 6;
}
else {
ng = 3;
lg = 10;
}
h = -X;
k = -y;
hk = h * k;
bvn = 0;
if (rho.abs() < 0.925) {
if (rho.abs() > 0) {
hs = (h * h + k * k) / 2;
asr = arcSin(rho);
for(i = 1; i < lg; i++) {
for(iss = -1; iss < 1; iss+=2) {
sn = sin(asr * (iss * xxMap[[i,ng]] + 1) / 2);
bvn = bvn + wMap[[i,ng]] * exp((sn * hk - hs) / (1 - sn * sn));
}
}
bvn = bvn * asr / (4 * pi);
}
bvn = bvn + cnd(-h) * cnd(-k);
}
else{
if (rho < 0) {
k = -k;
hk = -hk;
}
if (rho.abs() < 1) {
ass = (1 - rho) * (1 + rho);
a = sqrt(ass);
bs = pow((h - k), 2);
c = (4 - hk) / 8;
d = (12 - hk) / 16;
asr = -(bs / ass + hk) / 2;
if (asr > -100) {
bvn = a * exp(asr) * (1 - c * (bs - ass)
* (1 - d * bs / 5) / 3 + c * d * ass * ass / 5);
if (-hk < 100) {
b = sqrt(bs);
bvn = bvn - exp(-hk / 2) * sqrt(2 * pi) * cnd(-b / a)
* b * (1 - c * bs * (1 - d * bs / 5) / 3);
}
a = a / 2;
for(i = 1; i < lg; i++) {
for (iss = -1; iss < 1; iss+=2) {
xs = pow(a * (iss * xxMap[{i, ng}] +1), 2);
rs = sqrt(1 - xs);
asr = -(bs / xs + hk) / 2;
if (asr > -100) {
bvn = bvn + a * wMap[{i, ng}] * exp(asr)
* (exp(-hk * (1 - rs) / (2 * (1 + rs))) / rs
- (1 + c * xs * (1 + d * xs)));
}
}
}
bvn = - bvn / (2 * pi);
}
if (rho > 0) {
bvn = bvn + cnd(-max(h, k));
}
else {
bvn = -bvn;
if (k > h) {
bvn = bvn + cnd(k) - cnd(h);
}
}
}
}
print(bvn);
return bvn;
}
这是错误代码:
Performing hot restart...
Syncing files to device Android SDK built for x86...
Restarted application in 135ms.
I/flutter ( 7281): 0.6033458857722407
I/flutter ( 7281): 0.396061477681382
I/flutter ( 7281): 9588.900336837181
I/flutter ( 7281): 0.6066215038705733
I/flutter ( 7281): 0.39322784023367435
I/flutter ( 7281): 21.675664402433934
I/flutter ( 7281): 0.5567942331117398
I/flutter ( 7281): 0.43911123505550037
I/flutter ( 7281): 11.019478064121111
I/flutter ( 7281): 0.6067721597663256
I/flutter ( 7281): 0.3933784961294267
I/flutter ( 7281): 0.2265553776778987
I/flutter ( 7281): 0.5708243206704915
I/flutter ( 7281): 0.4261760665459637
I/flutter ( 7281): 0.1594404921802129
I/flutter ( 7281): 0.5331974688940583
I/flutter ( 7281): 0.4606874160295979
I/flutter ( 7281): 207.2825189948513
I/flutter ( 7281): 0.9045568943023813
E/flutter ( 7281): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: The method '_mulFromInteger' was called on null.
E/flutter ( 7281): Receiver: null
E/flutter ( 7281): Tried calling: _mulFromInteger(-1)
E/flutter ( 7281): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
E/flutter ( 7281): #1 int.* (dart:core-patch/integers.dart:16:38)
E/flutter ( 7281): #2 cbnd (package:flutter_apptest/main.dart:280:31)
E/flutter ( 7281): #3 ksi (package:flutter_apptest/main.dart:92:47)
E/flutter ( 7281): #4 bsAmericanCallApprox2002 (package:flutter_apptest/main.dart:57:67)
E/flutter ( 7281): #5 bsAmericanApprox2002 (package:flutter_apptest/main.dart:12:13)
E/flutter ( 7281): #6 main (package:flutter_apptest/main.dart:4:18)
E/flutter ( 7281): #7 _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:231:25)
E/flutter ( 7281): #8 _rootRun (dart:async/zone.dart:1190:13)
E/flutter ( 7281): #9 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter ( 7281): #10 _runZoned (dart:async/zone.dart:1630:10)
E/flutter ( 7281): #11 runZonedGuarded (dart:async/zone.dart:1618:12)
E/flutter ( 7281): #12 _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:223:5)
E/flutter ( 7281): #13 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:301:19)
E/flutter ( 7281): #14 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
E/flutter ( 7281):
【问题讨论】: