Skip to content

Commit 659385c

Browse files
committed
Update README
1 parent 50b5408 commit 659385c

File tree

4 files changed

+26
-35
lines changed

4 files changed

+26
-35
lines changed

README.md

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ h = f + g^2
3636
r = roots(h)
3737
rp = roots(h')
3838

39-
using Plots
40-
plot(h)
41-
scatter!(r,h.(r))
42-
scatter!(rp,h.(rp))
39+
plot(h; label="f + g^2")
40+
scatter!(r, h.(r); label="roots")
41+
scatter!(rp, h.(rp); label="extrema")
4342
```
4443

4544
<img src=https://github.com/JuliaApproximation/ApproxFun.jl/raw/master/images/extrema.png width=500 height=400>
@@ -54,15 +53,15 @@ derivative, the `norm` is small:
5453

5554
```julia
5655
f = Fun(x->exp(x), -1..1)
57-
norm(f-f')
56+
norm(f-f') # 4.4391656415701095e-14
5857
```
5958

6059
Similarly, `cumsum` defines an indefinite integration operator:
6160

6261
```julia
6362
g = cumsum(f)
6463
g = g + f(-1)
65-
norm(f-g)
64+
norm(f-g) # 3.4989733283850415e-15d
6665
```
6766

6867
Algebraic and differential operations are also implemented where possible, and most of Julia's built-in functions are overridden to accept `Fun`s:
@@ -78,17 +77,15 @@ h = airyai(10asin(f)+2g)
7877
## Solving ordinary differential equations
7978

8079

81-
Solve the Airy ODE `u'' - x u = 0` as a BVP on `[-1000,200]`:
80+
We can also solve differential equations. Consider the Airy ODE `u'' - x u = 0` as a boundary value problem on `[-1000,200]` with conditions `u(-1000) = 1` and `u(200) = 2`. The unique solution is a linear combination of Airy functions. We can calculate it as follows:
8281

8382
```julia
84-
a,b = -1000,200
85-
x = Fun(identity, a..b)
86-
d = domain(x)
87-
D = Derivative(d)
88-
B = Dirichlet(d)
89-
L = D^2 - x
90-
u = [B;L] \ [[airyai(a),airyai(b)],0]
91-
plot(u)
83+
x = Fun(identity, -1000..200) # the function x on the interval -1000..200
84+
D = Derivative() # The derivative operator
85+
B = Dirichlet() # Dirichlet conditions
86+
L = D^2 - x # the Airy operator
87+
u = [B;L] \ [[1,2],0] # Calculate u such that B*u == [1,2] and L*u == 0
88+
plot(u; label="u")
9289
```
9390

9491
<img src=https://github.com/JuliaApproximation/ApproxFun.jl/raw/master/images/airy.png width=500 height=400>
@@ -100,10 +97,9 @@ Solve a nonlinear boundary value problem satisfying the ODE `0.001u'' + 6*(1-x^2
10097

10198
```julia
10299
x = Fun()
103-
u₀ = 0.0x
104-
100+
u₀ = 0.0x # initial guess
105101
N = u -> [u(-1)-1, u(1)+0.5, 0.001u'' + 6*(1-x^2)*u' + u^2 - 1]
106-
u = newton(N,u0)
102+
u = newton(N, u₀) # perform Newton iteration in function space
107103
plot(u)
108104
```
109105

@@ -112,22 +108,18 @@ plot(u)
112108
One can also solve a system nonlinear ODEs with potentially nonlinear boundary conditions:
113109

114110
```julia
115-
function nonlinear_test()
116-
x=Fun(Chebyshev(0..1))
117-
N = (u1,u2) -> [u1'(0) - 0.5*u1(0)*u2(0);
118-
u2'(0) + 1;
119-
u1(1) - 1;
120-
u2(1) - 1;
121-
u1'' + u1*u2;
122-
u2'' - u1*u2]
123-
124-
u10 = one(x)
125-
u20 = one(x)
126-
127-
return newton(N, [u10,u20])
128-
end
129111

130-
u1,u2 = nonlinear_test()
112+
x=Fun(identity, 0..1)
113+
N = (u1,u2) -> [u1'(0) - 0.5*u1(0)*u2(0);
114+
u2'(0) + 1;
115+
u1(1) - 1;
116+
u2(1) - 1;
117+
u1'' + u1*u2;
118+
u2'' - u1*u2]
119+
120+
u10 = one(x)
121+
u20 = one(x)
122+
u1,u2 = newton(N, [u10,u20])
131123

132124
plot(u1, label="u1")
133125
plot!(u2, label="u2")
@@ -144,7 +136,7 @@ Specify the space `Fourier` to ensure that the representation is periodic:
144136

145137
```julia
146138
f = Fun(cos, Fourier(-π..π))
147-
norm(f' + Fun(sin, Fourier(-π..π))
139+
norm(f' + Fun(sin, Fourier(-π..π))) # 5.923502902288505e-17
148140
```
149141

150142
Due to the periodicity, Fourier representations allow for the asymptotic savings of `2/π`

images/airy.png

-37.8 KB
Loading

images/extrema.png

-116 KB
Loading

test/ReadmeTest.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ using ApproxFun, SpecialFunctions, LinearAlgebra, Test
77
f = sin(x^2)
88
g = cos(x)
99

10-
1110
@test (f(.1),sin(.1^2);atol=1000eps())
1211

1312
h = f + g^2

0 commit comments

Comments
 (0)