Python Forum
linspace not dividing equal intervals
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
linspace not dividing equal intervals
i have written a code to find out effect of order of accuracy on numerical differentiation but when i am trying to use linspace(1,epsilon,100) it is not dividing it into equal is the code and the plot for the error is also incorrect

from numpy import *
import sys
import numpy as np
# machine epsilon
h = np.linspace(1,epsilon,1000)
e1= (((sin(x)- sin(x-h))/h-cos(x))/cos(x))                                    #realtive error in first order
e2= (((sin(x-2*h)-4*sin(x-h)+3*sin(x))/(2*h)-cos(x))/cos(x))                 #realtive error in second order
e3= (((2*sin(x+h)+3*sin(x)-6*sin(x-h)+sin(x-2*h))/(6*h)-cos(x))/cos(x))      #realtive error in third order
e4 = (((-sin(x-3*h)+6*sin(x-2*h)-18*sin(x-h)+10*sin(x)+3*sin(x+h))/(12*h)-cos(x))/cos(x)) 
import matplotlib.pyplot as plt
plt.ylabel('Relative error')
plt.legend(['first order','second order','third order','fourth order'])
plt.title('Effect of order of accuracy on the numerical differentiation')

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Dividing a single column of dataframe into multiple columns based on char length darpInd 2 481 Mar-14-2020, 09:19 AM
Last Post: scidam
  datetime intervals - dataframe selection (via plotted data) karlito 0 346 Nov-12-2019, 08:16 AM
Last Post: karlito
  When dividing elements of matrix i would like the result 0 instead of inf? Koczkodan 4 805 Jul-22-2019, 11:40 AM
Last Post: Koczkodan
  Confidence intervals over time with polynomial regression jjameson 0 950 May-16-2019, 02:22 PM
Last Post: jjameson
  dividing by list not possible? SchroedingersLion 5 1,162 Oct-11-2018, 10:00 AM
Last Post: volcano63
  RNG; One variable must not be equal to another DavidRobinsons 12 1,949 Oct-10-2018, 02:43 AM
Last Post: micseydel
  How to extract previous and current rows if their value is equal SriRajesh 5 1,568 Jun-18-2018, 08:09 PM
Last Post: volcano63
  Conditional If Statement: If value contains string then set another column equal to s Jack_Sparrow 2 2,242 Jun-15-2018, 03:33 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020