From ec69ee6f29da4b3617f2d4108b06c106eae7ed14 Mon Sep 17 00:00:00 2001 From: "Documenter.jl" Date: Tue, 17 Oct 2023 10:28:27 +0000 Subject: [PATCH] build based on 4ee50d0 --- dev/.documenter-siteinfo.json | 2 +- dev/index.html | 6 +- dev/interface/index.html | 2 +- dev/methods/{35055978.svg => 03781d90.svg} | 78 ++-- dev/methods/{26f02551.svg => 2ec976a5.svg} | 82 ++-- dev/methods/{b088b4b5.svg => 2f3ebce7.svg} | 468 ++++++++++----------- dev/methods/{43f8af8c.svg => 3a7d3077.svg} | 82 ++-- dev/methods/{3498931a.svg => 47587af6.svg} | 262 ++++++------ dev/methods/{60c73e3c.svg => 5b65bccf.svg} | 96 ++--- dev/methods/{d8d65d27.svg => 8f57f05e.svg} | 86 ++-- dev/methods/{7d713435.svg => aaa6e30b.svg} | 86 ++-- dev/methods/{6e2c9c33.svg => b7ac4ce8.svg} | 82 ++-- dev/methods/{1f1e599f.svg => becd86d9.svg} | 262 ++++++------ dev/methods/{3bf96f41.svg => d1f581c5.svg} | 90 ++-- dev/methods/{bc52c47f.svg => d2dcaaf7.svg} | 82 ++-- dev/methods/{110bf474.svg => e3bdb15c.svg} | 82 ++-- dev/methods/index.html | 28 +- 17 files changed, 938 insertions(+), 938 deletions(-) rename dev/methods/{35055978.svg => 03781d90.svg} (97%) rename dev/methods/{26f02551.svg => 2ec976a5.svg} (97%) rename dev/methods/{b088b4b5.svg => 2f3ebce7.svg} (80%) rename dev/methods/{43f8af8c.svg => 3a7d3077.svg} (97%) rename dev/methods/{3498931a.svg => 47587af6.svg} (95%) rename dev/methods/{60c73e3c.svg => 5b65bccf.svg} (86%) rename dev/methods/{d8d65d27.svg => 8f57f05e.svg} (97%) rename dev/methods/{7d713435.svg => aaa6e30b.svg} (97%) rename dev/methods/{6e2c9c33.svg => b7ac4ce8.svg} (97%) rename dev/methods/{1f1e599f.svg => becd86d9.svg} (95%) rename dev/methods/{3bf96f41.svg => d1f581c5.svg} (97%) rename dev/methods/{bc52c47f.svg => d2dcaaf7.svg} (97%) rename dev/methods/{110bf474.svg => e3bdb15c.svg} (97%) diff --git a/dev/.documenter-siteinfo.json b/dev/.documenter-siteinfo.json index 70c2a174..b70f098a 100644 --- a/dev/.documenter-siteinfo.json +++ b/dev/.documenter-siteinfo.json @@ -1 +1 @@ -{"documenter":{"julia_version":"1.9.3","generation_timestamp":"2023-10-17T07:35:29","documenter_version":"1.1.1"}} \ No newline at end of file +{"documenter":{"julia_version":"1.9.3","generation_timestamp":"2023-10-17T10:28:20","documenter_version":"1.1.1"}} \ No newline at end of file diff --git a/dev/index.html b/dev/index.html index 08d60331..c3e5647e 100644 --- a/dev/index.html +++ b/dev/index.html @@ -12,10 +12,10 @@ Official https://julialang.org/ release Platform Info: OS: Linux (x86_64-linux-gnu) - CPU: 2 × Intel(R) Xeon(R) Platinum 8272CL CPU @ 2.60GHz + CPU: 2 × Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz WORD_SIZE: 64 LIBM: libopenlibm - LLVM: libLLVM-14.0.6 (ORCJIT, skylake-avx512) + LLVM: libLLVM-14.0.6 (ORCJIT, icelake-server) Threads: 1 on 2 virtual cores
A more complete overview of all dependencies and their versions is also provided.
Status `~/work/DataInterpolations.jl/DataInterpolations.jl/docs/Manifest.toml`
   [a4c015fc] ANSIColoredPrinters v0.0.1
   [1520ce14] AbstractTrees v0.4.4
@@ -241,4 +241,4 @@
   [8e850b90] libblastrampoline_jll v5.8.0+0
   [8e850ede] nghttp2_jll v1.48.0+0
   [3f19e933] p7zip_jll v17.4.0+0
