c - 数值积分法、中点、误差、C 代码

标签 c compiler-errors syntax-error integration

我正在编写计算函数积分的代码,该函数有两个部分,并且积分是单独计算的。但编译后出现3个错误。请帮忙...

#define I = 0.0225; W = 50000; L = 25; Y = 12000; E = 72*pow(10,9);
#include <stdio.h>
typedef double (*DfD) (double);
double g(double);
double h(double);

double g(double x)
return W*x*(x-L/2)-(Y*pow(x,3))/2   //error: expected declaration specifiers before 'return'
double h(double x)
return (Y*pow(x,3))/2

double midpoint_int(DfD f,
             double x0, double x1, int n)
{   int i;
double x, dx, sum = 0.0;
dx = (x1-x0)/n;
for (i = 0, x = x0 + dx/2; i < n; i ++, x +=dx)
    sum += f(x);
return sum*dx;
}

int main (void){  //error: expected ',', '=', ';' before  '{' token
double int1
double int2
double deflcetion ;
int1 = midpoint_int(g, L/2, L, 1000);
int2 = midpoint_int(h, 0, L/2, 1000);
deflection = 1/EI * (int1 - int2);
return 0
}   //error: expected '{' at the end of input

最佳答案

我已尝试纠正一些错误

#include <stdio.h>
I = 0.0225;
W = 50000;
L = 25;
Y = 12000;
E = 72*pow(10,9);

typedef double (*DfD) (double);
double g(double);
double h(double);

double g(double x){
    return W*x*(x-L/2)-(Y*pow(x,3))/2;
}   
double h(double x){
    return (Y*pow(x,3))/2;
}

double midpoint_int(DfD f, double x0, double x1, int n)
{
    int i;
    double x, dx, sum = 0.0;
    dx = (x1-x0)/n;
    for (i = 0, x = x0 + dx/2; i < n; i ++, x +=dx)
        sum += f(x);
    return sum*dx;
}

int main (void){  
    double int1;
    double int2;
    double deflcetion ;
    int1 = midpoint_int(g, L/2, L, 1000);
    int2 = midpoint_int(h, 0, L/2, 1000);
    deflcetion = 1/E*I * (int1 - int2);
    return 0;
}

关于c - 数值积分法、中点、误差、C 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29502706/

相关文章:

c - 如何将大十六进制插入 BLOB 列?

c - 计算点与多个面之间最小距离的有效方法

c - NCURSES - 在 pad 中移动光标

C#.NET : Is it possible to create compile time warnings when property is set to invalid values?

php - 为什么构造对象时不能使用它?

postgresql - 通过连接 PostgreSQL 中的列进行更新

c - 如何使用 goto 代替 for、while 或 switch

macos - 在 OSX 上安装 Go 时出现 Ld 错误

java - 使用堆栈声明编译错误

android - 查询联系人数据库中的电子邮件时出现语法错误