I have created a function that shall take as input two columns( arrays), use the central difference for the gradient, and return a column/array with the gradient values.
This is what I have written:
def central_diff_method (array_vert_disp , array_chain):
# Compute the difference formula for f'(a) with step size h.
import pandas as pd
length_of_column= len(array_vert_disp)
array_diff=pd.DataFrame()
array_chain_diff=pd.DataFrame()
grad_inc=pd.DataFrame()
k=0
for i in range (1,length_of_column-1):
array_diff[k]=array_chain[i+1]-array_chain[i-1]
array_chain_diff[k]=array_chain[i+1]-array_chain[i-1]
grad_inc[k]=array_diff[k]/(array_chain_diff[k]*2)
k=k+1
return grad_inc
And this is how I call it in the main script:
disps['grad_inc']=central_diff_method(disps['z_disps'], disps['chainage'])
I get a nameerror in the command window: disps['grad_inc']=central_diff_method(disps['z_disps'], disps['chainage'])
NameError: name 'central_diff_method' is not defined
What am I doing wrong ? Apart from that, do you see anything else wrong in my function?