Closed. This question needs details or clarity。它当前不接受答案。












想改善这个问题吗?添加详细信息,并通过editing this post阐明问题。

5年前关闭。



Improve this question




我正在编写一个代码,计算一个函数的积分,该函数具有两个部分,并且分别计算积分。但是编译后出现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/

10-13 02:29