rgsl/types/
mathieu.rs

1//
2// A rust binding for the GSL library by Guillaume Gomez (guillaume1.gomez@gmail.com)
3//
4
5/*!
6The routines described in this section compute the angular and radial Mathieu functions, and their characteristic values. Mathieu functions are the solutions of the following two differential equations:
7
8d^2y/dv^2 + (a - 2q\cos 2v)y = 0
9
10d^2f/du^2 - (a - 2q\cosh 2u)f = 0
11
12The angular Mathieu functions ce_r(x,q), se_r(x,q) are the even and odd periodic solutions of the first equation, which is known as Mathieu’s equation. These exist only for the discrete sequence of characteristic values a=a_r(q) (even-periodic) and a=b_r(q) (odd-periodic).
13
14The radial Mathieu functions Mc^{(j)}_{r}(z,q), Ms^{(j)}_{r}(z,q) are the solutions of the second equation, which is referred to as Mathieu’s modified equation. The radial Mathieu functions of the first, second, third and fourth kind are denoted by the parameter j, which takes the value 1, 2, 3 or 4.
15
16For more information on the Mathieu functions, see Abramowitz and Stegun, Chapter 20.
17!*/
18
19use crate::{types, Value};
20use ffi::FFI;
21use std::mem::MaybeUninit;
22
23ffi_wrapper!(MathieuWorkspace, *mut sys::gsl_sf_mathieu_workspace, gsl_sf_mathieu_free,
24"The Mathieu functions can be computed for a single order or for multiple orders, using array-based
25routines. The array-based routines require a preallocated workspace.");
26
27impl MathieuWorkspace {
28    /// This function returns a workspace for the array versions of the Mathieu routines.
29    /// The arguments n and qmax specify the maximum order and q-value of Mathieu functions which can be computed with this workspace.
30    #[doc(alias = "gsl_sf_mathieu_alloc")]
31    pub fn new(n: usize, qmax: f64) -> Option<MathieuWorkspace> {
32        let tmp = unsafe { sys::gsl_sf_mathieu_alloc(n, qmax) };
33
34        if tmp.is_null() {
35            None
36        } else {
37            Some(Self::wrap(tmp))
38        }
39    }
40
41    /// This routine computes the characteristic values a_n(q), b_n(q) of the Mathieu functions ce_n(q,x) and se_n(q,x), respectively.
42    #[doc(alias = "gsl_sf_mathieu_a_e")]
43    pub fn mathieu_a(n: i32, q: f64) -> Result<types::Result, Value> {
44        let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
45        let ret = unsafe { sys::gsl_sf_mathieu_a_e(n, q, result.as_mut_ptr()) };
46
47        result_handler!(ret, unsafe { result.assume_init() }.into())
48    }
49
50    /// This routine computes the characteristic values a_n(q), b_n(q) of the Mathieu functions ce_n(q,x) and se_n(q,x), respectively.
51    #[doc(alias = "gsl_sf_mathieu_b_e")]
52    pub fn mathieu_b(n: i32, q: f64) -> Result<types::Result, Value> {
53        let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
54        let ret = unsafe { sys::gsl_sf_mathieu_b_e(n, q, result.as_mut_ptr()) };
55
56        result_handler!(ret, unsafe { result.assume_init() }.into())
57    }
58
59    /// This routine computes a series of Mathieu characteristic values a_n(q), b_n(q) for n from order_min to order_max inclusive, storing the results in the array result_array.
60    #[doc(alias = "gsl_sf_mathieu_a_array")]
61    pub fn mathieu_a_array(
62        &mut self,
63        order_min: i32,
64        order_max: i32,
65        q: f64,
66        result_array: &mut [f64],
67    ) -> Result<(), Value> {
68        let ret = unsafe {
69            sys::gsl_sf_mathieu_a_array(
70                order_min,
71                order_max,
72                q,
73                self.unwrap_unique(),
74                result_array.as_mut_ptr(),
75            )
76        };
77        result_handler!(ret, ())
78    }
79
80    /// This routine computes a series of Mathieu characteristic values a_n(q), b_n(q) for n from order_min to order_max inclusive, storing the results in the array result_array.
81    #[doc(alias = "gsl_sf_mathieu_b_array")]
82    pub fn mathieu_b_array(
83        &mut self,
84        order_min: i32,
85        order_max: i32,
86        q: f64,
87        result_array: &mut [f64],
88    ) -> Result<(), Value> {
89        let ret = unsafe {
90            sys::gsl_sf_mathieu_b_array(
91                order_min,
92                order_max,
93                q,
94                self.unwrap_unique(),
95                result_array.as_mut_ptr(),
96            )
97        };
98        result_handler!(ret, ())
99    }
100
101    /// This routine computes the angular Mathieu functions ce_n(q,x) and se_n(q,x), respectively.
102    #[doc(alias = "gsl_sf_mathieu_ce_e")]
103    pub fn mathieu_ce(n: i32, q: f64, x: f64) -> Result<types::Result, Value> {
104        let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
105        let ret = unsafe { sys::gsl_sf_mathieu_ce_e(n, q, x, result.as_mut_ptr()) };
106
107        result_handler!(ret, unsafe { result.assume_init() }.into())
108    }
109
110    /// This routine computes the angular Mathieu functions ce_n(q,x) and se_n(q,x), respectively.
111    #[doc(alias = "gsl_sf_mathieu_se_e")]
112    pub fn mathieu_se(n: i32, q: f64, x: f64) -> Result<types::Result, Value> {
113        let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
114        let ret = unsafe { sys::gsl_sf_mathieu_se_e(n, q, x, result.as_mut_ptr()) };
115
116        result_handler!(ret, unsafe { result.assume_init() }.into())
117    }
118
119    /// This routine computes a series of the angular Mathieu functions ce_n(q,x) and se_n(q,x) of order n from nmin to nmax inclusive, storing the results in the array result_array.
120    #[doc(alias = "gsl_sf_mathieu_ce_array")]
121    pub fn mathieu_ce_array(
122        &mut self,
123        nmin: i32,
124        nmax: i32,
125        q: f64,
126        x: f64,
127        result_array: &mut [f64],
128    ) -> Result<(), Value> {
129        let ret = unsafe {
130            sys::gsl_sf_mathieu_ce_array(
131                nmin,
132                nmax,
133                q,
134                x,
135                self.unwrap_unique(),
136                result_array.as_mut_ptr(),
137            )
138        };
139        result_handler!(ret, ())
140    }
141
142    /// This routine computes a series of the angular Mathieu functions ce_n(q,x) and se_n(q,x) of order n from nmin to nmax inclusive, storing the results in the array result_array.
143    #[doc(alias = "gsl_sf_mathieu_se_array")]
144    pub fn mathieu_se_array(
145        &mut self,
146        nmin: i32,
147        nmax: i32,
148        q: f64,
149        x: f64,
150        result_array: &mut [f64],
151    ) -> Result<(), Value> {
152        let ret = unsafe {
153            sys::gsl_sf_mathieu_se_array(
154                nmin,
155                nmax,
156                q,
157                x,
158                self.unwrap_unique(),
159                result_array.as_mut_ptr(),
160            )
161        };
162        result_handler!(ret, ())
163    }
164
165    /// This routine computes the radial j-th kind Mathieu functions Mc_n^{(j)}(q,x) and Ms_n^{(j)}(q,x) of order n.
166    ///
167    /// The allowed values of j are 1 and 2. The functions for j = 3,4 can be computed as M_n^{(3)} = M_n^{(1)} + iM_n^{(2)} and M_n^{(4)} = M_n^{(1)} - iM_n^{(2)}, where M_n^{(j)} = Mc_n^{(j)} or Ms_n^{(j)}.
168    #[doc(alias = "gsl_sf_mathieu_Mc_e")]
169    pub fn mathieu_Mc(j: i32, n: i32, q: f64, x: f64) -> Result<types::Result, Value> {
170        let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
171        let ret = unsafe { sys::gsl_sf_mathieu_Mc_e(j, n, q, x, result.as_mut_ptr()) };
172
173        result_handler!(ret, unsafe { result.assume_init() }.into())
174    }
175
176    /// This routine computes the radial j-th kind Mathieu functions Mc_n^{(j)}(q,x) and Ms_n^{(j)}(q,x) of order n.
177    ///
178    /// The allowed values of j are 1 and 2. The functions for j = 3,4 can be computed as M_n^{(3)} = M_n^{(1)} + iM_n^{(2)} and M_n^{(4)} = M_n^{(1)} - iM_n^{(2)}, where M_n^{(j)} = Mc_n^{(j)} or Ms_n^{(j)}.
179    #[doc(alias = "gsl_sf_mathieu_Ms_e")]
180    pub fn mathieu_Ms(j: i32, n: i32, q: f64, x: f64) -> Result<types::Result, Value> {
181        let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
182        let ret = unsafe { sys::gsl_sf_mathieu_Ms_e(j, n, q, x, result.as_mut_ptr()) };
183
184        result_handler!(ret, unsafe { result.assume_init() }.into())
185    }
186
187    /// This routine computes a series of the radial Mathieu functions of kind j, with order from nmin to nmax inclusive, storing the results in the array result_array.
188    #[doc(alias = "gsl_sf_mathieu_Mc_array")]
189    pub fn mathieu_Mc_array(
190        &mut self,
191        j: i32,
192        nmin: i32,
193        nmax: i32,
194        q: f64,
195        x: f64,
196        result_array: &mut [f64],
197    ) -> Result<(), Value> {
198        let ret = unsafe {
199            sys::gsl_sf_mathieu_Mc_array(
200                j,
201                nmin,
202                nmax,
203                q,
204                x,
205                self.unwrap_unique(),
206                result_array.as_mut_ptr(),
207            )
208        };
209        result_handler!(ret, ())
210    }
211
212    /// This routine computes a series of the radial Mathieu functions of kind j, with order from nmin to nmax inclusive, storing the results in the array result_array.
213    #[doc(alias = "gsl_sf_mathieu_Ms_array")]
214    pub fn mathieu_Ms_array(
215        &mut self,
216        j: i32,
217        nmin: i32,
218        nmax: i32,
219        q: f64,
220        x: f64,
221        result_array: &mut [f64],
222    ) -> Result<(), Value> {
223        let ret = unsafe {
224            sys::gsl_sf_mathieu_Ms_array(
225                j,
226                nmin,
227                nmax,
228                q,
229                x,
230                self.unwrap_unique(),
231                result_array.as_mut_ptr(),
232            )
233        };
234        result_handler!(ret, ())
235    }
236}