赞
踩
你要知道,你要拟合的是一个分段函数,这本身就不是一般的连续光滑函数。
nlinfit之所以要有初值这一项,就是考虑到在某些变态的情况下,无法找到最小二乘函数的最小值,可能是一个局部的最小值,也可能根本找不到,所以有必要通过改变迭代初值的方法进行试验。对于这种分段函数,最好的方法还是分段拟合。
fun1=inline('4.213-300*x/ref(1)-300*(ref(2)+ref(3))+300*ref(3)*exp(-x/(ref(3)*ref(4)))','ref','x');
fun2=inline('4.213-3000/ref(1)-300*ref(3)*exp(-x/(ref(3)*ref(4)))*(exp(10/(ref(3)*ref(4)))-1)','ref','x');
fun=@(ref,t)((t<=10).*fun1(ref,t)+(t>10).*fun2(ref,t));
t=0:0.1:50;
v=[3.969
3.963
3.959
3.955
3.952
3.949
3.947
3.945
3.943
3.941
3.939
3.938
3.936
3.935
3.933
3.932
3.93
3.929
3.928
3.927
3.926
3.925
3.923
3.922
3.921
3.92
3.919
3.918
3.917
3.916
3.915
3.914
3.913
3.912
3.911
3.91
3.909
3.908
3.907
3.907
3.906
3.905
3.904
3.903
3.903
3.902
3.901
3.9
3.9
3.899
3.898
3.898
3.897
3.896
3.896
3.895
3.894
3.893
3.893
3.892
3.891
3.891
3.89
3.889
3.889
3.888
3.888
3.887
3.887
3.886
3.886
3.885
3.884
3.884
3.883
3.882
3.882
3.881
3.88
3.88
3.879
3.879
3.878
3.878
3.877
3.877
3.876
3.876
3.875
3.875
3.874
3.874
3.873
3.873
3.872
3.872
3.871
3.87
3.87
3.869
3.869
4.105
4.108
4.11
4.112
4.114
4.115
4.116
4.117
4.118
4.119
4.119
4.12
4.12
4.121
4.122
4.122
4.123
4.123
4.124
4.124
4.124
4.125
4.125
4.126
4.126
4.126
4.127
4.127
4.128
4.128
4.129
4.129
4.129
4.129
4.129
4.13
4.13
4.13
4.13
4.13
4.131
4.131
4.131
4.131
4.132
4.132
4.132
4.132
4.132
4.132
4.133
4.133
4.133
4.133
4.133
4.134
4.134
4.134
4.134
4.134
4.134
4.135
4.135
4.135
4.135
4.135
4.136
4.136
4.136
4.136
4.136
4.137
4.137
4.138
4.138
4.138
4.139
4.139
4.139
4.139
4.139
4.14
4.14
4.14
4.14
4.14
4.14
4.14
4.14
4.14
4.14
4.14
4.14
4.14
4.14
4.14
4.14
4.14
4.14
4.14
4.14
4.14
4.14
4.14
4.14
4.141
4.141
4.141
4.141
4.141
4.141
4.141
4.141
4.141
4.141
4.142
4.142
4.142
4.142
4.142
4.142
4.142
4.142
4.142
4.142
4.143
4.143
4.143
4.143
4.143
4.143
4.143
4.143
4.143
4.143
4.143
4.143
4.143
4.144
4.144
4.144
4.144
4.144
4.144
4.144
4.144
4.144
4.144
4.144
4.145
4.145
4.145
4.145
4.145
4.145
4.145
4.145
4.145
4.145
4.145
4.145
4.145
4.145
4.145
4.145
4.146
4.146
4.146
4.146
4.146
4.146
4.146
4.146
4.146
4.146
4.146
4.146
4.146
4.147
4.147
4.147
4.147
4.147
4.147
4.147
4.147
4.147
4.147
4.147
4.147
4.147
4.147
4.147
4.148
4.148
4.148
4.148
4.148
4.148
4.148
4.148
4.148
4.148
4.148
4.148
4.148
4.148
4.148
4.148
4.148
4.149
4.149
4.149
4.149
4.149
4.149
4.149
4.149
4.149
4.149
4.149
4.149
4.149
4.149
4.149
4.149
4.15
4.15
4.15
4.15
4.15
4.15
4.15
4.15
4.15
4.15
4.15
4.15
4.15
4.15
4.15
4.15
4.15
4.15
4.15
4.15
4.151
4.151
4.151
4.151
4.151
4.151
4.151
4.151
4.151
4.151
4.151
4.151
4.151
4.151
4.151
4.151
4.151
4.151
4.151
4.151
4.151
4.152
4.152
4.152
4.152
4.152
4.152
4.152
4.152
4.152
4.152
4.152
4.152
4.152
4.152
4.152
4.152
4.152
4.152
4.152
4.152
4.152
4.152
4.152
4.153
4.153
4.153
4.153
4.153
4.153
4.153
4.153
4.153
4.153
4.153
4.153
4.153
4.153
4.153
4.153
4.153
4.153
4.153
4.153
4.153
4.153
4.153
4.153
4.154
4.154
4.154
4.154
4.154
4.154
4.154
4.154
4.154
4.154
4.154
4.154
4.154
4.154
4.154
4.154
4.154
4.154
4.154
4.154
4.154
4.154
4.154
4.154
4.154
4.154
4.155
4.155
4.155
4.155
4.155
4.155
4.155
4.155
4.155
4.155
4.155
4.155
4.155
4.155
4.155
4.155
4.155
4.155
4.155
4.155
4.155
4.155
4.155
4.155
4.155
4.155
4.155
4.155
4.156
4.156
4.156
4.156
4.156
4.156
4.156
4.156
4.156
4.156
4.156
4.156
4.156
4.156
4.156
4.156
4.156
4.156
4.156
4.156
4.156
4.156
4.156
4.156
4.156
4.156
4.156
4.156
4.156
4.156
4.156
4.156];
abc=nlinfit(t',v,fun,[51891 0.00083 0.00013 12050]');
plot(t,v);hold on;
f=@(t)(fun(abc,t));
fplot(f,[0,50],'r')
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。