标题: VB中定义Arccos函数 [打印本页] 作者: 游侠无极限 时间: 2003-4-18 01:11 标题: VB中定义Arccos函数 我是这样的: 3 J7 y& [: k! _9 j: R+ xPrivate Function Arccos(x As Double, n As Long). }4 v% b5 d! u f, r3 Z
Dim i As Long, y As Double * q4 Q% \5 F {, }; h$ SFor i = 1 To n * G% G% q! k6 g y = y + (-1 / Sqr(1 + (x / n * i) ^ 2)) * x / n 0 B# P; E* W7 y* d: h' P8 y7 \Next, ~' H/ F( N2 u7 x' F- g- K
Arccos = y * X6 F' u7 ?# u- t/ D( P6 [End Function: S, m5 M; Y- Q5 Z
+ c6 x; E2 l+ X8 @6 B! t
用的是Arccos的微分来算近似值,怎么不对? ' [+ r2 ]! r( Z. d; z作者: 煎饼 时间: 2003-4-19 22:04
公式对就没有问题拉作者: 游侠无极限 时间: 2003-4-24 22:58
Const pi As Double = 3.14159265359; Z% p6 Z. f9 O4 Y9 X, c- e, }" Q
Private Function Arccos(x As Double, n As Long) ' n 为函数精度,建议为100 - g- n6 y) j( E+ V" b Select Case x 3 @. B3 _" |8 S Case 1, h5 \ l! B; F
Arccos = 0 : ~9 D6 R; a# g5 ^- z( s& s Case -1! s$ k( o6 s5 r& R- p9 l" D8 M
Arccos = pi+ s6 f( s; H8 n) L @* H; A% z
Case -1 To 11 z2 ~7 r& ?% e7 p9 b( c
Dim dx As Double, y As Double, i As Long 0 K# |' V' @" ~! R0 C dx = x / n# z+ @3 ^3 B3 |# x }7 G+ L3 G
For i = 1 To n& U8 F( I. t, n# @+ w( ^/ {
y = y + (-1 / Sqr(1 - (dx * i + dx / 2) ^ 2)) * dx , L) g* f+ {; S F7 E Next . ?& P" N# f7 w+ d4 k* H c Arccos = y + pi / 2- j3 K/ e9 n& Y& M/ ]" G# W3 D% h' Z ^
Case Else . l/ P: ?3 `1 B" W! M '异常 + x3 x! q% R0 x End Select % {" X8 w" W; V( z% O8 S8 }End Function $ {. D9 b& z% \ 3 I5 V- C1 }( ?搞定了