c - 如何计算c中的微分系数

标签 c math numerical-methods derivative differentiation

感谢很多人到目前为止的帮助,但我犯了一个很大的错误,我需要在特定点推导函数!

我必须计算函数的一阶导数,但我真的不知道如何实现。如果我只需要计算一个只有 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/

相关文章:

c - 如何通过给出行的坐标将行的内容复制到字符串中

Python 飞行距离和时间计算器

math - 正弦函数在哪里?

r - 为什么 NaN^0 == 1

python - 比较 Python 中的(函数的)求根算法

c - AltBeacon - 从自定义字节数据创建

c - Valgrind 在二维数组中读取 1 的大小无效

我可以使用 main 中 argc 的地址作为随机源吗?

python - 方程组的 fsolve、brentq 和 root 在使用和精度上有什么区别?

algorithm - 符号与数值数学 - 性能