Test Book


In [2]:
import time
time.sleep(10)

In [4]:
!gcc?


Object `gcc` not found.

In [6]:
from ctypes import CDLL

In [7]:
CDLL?

In [9]:
dll = 'dylib'
libc = CDLL("libc.%s" % dll)

In [10]:
libc?

In [16]:
libc?

In [17]:
message = 'The IPython notebook is great!'
# note: the echo command does not run on Windows, it's a unix command.
!echo $message


The IPython notebook is great!

In [18]:
%load?

In [19]:
%load http://matplotlib.sourceforge.net/mpl_examples/pylab_examples/integral_demo.py

In [20]:
#!/usr/bin/env python

# implement the example graphs/integral from pyx
from pylab import *
from matplotlib.patches import Polygon

def func(x):
    return (x-3)*(x-5)*(x-7)+85

ax = subplot(111)

a, b = 2, 9 # integral area
x = arange(0, 10, 0.01)
y = func(x)
plot(x, y, linewidth=1)

# make the shaded region
ix = arange(a, b, 0.01)
iy = func(ix)
verts = [(a,0)] + list(zip(ix,iy)) + [(b,0)]
poly = Polygon(verts, facecolor='0.8', edgecolor='k')
ax.add_patch(poly)

text(0.5 * (a + b), 30,
     r"$\int_a^b f(x)\mathrm{d}x$", horizontalalignment='center',
     fontsize=20)

axis([0,10, 0, 180])
figtext(0.9, 0.05, 'x')
figtext(0.1, 0.9, 'y')
ax.set_xticks((a,b))
ax.set_xticklabels(('a','b'))
ax.set_yticks([])
show()


---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-20-766c9cf4d8d7> in <module>()
      2 
      3 # implement the example graphs/integral from pyx
----> 4 from pylab import *
      5 from matplotlib.patches import Polygon
      6 

ImportError: No module named pylab

What the hell!!

  • 国家为了加强对房地产市场的宏观调控控制房价的过快上涨。(无用信息)
  • 规定购买新房满五年后才可以上市转卖。(无用信息)
  • 对二手房买卖征收差价的x%的附加税。(求解X)
  • 某城市在不征收附加税时每年可成交十万套二手房。(已知常数:houses = 100000)
  • 征收附加税后每年减少0.1x万套二手房交易。 (newHouses = houses - 0.1x10000)
  • 现已知每套二手房买卖的平均差价为10万元。(oneHouseProfit = 100000)
  • 如果要是每年增收的附加税为16亿元,并且要使二手房市场保持一定的活力。(totalProfit = x/100 * newHouses * oneHouseProfit >= 1600000000)
  • 每年二手房交易量不低于6万套。(newHouses >= 60000)
  • 问。二手房交易附加税的税率应确定为多少?(Question: X = ?)
  • 已知条件:
    • 常数:
      • houses = 100000
      • oneHouseProfit = 100000
    • 变量关系:
      • newHouses = houses - 0.1x10000
      • totalProfit = x/100 * newHouses * oneHouseProfit
    • 限制条件:
      • totalProfit >= 1600000000
      • newHouses >= 60000
    • 求解问题:
      • x=?

In [2]:
x = 0
houses = 100000
oneHouseProfit = 100000
newHouses = houses - 0.1*x*10000
totalProfit = x/100*newHouses*oneHouseProfit
  • 解题思路:
    • 先考察x的范围:[0, 100]

In [3]:
#x = 0
x = 0
houses = 100000
oneHouseProfit = 100000
newHouses = houses - 0.1*x*10000
totalProfit = x/100*newHouses*oneHouseProfit
print ("当税率为",x,"时:")
print ("可销售房屋数量为:", newHouses)
print ("税收为:", totalProfit)


当税率为 0 时:
可销售房屋数量为: 100000.0
税收为: 0.0

In [4]:
#x = 100
x = 100
houses = 100000
oneHouseProfit = 100000
newHouses = houses - 0.1*x*10000
totalProfit = x/100*newHouses*oneHouseProfit
print ("当税率为",x,"时:")
print ("可销售房屋数量为:", newHouses)
print ("税收为:", totalProfit)


当税率为 100 时:
可销售房屋数量为: 0.0
税收为: 0.0

注意到销售数量和税收的关系,将其带入方程为:


In [5]:
totalProfit = x/100 * (houses - 0.1*x*10000) * oneHouseProfit

原题转化为求解二次方程的极大值问题。

  • 为了便于直观讲解,我们来画一下看看:

In [10]:
fig, axes = subplots(1,2)
x = np.linspace(0,100,50)
totalProfit = x/100 * (houses - 0.1*x*10000) * oneHouseProfit

newHouses = houses - 0.1*x*10000

axes[0].plot(x, totalProfit)
axes[0].set_xlabel("X")
axes[0].set_ylabel("totalProfit")


axes[1].plot(x, newHouses)
axes[1].set_xlabel("x")
axes[1].set_ylabel("newHouses")
fig.tight_layout()
fig.show()


左图为税收随X的变化状况。右图为房屋销售数量的变化情况。

  • 根据限制条件,则不难解出X的取值。
  • Done

In [49]:
k = axes[0]

In [33]:


In [33]:


In [7]:
%pylab inline


Populating the interactive namespace from numpy and matplotlib

In [ ]: