Evaluating gradient of numerically approximated function

asked 2021-10-25 16:55:41 +0200

VonbatenBach gravatar image

Hello, I'd like to ask how to solve the following problem in Sage.

Let's suppose that I have a scalar function on R^3 (written in spherical coordinates) V(r,\theta,\phi), given by some tedious integral over a region in R^2: V(r,th,ph) = \int dx \int dy f(x,y,r,th,ph) (typical when calculating potentials by Green functions). The first question, how could I define such a function V in Sage? I guess it would involve approximating this function point by point by a 3-dim matrix containing results of numerical integration V(r0,th0,ph0) at different (r0,th0,ph0)...

Then, I would like to calculate the gradient of this V(r,th,ph) and plot streamlines or at least some plot of resulting vector field. I know how to do this when Sage is able to evaluate this gradient symbolically, but I don't know how to approximate it numerically and then make a plot.
I appreciate any help.

edit retag flag offensive close merge delete

Comments

Could you please provide the code defining f, V, etc, so that we could understand your request better.

tmonteil gravatar imagetmonteil ( 2021-10-26 09:04:54 +0200 )edit