22
22
23
23
const VFun{S,T} = Fun{S,T,Vector{T}}
24
24
25
+ """
26
+ Fun(s::Space, coefficients::AbstractVector)
27
+
28
+ Return a `Fun` with the specified `coefficients` in the space `s`
29
+
30
+ # Examples
31
+ ```jldoctest
32
+ julia> f = Fun(Fourier(), [1,1]);
33
+
34
+ julia> f(0.1) == 1 + sin(0.1)
35
+ true
36
+
37
+ julia> f = Fun(Chebyshev(), [1,1]);
38
+
39
+ julia> f(0.1) == 1 + 0.1
40
+ true
41
+ ```
42
+ """
25
43
Fun (sp:: Space ,coeff:: AbstractVector ) = Fun {typeof(sp),eltype(coeff),typeof(coeff)} (sp,coeff)
44
+
45
+ """
46
+ Fun()
47
+
48
+ Return `Fun(identity, Chebyshev())`, which represents the identity function in `-1..1`.
49
+
50
+ # Examples
51
+ ```jldoctest
52
+ julia> f = Fun(Chebyshev())
53
+ Fun(Chebyshev(), [0.0, 1.0])
54
+
55
+ julia> f(0.1)
56
+ 0.1
57
+ ```
58
+ """
26
59
Fun () = Fun (identity, ChebyshevInterval ())
27
60
Fun (d:: Domain ) = Fun (identity,d)
61
+
62
+ """
63
+ Fun(s::Space)
64
+
65
+ Return `Fun(identity, s)`
66
+
67
+ # Examples
68
+ ```jldoctest
69
+ julia> x = Fun(Chebyshev())
70
+ Fun(Chebyshev(), [0.0, 1.0])
71
+
72
+ julia> x(0.1)
73
+ 0.1
74
+ ```
75
+ """
28
76
Fun (d:: Space ) = Fun (identity,d)
29
77
30
78
@@ -44,6 +92,20 @@ hasnumargs(f::Fun,k) = k == 1 || domaindimension(f) == k # all funs take a sing
44
92
# #Coefficient routines
45
93
# TODO : domainscompatible?
46
94
95
+ """
96
+ coefficients(f::Fun, s::Space) -> Vector
97
+
98
+ Return the coefficients of `f` in the space `s`, which
99
+ may not be the same as `space(f)`.
100
+
101
+ # Examples
102
+ ```jldoctest
103
+ julia> f = Fun(x->(3x^2-1)/2);
104
+
105
+ julia> coefficients(f, Legendre()) ≈ [0, 0, 1]
106
+ true
107
+ ```
108
+ """
47
109
function coefficients (f:: Fun ,msp:: Space )
48
110
# zero can always be converted
49
111
fc = f. coefficients
@@ -54,6 +116,24 @@ function coefficients(f::Fun,msp::Space)
54
116
end
55
117
end
56
118
coefficients (f:: Fun ,:: Type{T} ) where {T<: Space } = coefficients (f,T (domain (f)))
119
+
120
+ """
121
+ coefficients(f::Fun) -> Vector
122
+
123
+ Return the coefficients of `f`, corresponding to the space `space(f)`.
124
+
125
+ # Examples
126
+ ```jldoctest
127
+ julia> f = Fun(x->x^2)
128
+ Fun(Chebyshev(), [0.5, 0.0, 0.5])
129
+
130
+ julia> coefficients(f)
131
+ 3-element Vector{Float64}:
132
+ 0.5
133
+ 0.0
134
+ 0.5
135
+ ```
136
+ """
57
137
coefficients (f:: Fun ) = f. coefficients
58
138
coefficients (c:: Number ,sp:: Space ) = Fun (c,sp). coefficients
59
139
@@ -178,11 +258,45 @@ setspace(f::Fun,s::Space) = Fun(s,f.coefficients)
178
258
179
259
# # General routines
180
260
261
+ """
262
+ domain(f::Fun)
181
263
264
+ Return the domain that `f` is defined on.
265
+
266
+ # Examples
267
+ ```jldoctest
268
+ julia> f = Fun(x->x^2);
269
+
270
+ julia> domain(f)
271
+ -1.0..1.0 (Chebyshev)
272
+
273
+ julia> f = Fun(x->x^2, 0..1);
274
+
275
+ julia> domain(f)
276
+ 0..1
277
+ ```
278
+ """
182
279
domain (f:: Fun ) = domain (f. space)
183
280
domain (v:: AbstractMatrix{T} ) where {T<: Fun } = map (domain,v)
184
281
domaindimension (f:: Fun ) = domaindimension (f. space)
185
282
283
+ """
284
+ setdomain(f::Fun, d::Domain)
285
+
286
+ Return `f` projected onto `domain`.
287
+
288
+ !!! note
289
+ The new function may differ from the original one, as the coefficients are left unchanged.
290
+
291
+ # Examples
292
+ ```jldoctest
293
+ julia> f = Fun(x->x^2)
294
+ Fun(Chebyshev(), [0.5, 0.0, 0.5])
295
+
296
+ julia> setdomain(f, 0..1)
297
+ Fun(Chebyshev(0..1), [0.5, 0.0, 0.5])
298
+ ```
299
+ """
186
300
setdomain (f:: Fun ,d:: Domain ) = Fun (setdomain (space (f),d),f. coefficients)
187
301
188
302
for op in (:tocanonical ,:tocanonicalD ,:fromcanonical ,:fromcanonicalD ,:invfromcanonicalD )
@@ -197,6 +311,20 @@ for op in (:fromcanonical,:fromcanonicalD,:invfromcanonicalD)
197
311
end
198
312
199
313
314
+ """
315
+ space(f::Fun)
316
+
317
+ Return the space of `f`.
318
+
319
+ # Examples
320
+ ```jldoctest
321
+ julia> f = Fun(x->x^2)
322
+ Fun(Chebyshev(), [0.5, 0.0, 0.5])
323
+
324
+ julia> space(f)
325
+ Chebyshev()
326
+ ```
327
+ """
200
328
space (f:: Fun ) = f. space
201
329
spacescompatible (f:: Fun ,g:: Fun ) = spacescompatible (space (f),space (g))
202
330
pointscompatible (f:: Fun ,g:: Fun ) = pointscompatible (space (f),space (g))
@@ -206,6 +334,14 @@ canonicaldomain(f::Fun) = canonicaldomain(space(f))
206
334
207
335
# #Evaluation
208
336
337
+ """
338
+ evaluate(coefficients::AbstractVector, sp::Space, x)
339
+
340
+ Evaluate the expansion at a point `x` that lies in `domain(sp)`.
341
+ If `x` is not in the domain, the returned value will depend on the space,
342
+ and should not be relied upon. See [`extrapolate`](@ref) to evaluate a function
343
+ at a value outside the domain.
344
+ """
209
345
function evaluate (f:: AbstractVector ,S:: Space ,x... )
210
346
csp= canonicalspace (S)
211
347
if spacescompatible (csp,S)
@@ -236,21 +372,94 @@ end
236
372
extrapolate (f:: AbstractVector ,S:: Space ,x... ) = evaluate (f,S,x... )
237
373
238
374
# Do not override these
375
+ """
376
+ extrapolate(f::Fun,x)
377
+
378
+ Return an extrapolation of `f` from its domain to `x`.
379
+
380
+ # Examples
381
+ ```jldoctest
382
+ julia> f = Fun(x->x^2)
383
+ Fun(Chebyshev(), [0.5, 0.0, 0.5])
384
+
385
+ julia> domain(f)
386
+ -1.0..1.0 (Chebyshev)
387
+
388
+ julia> extrapolate(f, 2)
389
+ 4.0
390
+ ```
391
+ """
239
392
extrapolate (f:: Fun ,x) = extrapolate (f. coefficients,f. space,x)
240
393
extrapolate (f:: Fun ,x,y,z... ) = extrapolate (f. coefficients,f. space,Vec (x,y,z... ))
241
394
242
395
243
396
# #Data routines
244
397
398
+ """
399
+ values(f::Fun)
400
+
401
+ Return `f` evaluated at `points(f)`.
402
+
403
+ # Examples
404
+ ```jldoctest
405
+ julia> f = Fun(x->x^2)
406
+ Fun(Chebyshev(), [0.5, 0.0, 0.5])
407
+
408
+ julia> values(f)
409
+ 3-element Vector{Float64}:
410
+ 0.75
411
+ 0.0
412
+ 0.75
245
413
414
+ julia> map(x->x^2, points(f)) ≈ values(f)
415
+ true
416
+ ```
417
+ """
246
418
values (f:: Fun ,dat... ) = _values (f. space, f. coefficients, dat... )
247
419
_values (sp, v, dat... ) = itransform (sp, v, dat... )
248
420
_values (sp:: UnivariateSpace , v:: Vector{T} , dat... ) where {T<: Number } =
249
421
itransform (sp, v, dat... ):: Vector{float(T)}
422
+ """
423
+ points(f::Fun)
424
+
425
+ Return a grid of points that `f` can be transformed into values
426
+ and back.
427
+
428
+ # Examples
429
+ ```jldoctest
430
+ julia> f = Fun(x->x^2);
431
+
432
+ julia> chebypts(n) = [cos((2i+1)pi/2n) for i in 0:n-1];
433
+
434
+ julia> points(f) ≈ chebypts(ncoefficients(f))
435
+ true
436
+ ```
437
+ """
250
438
points (f:: Fun ) = points (f. space,ncoefficients (f))
439
+
440
+ """
441
+ ncoefficients(f::Fun) -> Integer
442
+
443
+ Return the number of coefficients of a fun
444
+
445
+ # Examples
446
+ ```jldoctest
447
+ julia> f = Fun(x->x^2)
448
+ Fun(Chebyshev(), [0.5, 0.0, 0.5])
449
+
450
+ julia> ncoefficients(f)
451
+ 3
452
+ ```
453
+ """
251
454
ncoefficients (f:: Fun ):: Int = length (f. coefficients)
455
+
252
456
blocksize (f:: Fun ) = (block (space (f),ncoefficients (f)). n[1 ],)
253
457
458
+ """
459
+ stride(f::Fun)
460
+
461
+ Return the stride of the coefficients, checked numerically
462
+ """
254
463
function stride (f:: Fun )
255
464
# Check only for stride 2 at the moment
256
465
# as higher stride is very rare anyways
@@ -286,6 +495,20 @@ function chop!(f::Fun,tol...)
286
495
f
287
496
end
288
497
498
+ """
499
+ chop(f::Fun[, tol = 10eps()]) -> Fun
500
+
501
+ Reduce the number of coefficients by dropping the tail that is below the specified tolerance.
502
+
503
+ # Examples
504
+ ```jldoctest
505
+ julia> f = Fun(Chebyshev(), [1,2,3,0,0,0])
506
+ Fun(Chebyshev(), [1, 2, 3, 0, 0, 0])
507
+
508
+ julia> chop(f)
509
+ Fun(Chebyshev(), [1, 2, 3])
510
+ ```
511
+ """
289
512
chop (f:: Fun ,tol... ) = chop! (Fun (f. space,Vector (f. coefficients)),tol... )
290
513
291
514
copy (f:: Fun ) = Fun (space (f),copy (f. coefficients))
@@ -548,7 +771,11 @@ iszero(f::Fun) = all(iszero,f.coefficients)
548
771
549
772
# sum, integrate, and idfferentiate are in CalculusOperator
550
773
774
+ """
775
+ reverseorientation(f::Fun)
551
776
777
+ Return `f` on a reversed orientated contour.
778
+ """
552
779
function reverseorientation (f:: Fun )
553
780
csp= canonicalspace (f)
554
781
if spacescompatible (csp,space (f))
0 commit comments