Comments (3)
The problem is that you tried to feed the function with two 1D-arrays of coordinate values, but actually you need a 2D grid in your example. You can create the 2D grid arrays from the coordinate arrays using the numpy.meshgrid
function:
from findiff import FinDiff
import numpy as np
def f(x, y):
return 5*x**2 - 5*x + 10*y**2 -10*y
diff = .01
x = np.linspace(-10,0,11)
y = np.linspace(0,10,11)
X, Y = np.meshgrid(x, y, indexing='ij')
d_dx = FinDiff(0, diff)
df_dx = d_dx(f(X, Y))
np.meshgrid
works for any number of dimensions.
FinDiff determines the grid dimension by the arrays that you apply it to. If you pass a 1D-array to a FinDiff object, it thinks that your grid is only 1D. Incidentally, if you had calculated the partial derivative with respect to y instead of x in your original implementation, it would have thrown an IndexError exception, because there is no second index in the 1D array. All in all, if you use grid arrays, all should be fine. :-)
from findiff.
This is the output I expect when I inputted what I put in.
array([[-105.],
[ -95.],
[ -85.],
[ -75.],
[ -65.],
[ -55.],
[ -45.],
[ -35.],
[ -25.],
[ -15.],
[ -5.]])
This is the output that I get when I input what you say to
array([[-10500., -10500., -10500., -10500., -10500., -10500., -10500.,
-10500., -10500., -10500., -10500.],
[ -9500., -9500., -9500., -9500., -9500., -9500., -9500.,
-9500., -9500., -9500., -9500.],
[ -8500., -8500., -8500., -8500., -8500., -8500., -8500.,
-8500., -8500., -8500., -8500.],
[ -7500., -7500., -7500., -7500., -7500., -7500., -7500.,
-7500., -7500., -7500., -7500.],
[ -6500., -6500., -6500., -6500., -6500., -6500., -6500.,
-6500., -6500., -6500., -6500.],
[ -5500., -5500., -5500., -5500., -5500., -5500., -5500.,
-5500., -5500., -5500., -5500.],
[ -4500., -4500., -4500., -4500., -4500., -4500., -4500.,
-4500., -4500., -4500., -4500.],
[ -3500., -3500., -3500., -3500., -3500., -3500., -3500.,
-3500., -3500., -3500., -3500.],
[ -2500., -2500., -2500., -2500., -2500., -2500., -2500.,
-2500., -2500., -2500., -2500.],
[ -1500., -1500., -1500., -1500., -1500., -1500., -1500.,
-1500., -1500., -1500., -1500.],
[ -500., -500., -500., -500., -500., -500., -500.,
-500., -500., -500., -500.]])
The numbers are still off, and there are more of them.
Also how do I get just one point
df_0_0_dx = d_dx(f((0,0)))
If you want to look at the jupyter notebook I am trying to figure this out on it is
from findiff.
I figured this out.
I thought your program took at function evaluated the function along with the given dx and sent back the result at the point.
It instead evaluates the finite differences for already evaluated points from a function so the grid had to already be computed.
from findiff.
Related Issues (20)
- multi dimensional coordinates HOT 1
- Derivatives for a single point in a vector space HOT 1
- PDEs HOT 1
- Using findiff to solve the stationary Schrödinger equation HOT 2
- Allow the user to specify difference method HOT 2
- Problems with the stencil matrix HOT 4
- Time-dependency HOT 2
- First Order Schemes HOT 1
- Replace math images by latex expressions HOT 2
- Analytic inversion of Vandermonde matrix HOT 5
- Outdated conda-forge builds HOT 2
- Higher accuracy derivatives in 3D HOT 3
- Accuracy HOT 2
- How are the higher order derivatives computed in your code? HOT 1
- integrals in boundary conditions? HOT 2
- DOC: Equations seem broken on documentation site HOT 1
- Input for non-uniform spacing HOT 2
- Single point derivative
- possible typo in theory section
- Numerical derivative?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from findiff.