1

I want to plot a function and each time I got this error: only size-1 arrays can be converted to Python scalars. I want to plot my function over the w.

The code is :

import matplotlib.pyplot as plt
import numpy as np
import math
a = 10;
w = np.arange (0.001,10, 0.1)

function = (1/(np.pi*(w**2))+ np.pi)*abs(((-2*math.atan(a))*w)-(2*math.atanh(((w**2) + 1)/(-1*(w**2) + 2*(a**2) +1))*w)+ (np.pi*w) -(2*math.atanh(w/(a))))

plt.plot(w, function) 

plt.show() 

Thanks for your time.

1 Answer 1

3

You'll be better off using numpy.arctan and numpy.arctanh instead of the math equivalents, as they can work with arrays:

a = 10;
w = np.arange (0.001,10, 0.1)

function = (1/(np.pi*(w**2))+ np.pi)*abs(((-2*np.arctan(a))*w)-(2*np.arctanh(((w**2) + 1)/(-1*(w**2) + 2*(a**2) +1))*w)+ (np.pi*w) -(2*np.arctanh(w/(a))))

plt.plot(w, function) 

plt.show() 

enter image description here

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.