|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
实验测得两组数据,要用下面这个函数
y=x(1)*trapz(t,exp(-abs((xdata*1e-15-t)/x(2))).*exp(-3*log(2)*(t/x(3)).^2)),t=(linspace(-200e-15,200e-15,3000))'
进行拟合,程序如下:
function f=onewfit(x,xdata)
t=(linspace(-200e-15,200e-15,3000))';
f1w=exp(-abs((xdata*1e-15-t)/x(2))).*exp(-3*log(2)*(t/x(3)).^2);
f=x(1)*trapz(t,f1w);
xdata=-28.07
-26.733
-25.397
-24.06
-22.723
-21.387
-20.05
-18.713
-17.377
-16.04
-14.703
-13.367
-12.03
-10.693
-9.3567
-8.02
-6.6833
-5.3467
-4.01
-2.6733
-1.3367
0
1.3367
2.6733
4.01
5.3467
6.6833
8.02
9.3567
10.693
12.03
13.367
14.703
16.04
17.377
18.713
20.05
21.387
22.723
24.06
25.397
26.733
28.07
29.407
30.743
32.08
33.417
34.753
36.09
37.427
38.763
40.1
41.437
42.773
44.11
45.447
46.783
48.12
49.457
50.793
52.13
53.467
54.803
56.14
57.477
58.813
60.15
61.487
62.823
64.16
65.497
66.833
68.17
69.507
70.843
72.18
73.517
74.853
76.19
77.527
78.863
80.2
81.537
82.873
84.21
85.547
86.883
88.22
89.557
90.893
92.23
93.567
94.903
96.24
97.577
98.913
100.25
101.59
ydata=3.542
4.3628
5.2718
6.0982
7.1
7.9064
9.1087
9.991
11.039
11.998
12.717
13.749
14.791
15.482
16.094
16.857
17.439
17.722
18.442
18.588
19.151
18.638
18.6
18.509
18.37
17.887
17.088
16.714
16.107
15.297
14.286
13.447
12.505
11.45
10.203
9.461
8.5291
7.3575
6.7977
5.9653
4.927
4.0811
3.5185
2.8233
2.213
1.4887
1.0284
0.87324
0.98524
0.72658
0.98301
0.8818
0.93085
0.93437
1.2345
1.1338
1.0784
1.1148
1.3607
1.2652
1.1519
1.1537
1.0809
1.0139
0.93833
0.91336
0.78025
0.83429
0.6424
0.78952
0.66733
0.52645
0.57302
0.54375
0.68102
0.59113
0.29401
0.53691
0.56787
0.57317
0.60167
0.49723
0.6663
0.39746
0.63391
0.64165
0.35578
0.37859
0.37817
0.34839
0.082668
0.15233
0.16759
0.37992
0.25172
0.30564
0.048891
1.9698
x0=[1e15,3,25];
[x,resnorm,residual]=lsqcurvefit(@onewfit,x0,xdata,ydata);
运行出现如下错误:
??? Error using ==> optim\private\lsqncommon
User supplied function failed with the following error:
Error using ==> unknown
Matrix dimensions must agree.
Error in ==> lsqcurvefit at 149
[x,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...
Error in ==> Onewlsqfit
[x,resnorm,residual]=lsqcurvefit(@onewfit,x0,xdata,ydata)
刚接触Matlab,实在找不出原因,请高手帮忙,先行谢过了。 |
|