Underflow issue in Python

I need to draw the following function, which is what I call theory data

with a=z-(L/2) b=z+(L/2) for the following case

  • N=75
  • I=1
  • L=0.16
  • R=0.013

for z between -0.011 and 0.011. My guess is that there are underflow issues. The code is as follows

import numpy as np
import matplotlib.pyplot as plt

class Solenoid():

def __init__(self,N,I,L,R):
    self.N=N
    self.I=I
    self.L=L
    self.R=R

def field(self,z):

    mu=4*(np.pi)*(10 ** -7)

    coef=(mu*self.N*self.I)/(2*self.L)

    a=z+(self.L/2)
    b=z-(self.L/2)

    sum_a=a/((self.R ** 2 + a ** 2) ** 0.5)

    sum_b=b/((self.R ** 2 + b ** 2) ** 0.5)

    return (coef*(sum_a - sum_b))

sol=Solenoid(75,1,0.160,0.013)
x=np.linspace(-0.011, 0.011, 10000)
y=[]

for point in x:
    y.append(sol.field(point))

plt.plot(x,y)
plt.show()  

The output is

which is plain wrong. The expected output is a more or less smooth line along with experimental data:

UPDATE New output is

Answers


It was a factor of 10 in the x scale ...


Need Your Help

MVC 3 Shared ViewModel within other views with a different Model not working

asp.net-mvc asp.net-mvc-3 asp.net-mvc-partialview

I am working on building a blog with MVC 3 and EF. I have created all my models and everything is working great. I decided I wanted to have a right nav bar with the most recent posts, comments, and...

Split array into chunks in C/C++

c++ arrays windows split

I am looking for a way to split an array into multiple arrays in C/C++, with standard Win32 and C/C++ functions.