问个入门级的问题
本帖最后由 antonym55 于 2016-08-10 22:58 编辑已知 f(x) =(5*x)/2 - (25*asin(x/5))/2 - (x*(25 - x^2)^(1/2))/2 + x^2/4
def f(x):
return 0.25*x**2 - x*sqrt(-x**2 + 25)/2 + 2.5*x - 25*asin(x/5)/2
a = f(3)
a
结果为什么是3.75?
matlab 算的如下
Python 算得不对 本帖最后由 antonym55 于 2016-08-11 09:56 编辑
原因知道了,f(3)和f(3.0)结果不同的,有没办法默认就浮点数,需要取整的时候再用函数
改了一版
from math import *
def f(x):
x = float(x)
return 0.25*x**2 - x*sqrt(-x**2 + 25)/2 + 2.5*x - 25*asin(x/5)/2
g = lambda x: 0.25*x**2 - x*sqrt(-x**2 + 25)/2 + 2.5*x - 25*asin(x/5)/2
a = f(3)
b = g(3)
print(a,b)
结果
(-4.293763859916055, 3.75)
但是 lambda 的不正确,不知道怎么改比较方便
这个问题是之前网上流传的小学数学题,求阴影面积
把notebook 传上来,给有需要的
那个阴影题目错了.
页:
[1]