-Info Packages marked with ⌃ and ⌅ have new versions available, but those with ⌅ are restricted by compatibility constraints from upgrading. To see why use `status --outdated -m`

You can also download the manifest file and the project file.

+Info Packages marked with ⌃ and ⌅ have new versions available, but those with ⌅ are restricted by compatibility constraints from upgrading. To see why use `status --outdated -m`

You can also download the manifest file and the project file.

diff --git a/dev/interface/index.html b/dev/interface/index.html index b113d62d..f4625c08 100644 --- a/dev/interface/index.html +++ b/dev/interface/index.html @@ -17,4 +17,4 @@ A(100.0)
10.101397401671347
Note

The values computed beyond the range of the time points provided during interpolation will not be reliable as these methods only perform well within the range and the first/last piece polynomial fit is extrapolated on either sides which might not reflect the true nature of the data.

Derivatives

Derivatives of the interpolated curves can also be computed at any point for all the methods.

We will continue with the above example, but the API is same for all the methods.

# derivative(A, t)
 DataInterpolations.derivative(A, 1.0)
-0.051048168999699245

Integrals

Integrals of the interpolated curves can also be computed easily.

Currently, this is implemented only for a few methods - ConstantInterpolation, LinearInterpolation, QuadraticInterpolation, QuadraticSpline and CubicSpline.

To compute the integrals from the start of time points provided during interpolation to any point, we can do:

# integral(A, t)
 DataInterpolations.integral(A, 5.0)
72.86338611822583

If we want to compute integrals between two points, we can do:

# integral(A, t1, t2)
-DataInterpolations.integral(A, 1.0, 5.0)
114.9694509973317
Note

If the times provided in the integral goes beyond the range of the time points provided during interpolation, it uses extrapolation methods to compute the values and hence the integral can be misrepsentative and might not reflect the true nature of the data.

+DataInterpolations.integral(A, 1.0, 5.0)
114.9694509973317
Note

If the times provided in the integral goes beyond the range of the time points provided during interpolation, it uses extrapolation methods to compute the values and hence the integral can be misrepsentative and might not reflect the true nature of the data.

