```julia
using PyPlot
using Dierckx
using PiecewiseInterpolation
```

Define function with first order discontinuity.
\begin{equation}
f(t) = \mathrm{e}^{-10|t|}
\end{equation}


```julia
f = t -> exp(-10abs(t))
t = linspace(-1, 1, 1000)
figure(figsize=(4, 3))
plot(t, f.(t))
times = collect(linspace(-1, 1, 30))
values = f.(times)
plot(times, values, "o", label="input data")
xlabel(L"t")
ylabel(L"f(t)")
```

Create naive and piecewise spline (with a single discontinuity at $t=0$):


```julia
ff = Spline1D(times, values, k=3)
p = PiecewiseSpline1D(times, values, [0.0])
;
```

Comparison of exact function, input data, and both interpolations.


```julia
figure(figsize=(4, 3))
plot(times, values, "o", label="input data")
new_times = linspace(-1, 1, 1001)
plot(new_times, f.(new_times), label="exact")
plot(new_times, ff.(new_times), label="naive")
plot(new_times, p.(new_times), "--", label="piecewise")
legend()
```

Absolute errors of both interpolations (vs exact function).


```julia
figure(figsize=(4, 3))
plot(new_times, ff.(new_times) - f.(new_times), label="naive")
plot(new_times, p.(new_times) - f.(new_times), label="piecewise")
ylabel("absolute error")
legend()
axhline(0.0, color="k", lw=0.5)
```

Relative errors of both interpolations (vs exact function).


```julia
figure(figsize=(4, 3))
plot(new_times, (ff.(new_times) - f.(new_times)) ./ f.(new_times), label="naive")
plot(new_times, (p.(new_times) - f.(new_times)) ./ f.(new_times), label="piecewise")
ylabel("relative error")
legend()
axhline(0.0, color="k", lw=0.5)
```


```julia

```

a15fba3cf970bd4718175675775121284f7dfd44
ipynb
Jupyter Notebook
demo.ipynb
gwater/PiecewiseInterpolation.jl
a1308f7d30b5c14caa2bb19c5d3e7b37a48b9e9c
MIT
2018-05-11T10:29:21.000Z
2018-05-11T10:29:21.000Z
demo.ipynb
gwater/PiecewiseInterpolation.jl
a1308f7d30b5c14caa2bb19c5d3e7b37a48b9e9c
MIT
demo.ipynb
gwater/PiecewiseInterpolation.jl
a1308f7d30b5c14caa2bb19c5d3e7b37a48b9e9c
MIT
2020-02-08T11:03:30.000Z
2020-02-08T11:03:30.000Z
Qwen/Qwen-72B
1. YES
2. YES