1 | #Region "Microsoft.VisualBasic::1d47559d4e0a99ff810db30f73ca7409, Microsoft.VisualBasic.Core\Extensions\Math\Trigonometric\Trigonometric2.vb" |
2 | |
3 | ' Author: |
4 | ' |
5 | ' asuka (amethyst.asuka@gcmodeller.org) |
6 | ' xie (genetics@smrucc.org) |
7 | ' xieguigang (xie.guigang@live.com) |
8 | ' |
9 | ' Copyright (c) 2018 GPL3 Licensed |
10 | ' |
11 | ' |
12 | ' GNU GENERAL PUBLIC LICENSE (GPL3) |
13 | ' |
14 | ' |
15 | ' This program is free software: you can redistribute it and/or modify |
16 | ' it under the terms of the GNU General Public License as published by |
17 | ' the Free Software Foundation, either version 3 of the License, or |
18 | ' (at your option) any later version. |
19 | ' |
20 | ' This program is distributed in the hope that it will be useful, |
21 | ' but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23 | ' GNU General Public License for more details. |
24 | ' |
25 | ' You should have received a copy of the GNU General Public License |
26 | ' along with this program. If not, see <http://www.gnu.org/licenses/>. |
27 | |
28 | |
29 | |
30 | ' /********************************************************************************/ |
31 | |
32 | ' Summaries: |
33 | |
34 | ' Module Trigonometric |
35 | ' |
36 | ' Function: Arccos, Arccosec, Arccotan, Arcsec, Arcsin |
37 | ' Cosec, Cotan, HArccos, HArccosec, HArccotan |
38 | ' HArcsec, HArcsin, Harctan, HCos, HCosec |
39 | ' HCotan, HSec, HSin, HTan, Sec |
40 | ' |
41 | ' |
42 | ' /********************************************************************************/ |
43 | |
44 | #End Region |
45 | |
46 | Imports sys = System.Math |
47 | |
48 | Namespace Math |
49 | |
50 | Partial Module Trigonometric |
51 | |
52 | ''' <summary> |
53 | ''' Secant(正割) ``Sec(X) = 1 / Cos(X)`` |
54 | ''' </summary> |
55 | ''' <param name="x"></param> |
56 | ''' <returns></returns> |
57 | Public Function Sec(x As Double) As Double |
58 | Return 1 / sys.Cos(x) |
59 | End Function |
60 | |
61 | ''' <summary> |
62 | ''' Cosecant(余割) ``Cosec(X) = 1 / Sin(X)`` |
63 | ''' </summary> |
64 | ''' <param name="x"></param> |
65 | ''' <returns></returns> |
66 | Public Function Cosec(x As Double) As Double |
67 | Return 1 / sys.Sin(x) |
68 | End Function |
69 | |
70 | ''' <summary> |
71 | ''' Cotangent(余切) ``Cotan(X) = 1 / Tan(X)`` |
72 | ''' </summary> |
73 | ''' <param name="x"></param> |
74 | ''' <returns></returns> |
75 | Public Function Cotan(x As Double) As Double |
76 | Return 1 / sys.Tan(x) |
77 | End Function |
78 | |
79 | ''' <summary> |
80 | ''' Inverse Sine(反正弦) ``Arcsin(X) = Atn(X / Sqr(-X * X + 1))`` |
81 | ''' </summary> |
82 | ''' <param name="x"></param> |
83 | ''' <returns></returns> |
84 | Public Function Arcsin(x As Double) As Double |
85 | Return Atn(x / sys.Sqrt(-x * x + 1)) |
86 | End Function |
87 | |
88 | ''' <summary> |
89 | ''' Inverse Cosine(反余弦) ``Arccos(X) = Atn(-X / Sqr(-X * X + 1)) + 2 * Atn(1)`` |
90 | ''' </summary> |
91 | ''' <param name="x"></param> |
92 | ''' <returns></returns> |
93 | Public Function Arccos(x As Double) As Double |
94 | Return Atn(-x / sys.Sqrt(-x * x + 1)) + 2 * Atn(1) |
95 | End Function |
96 | |
97 | ''' <summary> |
98 | ''' Inverse Secant(反正割) ``Arcsec(X) = Atn(X / Sqr(X * X - 1)) + Sgn((X) - 1) * (2 * Atn(1))`` |
99 | ''' </summary> |
100 | ''' <param name="x"></param> |
101 | ''' <returns></returns> |
102 | Public Function Arcsec(x As Double) As Double |
103 | Return Atn(x / sys.Sqrt(x * x - 1)) + sys.Sign((x) - 1) * (2 * Atn(1)) |
104 | End Function |
105 | |
106 | ''' <summary> |
107 | ''' Inverse Cosecant(反余割) ``Arccosec(X) = Atn(X / Sqr(X * X - 1)) + (Sgn(X) - 1) * (2 * Atn(1))`` |
108 | ''' </summary> |
109 | ''' <param name="x"></param> |
110 | ''' <returns></returns> |
111 | Public Function Arccosec(x As Double) As Double |
112 | Return Atn(x / sys.Sqrt(x * x - 1)) + (sys.Sign(x) - 1) * (2 * Atn(1)) |
113 | End Function |
114 | |
115 | ''' <summary> |
116 | ''' Inverse Cotangent(反余切) ``Arccotan(X) = Atn(X) + 2 * Atn(1)`` |
117 | ''' </summary> |
118 | ''' <param name="x"></param> |
119 | ''' <returns></returns> |
120 | Public Function Arccotan(x As Double) As Double |
121 | Return Atn(x) + 2 * Atn(1) |
122 | End Function |
123 | |
124 | ''' <summary> |
125 | ''' Hyperbolic Sine(双曲正弦) ``HSin(X) = (Exp(X) - Exp(-X)) / 2`` |
126 | ''' </summary> |
127 | ''' <param name="x"></param> |
128 | ''' <returns></returns> |
129 | Public Function HSin(x As Double) As Double |
130 | Return (sys.Exp(x) - sys.Exp(-x)) / 2 |
131 | End Function |
132 | |
133 | ''' <summary> |
134 | ''' Hyperbolic Cosine(双曲余弦) ``HCos(X) = (Exp(X) + Exp(-X)) / 2`` |
135 | ''' </summary> |
136 | ''' <param name="x"></param> |
137 | ''' <returns></returns> |
138 | Public Function HCos(x As Double) As Double |
139 | Return (sys.Exp(x) + sys.Exp(-x)) / 2 |
140 | End Function |
141 | |
142 | ''' <summary> |
143 | ''' Hyperbolic Tangent(双曲正切) ``HTan(X) = (Exp(X) - Exp(-X)) / (Exp(X) + Exp(-X))`` |
144 | ''' </summary> |
145 | ''' <param name="x"></param> |
146 | ''' <returns></returns> |
147 | Public Function HTan(x As Double) As Double |
148 | Return (sys.Exp(x) - sys.Exp(-x)) / (sys.Exp(x) + sys.Exp(-x)) |
149 | End Function |
150 | |
151 | ''' <summary> |
152 | ''' Hyperbolic Secant(双曲正割) ``HSec(X) = 2 / (Exp(X) + Exp(-X))`` |
153 | ''' </summary> |
154 | ''' <param name="x"></param> |
155 | ''' <returns></returns> |
156 | Public Function HSec(x As Double) As Double |
157 | Return 2 / (sys.Exp(x) + sys.Exp(-x)) |
158 | End Function |
159 | |
160 | ''' <summary> |
161 | ''' Hyperbolic Cosecant(双曲余割) ``HCosec(X) = 2 / (Exp(X) - Exp(-X))`` |
162 | ''' </summary> |
163 | ''' <param name="x"></param> |
164 | ''' <returns></returns> |
165 | Public Function HCosec(x As Double) As Double |
166 | Return 2 / (sys.Exp(x) - sys.Exp(-x)) |
167 | End Function |
168 | |
169 | ''' <summary> |
170 | ''' Hyperbolic Cotangent(双曲余切) ``HCotan(X) = (Exp(X) + Exp(-X)) / (Exp(X) - Exp(-X))`` |
171 | ''' </summary> |
172 | ''' <param name="x"></param> |
173 | ''' <returns></returns> |
174 | Public Function HCotan(x As Double) As Double |
175 | Return (sys.Exp(x) + sys.Exp(-x)) / (sys.Exp(x) - sys.Exp(-x)) |
176 | End Function |
177 | |
178 | ''' <summary> |
179 | ''' Inverse Hyperbolic Sine(反双曲正弦) ``HArcsin(X) = Log(X + Sqr(X * X + 1))`` |
180 | ''' </summary> |
181 | ''' <param name="x"></param> |
182 | ''' <returns></returns> |
183 | Public Function HArcsin(x As Double) As Double |
184 | Return sys.Log(x + sys.Sqrt(x * x + 1)) |
185 | End Function |
186 | |
187 | ''' <summary> |
188 | ''' Inverse Hyperbolic Cosine(反双曲余弦) ``HArccos(X) = Log(X + Sqr(X * X - 1))`` |
189 | ''' </summary> |
190 | ''' <param name="x"></param> |
191 | ''' <returns></returns> |
192 | Public Function HArccos(x As Double) As Double |
193 | Return sys.Log(x + sys.Sqrt(x * x - 1)) |
194 | End Function |
195 | |
196 | ''' <summary> |
197 | ''' Inverse Hyperbolic Tangent(反双曲正切) ``HArctan(X) = Log((1 + X) / (1 - X)) / 2`` |
198 | ''' </summary> |
199 | ''' <param name="x"></param> |
200 | ''' <returns></returns> |
201 | Public Function Harctan(x As Double) As Double |
202 | Return sys.Log((1 + x) / (1 - x)) / 2 |
203 | End Function |
204 | |
205 | ''' <summary> |
206 | ''' Inverse Hyperbolic Secant(反双曲正割) ``HArcsec(X) = Log((Sqr(-X * X + 1) + 1) / X)`` |
207 | ''' </summary> |
208 | ''' <param name="x"></param> |
209 | ''' <returns></returns> |
210 | Public Function HArcsec(x As Double) As Double |
211 | Return sys.Log((sys.Sqrt(-x * x + 1) + 1) / x) |
212 | End Function |
213 | |
214 | ''' <summary> |
215 | ''' Inverse Hyperbolic Cosecant(反双曲余割) ``HArccosec(X) = Log((Sgn(X) * Sqr(X * X + 1) + 1) / X)`` |
216 | ''' </summary> |
217 | ''' <param name="x"></param> |
218 | ''' <returns></returns> |
219 | Public Function HArccosec(x As Double) As Double |
220 | Return sys.Log((sys.Sign(x) * sys.Sqrt(x * x + 1) + 1) / x) |
221 | End Function |
222 | |
223 | ''' <summary> |
224 | ''' Inverse Hyperbolic Cotangent(反双曲余切) ``HArccotan(X) = Log((X + 1) / (X - 1)) / 2`` |
225 | ''' </summary> |
226 | ''' <param name="x"></param> |
227 | ''' <returns></returns> |
228 | Public Function HArccotan(x As Double) As Double |
229 | Return sys.Log((x + 1) / (x - 1)) / 2 |
230 | End Function |
231 | End Module |
232 | End Namespace |