在Matlab中输入:
x=[2 3 4 5 7 9 12 14 17 21 28 56];
y=[35 42 47 53 59 65 68 73 76 82 86 99]-0.5+1*rand(1,12);
plot(x,y,'*')
>> x=[2 3 4 5 7 9 12 14 17 21 28 56];
>> y=[35 42 47 53 59 65 68 73 76 82 86 99]-0.5+1*rand(1,12);
将
function f=fun(z,x)
f=z(1)+z(2)*log(x)
保存与fun.m文件中
>> z0=[5 5];
>> z=lsqcurvefit ('fun',z0,x,y)
f =
Columns 1 through 6
8.4657 10.4931 11.9315 13.0472 14.7296 15.9861
Columns 7 through 12
17.4245 18.1953 19.1661 20.2226 21.6610 25.1268
f =
Columns 1 through 6
8.4657 10.4931 11.9315 13.0472 14.7296 15.9861
Columns 7 through 12
17.4245 18.1953 19.1661 20.2226 21.6610 25.1268
f =
Columns 1 through 6
8.4657 10.4931 11.9315 13.0472 14.7296 15.9861
Columns 7 through 12
17.4245 18.1953 19.1661 20.2226 21.6610 25.1268
f =
Columns 1 through 6
18.6536 24.4369 28.5402 31.7230 36.5222 40.1068
Columns 7 through 12
44.2101 46.4088 49.1781 52.1921 56.2954 66.1820
f =
Columns 1 through 6
18.6536 24.4369 28.5402 31.7230 36.5222 40.1068
Columns 7 through 12
44.2101 46.4088 49.1781 52.1921 56.2954 66.1820
f = Columns 1 through 6
18.6536 24.4369 28.5402 31.7230 36.5222 40.1068
Columns 7 through 12
44.2101 46.4088 49.1781 52.1921 56.2954 66.1820
f =
Columns 1 through 6
34.8429 42.7115 48.2944 52.6248 59.1545 64.0316
Columns 7 through 12
69.6145 72.6060 76.3739 80.4746 86.0575 99.5090
f =
Columns 1 through 6
34.8429 42.7115 48.2944 52.6248 59.1545 64.0316
Columns 7 through 12
69.6145 72.6060 76.3739 80.4746 86.0575 99.5090
f =
Columns 1 through 6
34.8429 42.7115 48.2944 52.6248 59.1545 64.0316
Columns 7 through 12
69.6145 72.6060 76.3739 80.4746 86.0575 99.5090
f =
Columns 1 through 6
34.8429 42.7115 48.2944 52.6248 59.1545 64.0316
Columns 7 through 12
69.6145 72.6060 76.3739 80.4746 86.0575 99.5090
f =
Columns 1 through 6
34.8429 42.7115 48.2944 52.6248 59.1545 64.0316
Columns 7 through 12
69.6145 72.6060 76.3739 80.4746 86.0575 99.5090
f =
Columns 1 through 6
34.8429 42.7115 48.2944 52.6248 59.1545 64.0316
Columns 7 through 12
69.6145 72.6060 76.3739 80.4746 86.0575 99.5090
z =
21.3915 19.4064
f=21.3915+19.4064*log(x)
>> cftool(x,y)
General model Exp2:
f(x) = a*exp(b*x) + c*exp(d*x)
Coefficients (with 95% confidence bounds):
a = 73.71 (68.98, 78.44)
b = 0.005326 (0.003875, 0.006776)
c = -52.47 (-57.21, -47.72)
d = -0.1563 (-0.1973, -0.1153)
Goodness of fit:
SSE: 13.31
R-square: 0.9966
Adjusted R-square: 0.9954
RMSE: 1.29
由以上参数得知模型教符合数据的走型,由离散图与拟合图对比观察可知,所得到的回归模型与散点图能够比较接近,Coefficients (with 95% confidence bounds)故可得
z 1=21.3915 z2=19.4064
关系为:f=21.3915+19.4064*log(x) .
图形,请加我QQ进行发送,谢谢。QQ号码:68752271
验证消息 百度MATLAB编程
>> [x,min,flag]=fmincon('x+1/x',0.6,[],[],[],[],0.5,5)
运行结果:
x = 1.0000
min = 2.0000
flag = 5
可以用图解方法观察的。
>> ezplot('x+1/x',[0.5 5])