奇异点的高斯积分c++程序

奇异点的高斯积分c++程序,第1张

#include <stdio.h>伍携橡

#include <math.h>

#define N 3

float gauss(float(*)(float), float, float, int)

void main( )

{

float function_name(float)

float a, b

printf ("请输隐或入腔旁积分上限b\n")

scanf("%f", &b)

printf("请输入积分下限a\n")

scanf("%f", &a)

float ans

ans=gauss(function_name, a, b, N)

printf("ans=%f", ans)

}

float gauss(float(*func)(float x), float a, float b, int n )/*高斯求积*/

{

/*高斯点及其求积系数列表*/

float x1[1]={0.0}

float A1[1]={2}

float x2[2]={-0.5573503, 0.5573503}

float A2[2]={1, 1}

float x3[3]={-0.7745967, 0.0, 0.7745967}

float A3[3]={0.555556, 0.888889, 0.555556}

float x4[4]={0.3399810, -0.3399810, 0.8611363, -0.8611363}

float A4[4]={0.6521452, 0.6521452, 0.3478548, 0.3478548}

float x5[5]={0.0, 0.5384693, -0.5384693, 0.9061799, -0.9061799}

float A5[5]={0.5688889, 0.4786287, 0.4786287, 0.2369269, 0.2369269}

float *p, *t

switch (n)

{

case 1:

p=x1

t=A1

break

case 2:

p=x2

t=A2

break

case 3:

p=x3

t=A3

break

case 4:

p=x4

t=A4

break

case 5:

p=x5

t=A5

break

default:

printf ("intput wrong!")

}

float g

int i

for (i=0,g=0i<ni++){

g+=(*func)((b-a)*p[i]/2+(a+b)/2)*t[i]

}

g*=(b-a)/2

return g

}

float function_name(float x)

{

return (sqrt(4-x*x))

}

不好意思,没弄懂什么是三配慧点高磨茄斯法,所以手动给你算了一下,1+sin(4*x)*exp(-x)求积分瞎卖察的结果是:

x-e^(-x)/17*(sin(4*x)+4*cos(4*x))+C

然后把0和1代人计算得到结果:

1.3082506


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12405477.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存