要知道,你要拟合的是分段函数,它本身并不是一般的连续光滑函数。
nlinfit之所以要有初值,是考虑到在某些异常情况下,找不到最小二乘函数的最小值,可能是局部最小值,也可能根本找不到,所以需要通过改变迭代初值进行实验。对于这种分段函数,最好的方法是分段拟合。
fun1inlin:0.1:50
v
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
四.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.1524.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]
abcnlinfit(t,v,fun,[518910.000830.0001312050])
坚持住
f@(t)(fun(abc,t))
fplot(f,[0,50],r)
先确定对称轴,再确定极点、开口方向、与两个坐标轴的交点、连线。