Hi everyone! I was not sure whether to post it here or in the Numerics subforum, but given that my question is very basic I decided to go for this section.
Let’s say I want to integrate some function f(x,y) over [a_1,b_1] \times [a_2,b_2]. For definitness, suppose f(x,y) = x^2 + y and a_1 = -1, b_1 = 3, a_2 = 0, b_2 = 2. Using HCubature
I could achieve this as follows:
using HCubature
function f(x)
return x[1]^2 + x[2]
end
xmin = [-1,0];
xmax = [3,2];
val = hcubature(f,xmin,xmax);
Now, suppose the analytic expression for f(x,y) is not as simple and is given by some product of other functions and derivatives of thereof. In that case, it is much more convenient to first get the expression for f(x,y) using some in-built CAS such as SymPy
(which I am a bit more familiar with) or Symbolics
and then transform it into a Julia-type function. For simplicity, let’s say that the resulting expression is once again x^2 + y, i.e.,
using SymPy
x,y = symbols("x,y", real=true);
f(x,y) = x^2 + y;
How can I now convert it into f(x)
from the first example? Thank you in advance!
TL;DR: Given symbolic a f(x,y)
is there any way to convert it into the function f(x)
, with x
being a 2-dimensional array?