2013-07-03 115 views
-1

的二维函数I具有的功能:的Python:绘制2两个变量

def g(R, r): 
    return (np.sqrt(2.0 * (R + r)/(r * R)) - (1 + np.sqrt(R))/np.sqrt(R) - 
      np.sqrt(2.0/(r * (1 + r))) * (1 - r) - 
      (1.0/np.sqrt(R) - np.sqrt(2.0) * (1 - R)/np.sqrt(R * (1 + R)) 
      - 1)) 

的功能是通过设置delta v_B = delta v_H其中delta v_B

np.sqrt(2.0 * (R + r)/(r * R)) - (1 + np.sqrt(R))/np.sqrt(R) - 
       np.sqrt(2.0/(r * (1 + r))) * (1 - r) 

delta v_H定义是

1.0/np.sqrt(R) - np.sqrt(2.0) * (1 - R)/np.sqrt(R * (1 + R)) - 1 

因此,我写gdelta v_b - delta v_H

现在,这是我的功能,我使用下面的代码:

import pylab 
import numby as np 


def g(R, r): 
    return (np.sqrt(2.0 * (R + r)/(r * R)) - (1 + np.sqrt(R))/np.sqrt(R) - 
      np.sqrt(2.0/(r * (1 + r))) * (1 - r) - 
      (1.0/np.sqrt(R) - np.sqrt(2.0) * (1 - R)/np.sqrt(R * (1 + R)) 
      - 1)) 


r = np.linspace(11.9, 16, 500000) 
R = np.linspace(1, 20, 500000) 

fig2 = pylab.figure() 
ax2 = fig2.add_subplot(111) 
ax2.plot(R, g(R, r), 'r') 
pylab.xlabel('$R_1 = \\frac{r_C}{r_A}$') 
pylab.ylabel('$R_2 = \\frac{r_B}{r_A}$') 
pylab.xlim((0, 25)) 
pylab.ylim((0, 100))        

pylab.show() 

功能应在约11.94渐近线为无穷大并且交叉线y = x大约15.58

我怎么能做出这样的剧情?我不熟悉如何做到这一点,我不知道如何绘制这样的功能。

是我的定义不适当的gg(R, r)?如果是这样,如果情况并非如此,应该如何界定?

enter image description here

+0

是什么“的功能应该渐近线无穷平均在大约11.94“我不明白,为什么只有一个组件?而且,什么是R,R,它们是长度? – Pablo

+0

@Pablo在11.94时函数上升到正无穷大,但不会越过那个值只接近它。小'​​r'应该是y轴值。我会画一张可怜的图片来向你展示我的意思。 – dustin

+0

@Pablo我加了我可怕的图画。 – dustin

回答

2

这就是呼叫隐函数曲线,你可以使用contour与参数levels=[0]绘制:

import numpy as np 
import matplotlib.pyplot as plt 

def g(R, r): 
    return (np.sqrt(2.0 * (R + r)/(r * R)) - (1 + np.sqrt(R))/np.sqrt(R) - 
      np.sqrt(2.0/(r * (1 + r))) * (1 - r) - 
      (1.0/np.sqrt(R) - np.sqrt(2.0) * (1 - R)/np.sqrt(R * (1 + R)) 
      - 1)) 

R, r = np.mgrid[1:30:200j, 1:100:200j] 
Z = g(R,r) 
plt.contour(R, r, Z, colors='k', levels=[0]) 
plt.show() 

enter image description here

+0

如何剪切'y = x'下的弯曲部分? – dustin