Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compute divergence of vector field using python

Is there a function that could be used for calculation of the divergence of the vectorial field? (in matlab) I would expect it exists in numpy/scipy but I can not find it using Google.

I need to calculate div[A * grad(F)], where

F = np.array([[1,2,3,4],[5,6,7,8]]) # (2D numpy ndarray)

A = np.array([[1,2,3,4],[1,2,3,4]]) # (2D numpy ndarray)

so grad(F) is a list of 2D ndarrays

I know I can calculate divergence like this but do not want to reinvent the wheel. (I would also expect something more optimized) Does anyone have suggestions?

like image 700
nyvltak Avatar asked Jul 11 '12 15:07

nyvltak


People also ask

How do you find the divergence of a vector in Python?

but we need define func divergence as : divergence ( f) = dfx/dx + dfy/dy + dfz/dz +… = np. gradient( fx) + np. gradient(fy) + np.

How do you find the divergence of a vector field?

The numerical divergence of a vector field is a way to estimate the values of the divergence using the known values of the vector field at certain points. div F = ∇ · F = ∂ F x ∂ x + ∂ F y ∂ y + ∂ F z ∂ z .

How do you calculate divergent?

Formulas for divergence and curl For F:R3→R3 (confused?), the formulas for the divergence and curl of a vector field are divF=∂F1∂x+∂F2∂y+∂F3∂zcurlF=(∂F3∂y−∂F2∂z,∂F1∂z−∂F3∂x,∂F2∂x−∂F1∂y).

Can you take the divergence of a scalar field?

The divergence computes a scalar quantity from a vector field by differentiation. We can write this in a simplified notation using a scalar product with the ∇ vector differential operator: div a = ( ˆı ∂ ∂x + ˆ ∂ ∂y + k ∂ ∂z ) · a = ∇ · a (5.17) Notice that the divergence of a vector field is a scalar field.


1 Answers

Just a hint for everybody reading that:

the functions above do not compute the divergence of a vector field. they sum the derivatives of a scalar field A:

result = dA/dx + dA/dy

in contrast to a vector field (with three dimensional example):

result = sum dAi/dxi = dAx/dx + dAy/dy + dAz/dz

Vote down for all! It is mathematically simply wrong.

Cheers!

like image 113
Polly Avatar answered Sep 21 '22 05:09

Polly