diff --git a/dev/methods/35055978.svg b/dev/methods/03781d90.svg similarity index 97% rename from dev/methods/35055978.svg rename to dev/methods/03781d90.svg index b9a68ed8..1cf5a02a 100644 --- a/dev/methods/35055978.svg +++ b/dev/methods/03781d90.svg @@ -1,53 +1,53 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/methods/26f02551.svg b/dev/methods/2ec976a5.svg similarity index 97% rename from dev/methods/26f02551.svg rename to dev/methods/2ec976a5.svg index 02f04423..01c694c5 100644 --- a/dev/methods/26f02551.svg +++ b/dev/methods/2ec976a5.svg @@ -1,55 +1,55 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/methods/b088b4b5.svg b/dev/methods/2f3ebce7.svg similarity index 80% rename from dev/methods/b088b4b5.svg rename to dev/methods/2f3ebce7.svg index 69126088..00731c19 100644 --- a/dev/methods/b088b4b5.svg +++ b/dev/methods/2f3ebce7.svg @@ -1,248 +1,248 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/methods/43f8af8c.svg b/dev/methods/3a7d3077.svg similarity index 97% rename from dev/methods/43f8af8c.svg rename to dev/methods/3a7d3077.svg index 23e60b1a..b682b6ab 100644 --- a/dev/methods/43f8af8c.svg +++ b/dev/methods/3a7d3077.svg @@ -1,55 +1,55 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/methods/3498931a.svg b/dev/methods/47587af6.svg similarity index 95% rename from dev/methods/3498931a.svg rename to dev/methods/47587af6.svg index f7a263f3..53c5dc41 100644 --- a/dev/methods/3498931a.svg +++ b/dev/methods/47587af6.svg @@ -1,145 +1,145 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/methods/60c73e3c.svg b/dev/methods/5b65bccf.svg similarity index 86% rename from dev/methods/60c73e3c.svg rename to dev/methods/5b65bccf.svg index 83d05b3e..6fce8e21 100644 --- a/dev/methods/60c73e3c.svg +++ b/dev/methods/5b65bccf.svg @@ -1,62 +1,62 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/methods/d8d65d27.svg b/dev/methods/8f57f05e.svg similarity index 97% rename from dev/methods/d8d65d27.svg rename to dev/methods/8f57f05e.svg index 5237ce3e..c378c8b7 100644 --- a/dev/methods/d8d65d27.svg +++ b/dev/methods/8f57f05e.svg @@ -1,57 +1,57 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/methods/7d713435.svg b/dev/methods/aaa6e30b.svg similarity index 97% rename from dev/methods/7d713435.svg rename to dev/methods/aaa6e30b.svg index b5490d8e..fe71f4b0 100644 --- a/dev/methods/7d713435.svg +++ b/dev/methods/aaa6e30b.svg @@ -1,57 +1,57 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/methods/6e2c9c33.svg b/dev/methods/b7ac4ce8.svg similarity index 97% rename from dev/methods/6e2c9c33.svg rename to dev/methods/b7ac4ce8.svg index 5f10245d..c176c3f3 100644 --- a/dev/methods/6e2c9c33.svg +++ b/dev/methods/b7ac4ce8.svg @@ -1,55 +1,55 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/methods/1f1e599f.svg b/dev/methods/becd86d9.svg similarity index 95% rename from dev/methods/1f1e599f.svg rename to dev/methods/becd86d9.svg index 12e02518..143b6d77 100644 --- a/dev/methods/1f1e599f.svg +++ b/dev/methods/becd86d9.svg @@ -1,145 +1,145 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/methods/3bf96f41.svg b/dev/methods/d1f581c5.svg similarity index 97% rename from dev/methods/3bf96f41.svg rename to dev/methods/d1f581c5.svg index feee5969..02dfcb64 100644 --- a/dev/methods/3bf96f41.svg +++ b/dev/methods/d1f581c5.svg @@ -1,59 +1,59 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/methods/bc52c47f.svg b/dev/methods/d2dcaaf7.svg similarity index 97% rename from dev/methods/bc52c47f.svg rename to dev/methods/d2dcaaf7.svg index 7a33fbf6..02ca00f0 100644 --- a/dev/methods/bc52c47f.svg +++ b/dev/methods/d2dcaaf7.svg @@ -1,55 +1,55 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/methods/110bf474.svg b/dev/methods/e3bdb15c.svg similarity index 97% rename from dev/methods/110bf474.svg rename to dev/methods/e3bdb15c.svg index 77493a52..5d2b59b2 100644 --- a/dev/methods/110bf474.svg +++ b/dev/methods/e3bdb15c.svg @@ -1,55 +1,55 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/methods/index.html b/dev/methods/index.html index 9763c3bd..b2251e1c 100644 --- a/dev/methods/index.html +++ b/dev/methods/index.html @@ -13,24 +13,24 @@ 205.8 252.3

For each method, we will show how to perform the fit and use the plot recipe to show the fitting curve.

Linear Interpolation

This is a linear interpolation between ends points of interval of input data point.

A = LinearInterpolation(u, t)
 scatter(t, u, label = "input data")
-plot!(A)
Example block output

Quadratic Interpolation

This function fits a parabola passing through the two nearest points from the input data point as well as the next-closest point in the right or the left, depending on whether the forward- or backward-looking mode is selected (default mode is forward-looking). It is continuous and piecewise differentiable.

A = QuadraticInterpolation(u, t) # same as QuadraticInterpolation(u,t,:Forward)
+plot!(A)
Example block output

Quadratic Interpolation

This function fits a parabola passing through the two nearest points from the input data point as well as the next-closest point in the right or the left, depending on whether the forward- or backward-looking mode is selected (default mode is forward-looking). It is continuous and piecewise differentiable.

A = QuadraticInterpolation(u, t) # same as QuadraticInterpolation(u,t,:Forward)
 # alternatively: A = QuadraticInterpolation(u,t,:Backward)
 scatter(t, u, label = "input data")
-plot!(A)
Example block output

Lagrange Interpolation

It fits polynomial of degree d (=length(t)-1), and is thus a continuously differentiable function.

A = LagrangeInterpolation(u, t)
+plot!(A)
Example block output

Lagrange Interpolation

It fits polynomial of degree d (=length(t)-1), and is thus a continuously differentiable function.

A = LagrangeInterpolation(u, t)
 scatter(t, u, label = "input data")
-plot!(A)
Example block output

Constant Interpolation

This function is constant between data points. By default it takes value at left end of the interval. One can change that behavior by passing the keyword argument dir = :right.

A = ConstantInterpolation(u, t)
+plot!(A)
Example block output

Constant Interpolation

