LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
楼主: pupilzeng

求定积分有什么好的算法吗?

[复制链接]
发表于 2003-10-28 22:37:13 | 显示全部楼层
It turn out that the equation I show above can satisfy all condition. It can converge with all z from minus infinite to infinite.

So done.

Of course, while |z| is very large, n should be very large too. :p
发表于 2003-10-28 22:45:44 | 显示全部楼层
一次把区间分成10个试试
20,30,50,100...
再求面积
PS: 求导数甚么方法较好?
发表于 2003-10-28 23:03:52 | 显示全部楼层

PS: 求导数甚么方法较好?

f'=df/dx
发表于 2003-10-28 23:18:02 | 显示全部楼层
Though the result is very small, you have to deal with large number. You should use some skill.
Integral can be another way.

I can write a funtion for you if you want.
 楼主| 发表于 2003-10-29 00:54:29 | 显示全部楼层
最初由 lordbyorn 发表
Though the result is very small, you have to deal with large number. You should use some skill.
Integral can be another way.

I can write a funtion for you if you want.


谢谢,如果不占用你很多时间的话,那就请你写给我吧。
:thank :thank
发表于 2003-10-29 12:23:43 | 显示全部楼层
What is the max |z| do you want? If you just want to calculate some value, you don't have to create table.
发表于 2003-10-29 13:40:16 | 显示全部楼层
How about this:


  1. #include<stdio.h>
  2. #include<math.h>
  3. #define TERM 30
  4. main(int argc,char ** argv){
  5. double x,y;
  6. int c;
  7. double tmp;
  8. double poly[TERM];
  9. sscanf(argv[1],"%lf",&x);
  10. poly[0]=x;
  11. y=0;
  12. for(c=1;c<TERM;c++){
  13.         tmp=x*x/(c*2);
  14.         poly[c]=poly[c-1]*tmp;
  15.         }
  16. for(c=1;c<TERM;c++){
  17.         poly[c]=poly[c]/(2*c+1);
  18.         }
  19. for(c=1;c<TERM;c+=2){
  20.         poly[c]=-poly[c];
  21.         }
  22. printf("x=%lf\n",x);
  23. for(c=0;c<TERM;c++){
  24.         y+=poly[c];
  25.         }
  26. y=0.5+0.39894228*y;
  27. printf("y=%lf\n",y);
  28. return 0;
  29. }
  30.                                                                                                                
  31. ~
复制代码
发表于 2003-10-29 13:46:50 | 显示全部楼层
f:=dy/dx不够精确,I like some cool methods
发表于 2003-10-29 13:54:59 | 显示全部楼层
With very little improvement


  1. #include<stdio.h>
  2. #include<math.h>

  3. #define TERM 100
  4. #define CONST 0.39894228

  5. main(int argc,char ** argv){
  6. double x,y;
  7. int c;
  8. double tmp;
  9. double poly[TERM];
  10. sscanf(argv[1],"%lf",&x);
  11. poly[0]=x;
  12. y=0;
  13. for(c=1;c<TERM;c++){
  14.         tmp=x*x/(c*2);
  15.         poly[c]=poly[c-1]*tmp;
  16.         }
  17. for(c=1;c<TERM;c++){
  18.         poly[c]=poly[c]/(2*c+1);
  19.         }
  20. for(c=0,tmp=1;c<TERM;c++){
  21.         y+=poly[c]*tmp;
  22.         tmp*=-1;
  23.         }
  24. y=0.5+CONST*y;
  25. printf("y=%lf\n",y);
  26. return 0;
  27. }
复制代码
发表于 2003-10-29 14:15:06 | 显示全部楼层
Good job. fast, accurate.


  1. #include<stdio.h>
  2. #include<math.h>
  3. #define TERM 100

  4. double poly[TERM];

  5. double zhentai(double x);

  6. main(int argc,char ** argv){
  7. double z,step;
  8. for(z=0,step=0.0001;z<=3.0;z+=step){
  9. printf("z=%lf,y=%lf\n",z,zhentai(z));
  10. }

  11. return 0;
  12. }

  13. double zhentai(double x){
  14. double y;
  15. int c;
  16. double tmp;
  17. poly[0]=x;
  18. y=0;
  19. for(c=1;c<TERM;c++){
  20.         tmp=x*x/(c*2);
  21.         poly[c]=poly[c-1]*tmp;
  22.         }
  23. for(c=1;c<TERM;c++){
  24.         poly[c]=poly[c]/(2*c+1);
  25.         }
  26. for(c=0,tmp=1;c<TERM;c++){
  27.         y+=poly[c]*tmp;
  28.         tmp*=-1;
  29.         }
  30. y=0.5+0.39894228*y;
  31. return y;
  32. }

复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表