(x+1)^2=0的C++编法
- 提问者网友:南佳人~
- 2021-04-21 21:22
- 二级知识专家网友:情窦初殇
- 2021-04-21 22:55
ri。。。。。。我看你最近问的总是C或C++方面的问题哈
应该说用MATLAB是最好的
用二分法或者迭代都可以解出来
你看看上面用牛顿迭代法的程序
具体我没看
应该可以解出来
- 1楼网友:甜野猫
- 2021-04-22 01:25
#include <iostream.h> #include <math.h>
int main() { int x; x=sqrt(0)-1; cout<<x<<endl; }
- 2楼网友:悲观垃圾
- 2021-04-22 01:13
main()
{
int a=0;
int b,c;
c=b+1;
cout<<"x="<<c;
}
- 3楼网友:颜值超标
- 2021-04-22 00:25
你问的问题不是很清楚啊
- 4楼网友:两不相欠
- 2021-04-21 23:04
#include<iostream.h> #include<stdio.h> #include<math.h> #define f(x) ((x+1)*(x+1))//这里写原函数 #define g(x) (2*(x+1)) //这里写原函数的导数 #define x0 -2.0 //这里定义求解的区间[x0,x1] #define x1 1.0 #define MAXREPT 1e4//这里定义最大计算次数 #define epsilon 0.0001//这里定义计算精度 void main() { int i; double x_k=x0,x_k1=x1,x_k2=x1; cout<<"迭代开始:"<<endl; for(i=0;i<MAXREPT;i++) { cout<<"Got..."<<x_k2<<endl; x_k2=x_k1-f(x_k1)/g(x_k1); if(fabs(x_k2-x_k1)<epsilon) { cout<<"所得满足精度的解为:"<<endl; cout<<"!Root="<<x_k2<<endl; return; } x_k=x_k1;x_k1=x_k2; } cout<<"经过 "<<MAXREPT<<" 次迭代后,未达到所需精度要求"<<endl; } 运行结果如下:
迭代开始: Got...1 Got...0 Got...-0.5 Got...-0.75 Got...-0.875 Got...-0.9375 Got...-0.96875 Got...-0.984375 Got...-0.992188 Got...-0.996094 Got...-0.998047 Got...-0.999023 Got...-0.999512 Got...-0.999756 Got...-0.999878 所得满足精度的解为: !Root=-0.999939 Press any key to continue