# ApproxFun for vector-valued function

**URL:** <https://discourse.julialang.org/t/approxfun-for-vector-valued-function/45135>\
**Category:** Numerics\
**Created:** [August 18, 2020, 1:09am UTC](https://discourse.julialang.org/t/approxfun-for-vector-valued-function/45135 "2020-08-18T01:09:51Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![mleprovost](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mleprovost/32/7166_2.png) [@mleprovost](https://discourse.julialang.org/u/mleprovost)\
**Post date:** [August 18, 2020, 1:09am UTC](https://discourse.julialang.org/t/approxfun-for-vector-valued-function/45135/1 "2020-08-18T01:09:51Z")

</div>

Hello,

I have a vector-valued and nonlinear function f:\mathbb{R}^n \xrightarrow{} \mathbb{R}^m with n, m \sim 50.  
I am only interested in the local behavior of this function about a n-dimensional interval [a\_1, b\_1] \times [a\_2, b\_2] \times \ldots \times [a\_n, b\_n].

Do you have an example that use ApproxFun on multi-dimensional function

This function `f ` is just an example

```julia
using LinearAlgebra
using ApproxFun

n = 50
m = 50
a = randn(n)

b = a .+ rand(n)

# [a; b] defines the lower-upper bound intervals

function f(x)
    out = zeros(m)
    out[1] = 1.0
    for i=2:m
        out[i] = out[i-1]*cos(x[i])*exp(-x[i-1]^2)
    end
    return out
end

```

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [August 18, 2020, 1:15am UTC](https://discourse.julialang.org/t/approxfun-for-vector-valued-function/45135/2 "2020-08-18T01:15:44Z")

</div>

What behaviour are you interested in?

---

<div class="post-metadata">

**Author:** ![mleprovost](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mleprovost/32/7166_2.png) [@mleprovost](https://discourse.julialang.org/u/mleprovost)\
**Post date:** [August 18, 2020, 1:19am UTC](https://discourse.julialang.org/t/approxfun-for-vector-valued-function/45135/3 "2020-08-18T01:19:14Z")

</div>

I would like to get the Jacobian and Hessian. The function f involves intermediates computations in the complex space.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [August 18, 2020, 1:22am UTC](https://discourse.julialang.org/t/approxfun-for-vector-valued-function/45135/4 "2020-08-18T01:22:35Z")

</div>

Do you want to evaluate the Jacobian and Hessian at a single point? If so then you can use `ForwardDiff.jl`. Note that you will need to change `zeros(m)` to something like `zeros(eltype(x), m)`.

---

<div class="post-metadata">

**Author:** ![mleprovost](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mleprovost/32/7166_2.png) [@mleprovost](https://discourse.julialang.org/u/mleprovost)\
**Post date:** [August 18, 2020, 1:23am UTC](https://discourse.julialang.org/t/approxfun-for-vector-valued-function/45135/5 "2020-08-18T01:23:37Z")

</div>

ForwardDiff doesn’t support intermediate computations in the complex space. I need to evaluate the derivatives (Jacobian and Hessian) at multiples evaluation points. These evaluation points are “close”.

---

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [August 18, 2020, 6:29am UTC](https://discourse.julialang.org/t/approxfun-for-vector-valued-function/45135/6 "2020-08-18T06:29:23Z")

</div>

This is well-beyond ApproxFun’s capabilities: it can only do 2D, not 50D. To get to 50D one would need more sophisticated low rank approximation like tensor trains, but that will only work well Cass with low rank functions

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [August 18, 2020, 7:22am UTC](https://discourse.julialang.org/t/approxfun-for-vector-valued-function/45135/7 "2020-08-18T07:22:27Z")

</div>

Can there be something done analytically using ModelingToolkit?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 18, 2020, 2:07pm UTC](https://discourse.julialang.org/t/approxfun-for-vector-valued-function/45135/8 "2020-08-18T14:07:55Z")

</div>

> [@dlfivefifty](#):
>
> get to 50D one would need more sophisticated low rank approximation like tensor trains

I agree that TT is probably the best approach, but a Smolyak grid may also be viable alternative and there are some Julia implementations. I saw some TT libraries for Julia on Github but didn’t try any of them.

---

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [August 18, 2020, 2:17pm UTC](https://discourse.julialang.org/t/approxfun-for-vector-valued-function/45135/9 "2020-08-18T14:17:51Z")

</div>

Smolyak grid support in ApproxFun would be awesome

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 18, 2020, 2:36pm UTC](https://discourse.julialang.org/t/approxfun-for-vector-valued-function/45135/10 "2020-08-18T14:36:25Z")

</div>

What do you think about the approach in

> **[Spectral tensor-train decomposition](https://arxiv.org/abs/1405.5713)**
>
> The accurate approximation of high-dimensional functions is an essential task in uncertainty quantification and many other fields. We propose a new function approximation scheme based on a spectral extension of the tensor-train (TT) decomposition. We...

?

---

<div class="post-metadata">

**Author:** ![mleprovost](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mleprovost/32/7166_2.png) [@mleprovost](https://discourse.julialang.org/u/mleprovost)\
**Post date:** [August 18, 2020, 5:38pm UTC](https://discourse.julialang.org/t/approxfun-for-vector-valued-function/45135/11 "2020-08-18T17:38:14Z")

</div>

Thank you all for your feedbacks =)

Do you have some references of Julia packages that implement TensorTrain or Smolyak grid techniques, and support differentiation?

---

<div class="post-metadata">

**Author:** ![RJDennis](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@RJDennis](https://discourse.julialang.org/u/RJDennis)\
**Post date:** [August 19, 2020, 10:00am UTC](https://discourse.julialang.org/t/approxfun-for-vector-valued-function/45135/12 "2020-08-19T10:00:30Z")

</div>

It’s not documented , but this package will compute derivatives too, via the smolyak\_derivative() function.

[https://github.com/RJDennis/SmolyakApprox.jl](https://github.com/RJDennis/SmolyakApprox.jl)
