感谢很多人到目前为止的帮助,但我犯了一个很大的错误,我需要在特定点推导函数!
我必须计算函数的一阶导数,但我真的不知道如何实现。如果我只需要计算一个只有 X^1 的函数,我会知道如何计算,但我真的被困在这里了。
旧的东西:
函数可以类似于 2*x^2+1
。
该方法必须如下所示:double ab(double (f)(double),double x)
我的教授暗示我们可能应该使用这个函数:
(f(x0+Δx)−f(x0))/((x0+Δx)−x0)
。
抱歉我的英语不好,感谢您提前提供任何提示或提示。
最佳答案
此示例将帮助您入门:
#include<stdio.h>
#include <stdlib.h>
float func(float x)
{
return(2*x*x + 1);
}
int main(){
float h=0.01;
float x;
float deriv, second;
printf("Enter x value: ");
scanf("%f", &x);
// derivative at x is the slope of infinitely small
// line of the function
deriv = (func(x+h) - func(x))/h; // I assumed the length to be h
//for second derivative you can use:
second = (func(x+h) - 2*func(x) + func(x-h))/(h*h);
printf("%f\n", deriv);
return 0;
}
关于c - 如何计算c中的微分系数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25052907/