简体   繁体   English

用python中的贝塞尔函数绘图

[英]plotting with bessel functions in python

When I run this code: 当我运行此代码时:

from scipy.optimize import minimize
import numpy as np
import matplotlib.pyplot as plt
import scipy.special as spl 

def minf(x):
    return x[0]**2 + (x[1]-1.)**2

sol = minimize(minf, [1,2])
x = np.linspace(0,10,5000)
plt.plot(x, spl.jv(3,x), '-', sol.x, -sol.fun, 'o')

I get this error: ValueError: x and y must have same first dimension 我收到此错误:ValueError:x和y必须具有相同的第一维

How to correctly specify the plot statement? 如何正确指定绘图语句?

My objective is to plot a landscape of inputs and function values. 我的目标是绘制输入和函数值的概况。 In this case, a two dimensional set of inputs. 在这种情况下,是二维输入集。 I want to know how I can use linspace, the bessel function and plot correctly for achieving this. 我想知道如何使用linspace,贝塞尔函数并正确绘制以实现此目的。

I expect a plot like this, with also the optimal point marked: 我期望这样的图,并标出最佳点:

https://sites.google.com/site/haripkannan/Home/plot_pdqp.png https://sites.google.com/site/haripkannan/Home/plot_pdqp.png

Something is not quite right with the output from minimize . minimize的输出并不正确。 It is unclear what you are trying to do with it. 目前尚不清楚您正在尝试使用它。 Look at the output of sol , how is this supposed to be plotted? 看一下sol的输出,该如何绘制?

print sol.x, sol.fun
> [ -7.45132580e-09   9.99999993e-01] 1.1104451202e-16  

Nevertheless, plotting your Bessel function is simple: 不过,绘制Bessel函数很简单:

x = np.linspace(0,10,500)
y = spl.jv(3,x)
plt.plot(x, y, '-')
plt.show()

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM