gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 20:13:36 27 4
gpt4 key购买 nike

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com