我正在尝试编写一个执行以下操作的程序:
这个方程看起来很糟糕,但除了 V 之外,一切都是常数。这是方程。这个方程并不是很重要。
我应该如何解决这个问题?我的尝试(如下所示)不会计算从文件中读取的每个 V 值的积分。
from scipy import integrate #integrate.quad
from numpy import *
import pylab
import datetime
import time
import os
import math
# import V
fn = 'cooltemp.dat'
V = loadtxt(fn,unpack=True,usecols=[1])
# variables
del1, del2, R, E, fE, fEeV = 1,2,1,2,1,1
e = 1.602176565*10**-19
# eqn = dint(abc)
a = E/( math.sqrt( E**2 - del1**2 ) )
b = ( …
Run Code Online (Sandbox Code Playgroud) 我正在寻找一种方法来设置固定步长,以通过 Python 中的 Runge-Kutta 方法解决我的初始值问题。因此,我如何告诉scipy.integrate.RK45
其集成过程保持不断更新(步长)?
非常感谢。
I have a c console app which converts a c file to a html file, the c file location is passed to the program as a command line argument.(the app is for the windows platform)
What I would like to do is have a python gui app to allow the user to select a file and pass the location of the file to the c app for processing.
I already know how to create a basic python gui with tkinter, …
我想知道Ubuntu 13.04中存在哪些库允许与Grub2集成以及它的更多细节(即语言,开发阶段,开发人员等),或者如果不能这样做,为什么?
我还认为可以在Surface Pro架构中使用本机设备代码,但是没有如何开始的经验.如果有可能请告诉我!
编辑: 2013年3月14日@太平洋标准时间下午5:40
我一直在努力寻找并在Ubuntu 13.04下找到以下软件包:
我在 R 中使用积分函数来积分一个非常尖的函数。假设该函数是对数正态密度:
xs <- seq(0,3,0.00001)
fun <- function(xs) dlnorm(xs, meanlog=-1.057822,sdlog=0.001861871)
plot(xs,fun(xs),type="l")
Run Code Online (Sandbox Code Playgroud)
从图中,我知道峰值在 0.3-0.4 左右。
如果我将这个密度函数整合到它的支持上(增加abs.tol
和增加细分),integrate()
我会得到零,这不应该是真的。
integrate(fun,lower=0,upper=Inf,subdivisions=10000000,abs.tol=1e-100)
0 with absolute error < 0
Run Code Online (Sandbox Code Playgroud)
但是,如果我将间隔限制为 0.3 - 0.4,它会给我正确的答案。
integrate(fun,lower=0.3,upper=0.4,subdivisions=10000000,abs.tol=1e-100)
1 with absolute error < 1.7e-05
Run Code Online (Sandbox Code Playgroud)
有没有办法在不手动选择间隔的情况下整合这个密度?
我对上一篇文章有类似的挑战:如何通过向量来集成函数
我有一个函数,我想对曲线下的面积进行积分。
一、【生存】功能:
surv <- function(x,score) exp(-0.0405*exp(score)*x) # probability of survival
Run Code Online (Sandbox Code Playgroud)
score
来自风险计算器,它调整生存估计。患者有不同的分数,例如:
score <- c(0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1) # 7 different scores
Run Code Online (Sandbox Code Playgroud)
surv
如果我们有一个特定的时间点x
,计算所有 7 名患者的时间很容易:
surv(5, score) # Survival to year 5
[1] 0.7161497 0.6914399 0.6651219 0.6371998 0.6077026 0.5766890 0.5442516
Run Code Online (Sandbox Code Playgroud)
但是要获得种群的平均存活率或个体的预期存活率,我需要计算曲线下的面积,其中曲线由函数给出surv
。我需要计算x=0
和限制下的面积x=Inf
。我需要为所有 7 个(在本例中)患者执行此操作。
我引用的另一篇 stackoverflow 帖子也有类似的问题。目前尚不清楚该解决方案是否可以帮助我。我在下面介绍:
integrate(Vectorize(fun_integrate,vectorize.args='x'), upper = 3, lower = -3, vec = rnorm(100),subdivisions=10000)
Run Code Online (Sandbox Code Playgroud)
fun_integrate
是要集成的功能
vectorize.args
是要向量化并传递给 fun_integrate 的参数
vec
是作为要传递到 fun_integrate 的参数的值的向量 …
我有
y1=[ 9.49110000e-004 4.74145420e-004 1.41847155e-008 3.33228420e-028
3.76352289e-081 4.48206815e-193 0.00000000e+000 0.00000000e+000
0.00000000e+000 0.00000000e+000 0.00000000e+000]
x=[ 112. 111.97667396 111.90666665 111.78989038 111.62619837
111.41538384 111.15717866 110.85125168 110.49720654 110.09457901
109.64283388]
Run Code Online (Sandbox Code Playgroud)
所有y
值均为正,因此曲线下的面积应为正。但是当我尝试使用辛普森规则进行整合时
from scipy.integrate import simps
b= simps(y1, x)
print b
Run Code Online (Sandbox Code Playgroud)
我得到-2.45630795891e-05
答案。我究竟做错了什么?
我从themeforst购买了flatkit主题,但我不知道如何将购买的主题与rails 5应用程序集成?
我想用积分函数拟合数据(截断的伽玛分布).我尝试了以下代码,但发生了错误.如果你能帮助我,我感激不尽.非常感谢你提前.
%matplotlib inline
import numpy as np
from scipy import integrate
import scipy.optimize
import matplotlib.pyplot as plt
xlist=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14]
ylist=[1.0, 0.7028985507246377, 0.4782608695652174, 0.36231884057971014,
0.2536231884057971, 0.1811594202898551, 0.12318840579710147,
0.08695652173913046, 0.057971014492753645, 0.04347826086956524,
0.02173913043478263, 0.007246376811594223]
xdata=np.array(xlist)
ydata=np.array(ylist)
parameter_initial=np.array([0.0,0.0,0.0])#a,b,c
def func(x,a,b,c):
return integrate.quad(lambda t:t^(a-1)*np.exp(-t),x/c,b/c)/integrate.quad(lambda t:t^(a-1)*np.exp(-t),0.0,b/c)
parameter_optimal,cov=scipy.optimize.curve_fit(func,xdata,ydata,p0=parameter_initial)
print "paramater =", paramater_optimal
y = func(xdata,paramater_optimal[0],paramater_optimal[1],paramater_optimal[2])
plt.plot(xdata, ydata, 'o')
plt.plot(xdata, y, '-')
plt.show()
Run Code Online (Sandbox Code Playgroud)
发生以下错误.
ValueError: The truth value of an array with more than one element is ambiguous. …
Run Code Online (Sandbox Code Playgroud) 我试图通过指定 的参数来更精确地计算积分epsabs
,scipy.integrate.quad
假设我们正在将函数sin(x) / x^2从 1e-16 积分到 1.0
from scipy.integrate import quad
import numpy
integrand = lambda x: numpy.sin(x) / x ** 2
integral = quad(integrand, 1e-16, 1.0)
Run Code Online (Sandbox Code Playgroud)
这给了我们
(36.760078801255595, 0.01091187908038005)
Run Code Online (Sandbox Code Playgroud)
为了使结果更加精确,我们通过以下方式指定绝对误差容限epsabs
from scipy.integrate import quad
import numpy
integrand = lambda x: numpy.sin(x) / x ** 2
integral = quad(integrand, 1e-16, 1.0, epsabs = 1e-4)
Run Code Online (Sandbox Code Playgroud)
结果一模一样,误差还大到0.0109!我对参数的理解epsabs
有误吗?我应该采取什么不同的措施来提高积分的精度?