'How to plot a function with matching x and y dimensions? ValueError: x and y must have same first dimension, but have shapes (1000,) and (1,)
Im trying to plot my function against n which is an array of 1000 values, my function consists of n as a variable as well as k which ive also set as an array of 1000. But when I go to plot it, my function only returns 1 value.
How do I make my function 'd' return the same number of values as the array so it can be plotted?
import numpy as np
import matplotlib.pyplot as plt
from scipy.special import jv
from scipy.special import yv
from scipy.special import yn
from scipy.special import jn
n = np.arange(0,1,0.001)
k = np.arange(0,100,0.1)
ni = 10**(-4)
A = 1
B = 0
def C1(k):
return (np.sqrt(np.pi/2)*1/np.sqrt(k))*(((-5/2)*ni**. (-7/2)*yv(5/2,k*ni)+1/2*ni**(-7/2)*yv(3/2,k*ni)-1/2*ni**(-5/2)*yv(7/2,k*ni))*A-ni**. (-5/2)*yv(5/2,k*ni)*B)/1/2*ni**(-5)*(jv(5/2,k*ni)*yv(3/2,k*ni)- jv(5/2,k*ni)*yv(7/2,k*ni)+jv(3/2,k*ni)*yv(5/2,k*ni)-jv(7/2,k*ni)*yv(5/2,k*ni))
def C2(k):
return (np.sqrt(np.pi/2)*1/np.sqrt(k))*(ni**jv(5/2,k*ni)*B-(-5/2*ni**(-7/2)*jv(5/2,k*ni)+1/2*ni**(-5/2)*jv(3/2,k*ni)-1/2*ni**(-5/2)*jv(7/2,k*ni))*A)/1/2*ni**(-5)*(jv(5/2,k*ni)*yv(3/2,k*ni)-jv(5/2,k*ni)*yv(7/2,k*ni)+jv(3/2,k*ni)*yv(5/2,k*ni)-jv(7/2,k*ni)*yv(5/2,k*ni))
def d(k,n):
return C1*jn(2,k*n)/n**(5/2)
plt.plot(n,d)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|