Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python backward difference

import numpy as np

# Define x, y, and derived y
x = np.linspace(0.78, 0.79, 100)
y = np.sin(x)
dy = np.cos(x)

# Init variable to store backward diff calculation
dyb = [0.0] * len(x)
# set first element by forward difference
dyb[0] = (y[0] - y[1]) / (x[0] - x[1])
# Calculate backward diff
for i in range(1,len(y)):
    dyb[i] = (y[i] - y[i-1]) / (x[i]-x[i-1])
    
# Plot result
plt.figure(figsize = (12,8))
plt.plot(x, dy, label='Exact')
plt.plot(x, dyb, '--', label='backward')
plt.legend()
plt.show()
Comment

PREVIOUS NEXT
Code Example
Python :: convert set to list python time complexity 
Python :: timed loop python 
Python :: python wikipedia api search 
Python :: how to play mp3 audio in python 
Python :: python remove all except numbers 
Python :: how to find the multiples of a number in python 
Python :: python virus 
Python :: python ssh library 
Python :: write file with python 
Python :: python find word in list 
Python :: nlargest hierarchy series pandas 
Python :: python fizzbuzz 
Python :: binomial coefficient python 
Python :: read xls file in python 
Python :: https flask 
Python :: the system cannot find the file specified sublime text 3 python 
Python :: add something to list python 
Python :: punctuation list python 
Python :: python get angle between two points 
Python :: python number to letter 
Python :: How to Add R to Jupyter Notebook 
Python :: how to invert a list in python 
Python :: pd merge on multiple columns 
Python :: python version kali linux 
Python :: remove a character from a string python 
Python :: pandas.core.series.series to dataframe 
Python :: key press python 
Python :: how to cancel a input in python 
Python :: root number in python 
Python :: python django include another app url 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =