Skip to content

Commit 61f3ae1

Browse files
lxb1226lxb1226
lxb1226
authored and
lxb1226
committed
第五次数值分析作业
1 parent d28644d commit 61f3ae1

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

Diff for: simpson.c

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// Created by heyjude on 18-10-25.
3+
//
4+
5+
#include<stdio.h>
6+
#include<math.h>
7+
8+
//float f(float x);
9+
//
10+
//int main(void){
11+
// float b=2.0,a=0.0;
12+
// int m=5;
13+
// float h=(b-a)/(2*m);
14+
// int i;
15+
// float sum=0;
16+
// for(i=1;i<=m;i++){
17+
// sum+=4*f(a+h*(2*i-1))+2*f(a+2*i*h);
18+
//
19+
// }
20+
// sum=h/6*(f(a)+f(b)+sum);
21+
// printf("sum = %f\n",sum);
22+
// return 0;
23+
//}
24+
//
25+
//float f(float x){
26+
// return sin(x)*exp(-x*x);
27+
//}

Diff for: tixing.c

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include<stdio.h>
2+
#include<math.h>
3+
4+
double f(float x);
5+
6+
int main(void){
7+
int M=10;
8+
int i;
9+
float b=2.0,a=0.0;
10+
float h;
11+
double sum=0;
12+
h=(b-a)/M;
13+
printf("h = %f\n",h);
14+
for(i=1;i<=M-1;i++){
15+
sum+=f(a+i*h);
16+
}
17+
sum=h/2*(f(a)+f(b)+2*sum);
18+
printf("sum = %f",sum);
19+
return 0;
20+
}
21+
double f(float x){
22+
23+
return sin(x)*exp(-x*x);
24+
25+
}

0 commit comments

Comments
 (0)