我有一些功能,
int somefunction( //parameters here, let's say int x) {
return something Let's say x*x+2*x+3 or does not matter
}如何求此函数的导数?如果我有
int f(int x) {
return sin(x);
}在求导之后,它必须返回cos(x)。
发布于 2010-06-03 21:15:30
你可以通过观察一小段时间内的梯度来近似导数。例如
const double DELTA=0.0001;
double dfbydx(int x) {
return (f(x+DELTA) - f(x)) / DELTA;
}根据您评估函数的位置,您可能会从(f(x+DELTA) - f(x-DELTA)) / 2*DELTA获得更好的结果。
(我假设你问题中的“int”是一个打字错误。如果他们真的在使用整数,你可能会在精度方面遇到问题。)
发布于 2010-06-03 21:14:57
您可以使用许多numerical techniques中的一种(如Numerical ordinary Differential Equations )来获得大多数函数的数值积分
但是,您可以通过库(如Maple、Mathematica、Sage或SymPy )以函数定义的形式获得集成结果
https://stackoverflow.com/questions/2966193
复制相似问题