hello everyone.

i’m dealing with some struggles when programming in Julia since I come from matlab.

I need to extrapolate this plot so I can get rho(0).

any help?

version 1.6.3

hello everyone.

i’m dealing with some struggles when programming in Julia since I come from matlab.

I need to extrapolate this plot so I can get rho(0).

any help?

version 1.6.3

http://juliamath.github.io/Interpolations.jl/dev/interpolations/

btw, I think you may want a “fit”, do you have a formula you want to fit?

1 Like

yeah, a fit would really do.

actually this is a plot of two vectors rho x a

a = [1 2 4 6 8 16 32]

rho = [ 680 610 415 295 235 190 180]

i was wondering if there is a command to do this instead of finding the line equation.

In order to extrapolate, you really need to have *some* model in mind, even if you don’t explicitly fit.

For example, if you want to extrapolate using a straight line from the first two points, you can use `extrapolate(..., Line())`

from Interpolations.jl.

If you think that your data models a peak, so that `1/rho`

is approximately a low-degree polynomial, you can use Richardson extrapolation from Richardson.jl

For example, with your data I get an extrapolated value of 651 ± 7:

```
julia> val, err = extrapolate(zip(reverse(inv.(rho)), reverse(a)))
(0.0015350496476734183, 1.664001386944276e-5)
julia> 1/val
651.4447278728993
julia> err / val^2 # convert error estimate in val to error in 1/val via the derivative
7.061692970914665
```

If you additionally know that your data is symmetric around `a=0`

, \rho(-a) = \rho(a), then you can do even-order Richardson extrapolation (i.e. force it to use symmetric polynomials), which predicts \rho(0) = 742 \pm 6:

```
julia> val, err = extrapolate(zip(reverse(inv.(rho)), reverse(a)), power=2)
(0.0013481200793223414, 1.1069973063407247e-5)
julia> 1/val
741.7736856962099
julia> err / val^2
6.091011361487163
```

2 Likes

Expanding on this: if for instance you think `\rho = \frac{A}{a+B}`

then you can do

```
using LsqFit
model(x, p) = p[1] ./ (x .+ p[2])
fit = curve_fit(model, a, rho, [1.0, 1.0])
model(0, fit.param)
```

The same can be done for any (sensible) model.

1 Like

Without knowing the underlying model, will draw one more number in the lottery:

```
using Dierckx
a = [1, 2, 4, 6, 8, 16, 32]
rho = [ 680, 610, 415, 295, 235, 190, 180]
spl = Spline1D(a, rho; k=2, bc="extrapolate")
ρ₀ = evaluate(spl, 0) # ρ₀ = 723
```

3 Likes

Not sure if I understand the scope of the problem. Is the underlying function supposed to be analytic, are the points exact or can they contain noise, …

Do you mind sharing the Matlab code?

Honestly if there’s a function that lets you do this without specifying a model by which to do it, that function is lying to you. And if such a function is built into MATLAB, that’s a flaw of MATLAB, not a strength.

2 Likes