- UID
- 23593
- 好友
注册时间2009-1-8
威望值 点
最后登录1970-1-1
激情值 点
积分27
认证分 分
齿轮币 枚
回帖0
|
本帖子中包含更多资源。
您需要 登录 才可以下载或查看,没有账号?注册
x
本帖最后由 ryen.chen 于 2009-5-7 19:30 编辑
- #include<iostream.h>
- #include<math.h>
- #include<conio.h>
- double AInv(double y, double e);
- void main()
- {
- double x, y;
- cout<<"Input y (>0): ";
- cin>>y;
- x = AInv(y, 0.000001);
- if (x<0) cout<<"Failed after 100 iterations!"<<endl;
- else cout<<"ainv("<<y<<") = "<<x<<endl;
- getch();
- }
- double AInv(double y, double e)
- {
- double x, maxX, minX;
- const double pi = 3.14159265358979;
- maxX = pi/2;
- minX = 0;
- for (int i=1;i<=100;i++)
- { x = (maxX + minX) / 2;
- if (maxX-x<e) return(x);
- if (y>tan(x) - x) minX = x;
- else maxX = x;
- cout<<minX<<", "<<maxX<<endl;
- }
- return(-1);
- }
复制代码 |
|