c++数值分析
1、
算法说明:
程序代码:
#include"iostream"//曲线拟合 #include"math.h" using namespace std; double shuangquxian(double x[], double y[]) { double a, b; double a1=0, a2=0, a3=0, a4=0; for (int i = 0; i < 16; i++) { a1 = a1 + y[i] / x[i]; a2 = a2 + 1 / x[i]; a3 = a3 + x[i] * x[i]; a4 = a4 + x[i] * y[i]; } a1 = a1 / 16; a2 = a2 / 16; a3 = a3 / 16; a4 = a4 / 16; //计算a a = a1 - a2 * (a1*a3 - a4) / (a2*a3 - 1); //计算b b = (a1*a3 - a4) / (a2*a3 - 1); return a, b; } void main() { double x[16] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 }; double y[16] = { 4.00,6.40,8.00,8.80,9.22,9.50,9.70,9.86,10.00, 10.20,10.32,10.42,10.50,10.55,10.58,10.60 }; double a, b; a,b=shuangquxian(x,y); }
x = [ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 ]; y = [ 4.00,6.40,8.00,8.80,9.22,9.50,9.70,9.86,10.00,10.20,10.32,10.42,10.50,10.55,10.58,10.60 ]; z = 0.880619*x+3.22091./x; z2 = 6.4462*exp(0.0400316*x); plot(x,y,'*r',x,z2,'*b'); plot(x,y,'*r',x,z,'*b');
运行结果:
2、
算法说明:
程序代码:
运行结果:
3、
算法说明:
程序代码:
运行结果:
4、
算法说明:
程序代码:
运行结果: