0

I am trying to plot the content of the arrays x and lj in the following code. However, the point in the plots are not the one inside the arrays. Can someone help me see the mistake I did ? I am still new in python.

from matplotlib import pyplot as plt 
import numpy as np
import math 

lj=np.arange(10, dtype=np.float).reshape(10,1)
x=np.arange(10, dtype=np.float).reshape(10,1)

lj.fill(0)
x.fill(0)

for i in range(len(x)):
    x[i,0]=i*0.1
    lj[i,0]=4.0*( (1.0/(x[i,0]+0.0000001) )**12 - ( 1.0/(x[i,0]+0.0000001) )**6 )
    

for i in range(len(x)):
    print(x[i,0],"\t\t\t",lj[i,0])

plt.plot(x,lj,"o")
plt.show()

This is the content of the arrayys and the follwoiing one is the plot done with plt.plot()

0.0                      4e+84
0.1                      3999948000335.996
0.2                      976494140.831542
0.30000000000000004      7521188.628402116
0.4                      237441.3028118298
0.5                      16127.960985650918
0.6000000000000001       1751.8371605495026
0.7000000000000001       254.9905579573781
0.8                      42.94879598363375
0.9                      6.636105087302215

enter image description here

2
  • This is the value at x=0 . the problem is with the other values after 0 in the x-axis Commented Mar 19, 2021 at 14:31
  • 2
    0 is the singularity, remove it from your data, you would see a better curve. Commented Mar 19, 2021 at 14:37

1 Answer 1

1

Almost division by zero The plot is correct, lj[0] is almost equal to infinity, remove the first element, to get a better curve

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.