This function is constant between data points. By default it takes value at left end of the interval. One can change that behavior by passing the keyword argument dir = :right.

A = ConstantInterpolation(u, t)
 scatter(t, u, label = "input data")
-plot!(A)
Example block output

Or using the right endpoints:

A = ConstantInterpolation(u, t, dir = :right)
+plot!(A)
Example block output

Or using the right endpoints:

A = ConstantInterpolation(u, t, dir = :right)
 scatter(t, u, label = "input data")
-plot!(A)
Example block output

Quadratic Spline

This is the quadratic spline. It is a continuously differentiable interpolation which hits each of the data points exactly. Splines are a local interpolation method, meaning that the curve in a given spot is only affected by the points nearest to it.

A = QuadraticSpline(u, t)
+plot!(A)
Example block output

Quadratic Spline

This is the quadratic spline. It is a continuously differentiable interpolation which hits each of the data points exactly. Splines are a local interpolation method, meaning that the curve in a given spot is only affected by the points nearest to it.

A = QuadraticSpline(u, t)
 scatter(t, u, label = "input data")
-plot!(A)
Example block output

Cubic Spline

This is the cubic spline. It is a continuously twice differentiable interpolation which hits each of the data points exactly.

A = CubicSpline(u, t)
+plot!(A)
Example block output

Cubic Spline

This is the cubic spline. It is a continuously twice differentiable interpolation which hits each of the data points exactly.

A = CubicSpline(u, t)
 scatter(t, u, label = "input data")
-plot!(A)
Example block output

B-Splines

This is an interpolating B-spline. B-splines are a global method, meaning that every data point is taken into account for each point of the curve. The interpolating B-spline is the version which hits each of the points. This method is described in more detail here. Let's plot a cubic B-spline (3rd order). Since the data points are not close to uniformly spaced, we will use the :ArcLen and :Average choices:

A = BSplineInterpolation(u, t, 3, :ArcLen, :Average)
+plot!(A)
Example block output

B-Splines

This is an interpolating B-spline. B-splines are a global method, meaning that every data point is taken into account for each point of the curve. The interpolating B-spline is the version which hits each of the points. This method is described in more detail here. Let's plot a cubic B-spline (3rd order). Since the data points are not close to uniformly spaced, we will use the :ArcLen and :Average choices:

A = BSplineInterpolation(u, t, 3, :ArcLen, :Average)
 scatter(t, u, label = "input data")
-plot!(A)
Example block output

The approximating B-spline is a smoothed version of the B-spline. It again is a global method. In this case, we need to give a number of control points length(t)>h and this method fits a B-spline through the control points which is a least square approximation. This has a natural effect of smoothing the data. For example, if we use 4 control points, we get the result:

A = BSplineApprox(u, t, 3, 4, :ArcLen, :Average)
+plot!(A)
Example block output

The approximating B-spline is a smoothed version of the B-spline. It again is a global method. In this case, we need to give a number of control points length(t)>h and this method fits a B-spline through the control points which is a least square approximation. This has a natural effect of smoothing the data. For example, if we use 4 control points, we get the result:

A = BSplineApprox(u, t, 3, 4, :ArcLen, :Average)
 scatter(t, u, label = "input data")
-plot!(A)
Example block output

Regularization Smoothing

Smoothing by regularization (a.k.a. ridge regression) finds a function $\hat{u}$ that minimizes the objective function:

$Q(\hat{u}) = \int_{t_1}^{t_N} |\hat{u}(t) - u(t)|^2 \mathrm{d}t + \lambda \int_{\hat{t}_1}^{\hat{t}_N} |\hat{u}^{(d)}(\hat{t})|^2 \mathrm{d} \hat{t}$

where $(d)$ denotes derivative order and $\lambda$ is the regularization (smoothing) parameter. The integrals are evaluated numerically at the set of $t$ values for the first term and $\hat{t}$ values for the second term (equal to $t$ if not provided). Regularization smoothing is a global method and creates a smooth curve directly. See Stickel (2010) Comput. Chem. Eng. 34:467 for details. The implementation in this package uses cubic splines to interpolate between the smoothed points after they are determined.

using RegularizationTools
+plot!(A)
Example block output

Regularization Smoothing

Smoothing by regularization (a.k.a. ridge regression) finds a function $\hat{u}$ that minimizes the objective function:

$Q(\hat{u}) = \int_{t_1}^{t_N} |\hat{u}(t) - u(t)|^2 \mathrm{d}t + \lambda \int_{\hat{t}_1}^{\hat{t}_N} |\hat{u}^{(d)}(\hat{t})|^2 \mathrm{d} \hat{t}$

where $(d)$ denotes derivative order and $\lambda$ is the regularization (smoothing) parameter. The integrals are evaluated numerically at the set of $t$ values for the first term and $\hat{t}$ values for the second term (equal to $t$ if not provided). Regularization smoothing is a global method and creates a smooth curve directly. See Stickel (2010) Comput. Chem. Eng. 34:467 for details. The implementation in this package uses cubic splines to interpolate between the smoothed points after they are determined.

using RegularizationTools
 d = 2
 λ = 1e3
 A = RegularizationSmooth(u, t, d; λ = λ, alg = :fixed)
@@ -42,7 +42,7 @@
 lw = 1.5
 scatter(t, u, label = "data")
 scatter!(t, û, marker = :square, label = "smoothed data")
-plot!(titp, uitp, lw = lw, label = "smoothed interpolation")
Example block output

Dense Data Demonstration

Some methods are better suited for dense data. Let's generate such data to demonstrate these methods.

import StableRNGs: StableRNG
+plot!(titp, uitp, lw = lw, label = "smoothed interpolation")
Example block output

Dense Data Demonstration

Some methods are better suited for dense data. Let's generate such data to demonstrate these methods.

import StableRNGs: StableRNG
 rng = StableRNG(318)
 t = sort(10 .* rand(rng, 100))
 u = sin.(t) .+ 0.5 * randn(rng, 100);
100-element Vector{Float64}:
@@ -76,17 +76,17 @@
 scatter(t, u, label = "simulated data", legend = :top)
 scatter!(t, û, marker = (:square, 4), label = "smoothed data")
 plot!(titp, uitp, lw = lw, label = "smoothed interpolation")
-plot!(titp, ûm, lw = lw, linestyle = :dash, label = "smoothed, more points")
Example block output

Curve Fits

A curve fit works with both dense and sparse data. We will demonstrate the curve fit on the dense data since we generated it based on sin(t), so this is the curve we want to fit through it. Do do so, let's define a similar function with parameters. Let's choose the form:

m(t, p) = @. p[1] * sin(p[2] * t) + p[3] * cos(p[4] * t)
m (generic function with 1 method)

Notice that this is a function on the whole array of t and expects an array for the predicted u out. This choice of m is the assumption that our function is of the form p1*sin(p2*t)+p3*cos(p4*t). We want to find the p to match our data. Let's start with the guess of every p being zero, that is p=ones(4). Then we would fit this curve using:

using Optim
+plot!(titp, ûm, lw = lw, linestyle = :dash, label = "smoothed, more points")
Example block output

Curve Fits

A curve fit works with both dense and sparse data. We will demonstrate the curve fit on the dense data since we generated it based on sin(t), so this is the curve we want to fit through it. Do do so, let's define a similar function with parameters. Let's choose the form:

m(t, p) = @. p[1] * sin(p[2] * t) + p[3] * cos(p[4] * t)
m (generic function with 1 method)

Notice that this is a function on the whole array of t and expects an array for the predicted u out. This choice of m is the assumption that our function is of the form p1*sin(p2*t)+p3*cos(p4*t). We want to find the p to match our data. Let's start with the guess of every p being zero, that is p=ones(4). Then we would fit this curve using:

using Optim
 A = Curvefit(u, t, m, ones(4), LBFGS())
 scatter(t, u, label = "points", legend = :bottomright)
-plot!(A)
Example block output

We can check what the fitted parameters are via:

A.pmin
4-element Vector{Float64}:
+plot!(A)
Example block output

We can check what the fitted parameters are via:

A.pmin
4-element Vector{Float64}:
   1.002517318529601
   1.0396588440356678
  -0.13178842466234678
   1.0670107400182296

Notice that it essentially made p3=0 with p1=p2=1, meaning it approximately found sin(t)! But note that the ability to fit is dependent on the initial parameters. For example, with p=zeros(4) as the initial parameters the fit is not good:

A = Curvefit(u, t, m, zeros(4), LBFGS())
 scatter(t, u, label = "points", legend = :bottomright)
-plot!(A)
Example block output

And the parameters show the issue:

A.pmin
4-element Vector{Float64}:
+plot!(A)
Example block output

And the parameters show the issue:

A.pmin
4-element Vector{Float64}:
  0.0
  0.0
  0.042632088464589324
- 0.0
+ 0.0