matlab中的曲线拟合和参数估计

时间:2014-02-24 17:40:16

标签: matlab mathematical-optimization curve-fitting

我有matlab输出函数和输出曲线特征,我想从输出曲线特征中获取估计参数值,如何使用曲线拟合工具框获得95%置信度值

以下是输出功能

function c_t = output_function_conv(t, a1, a2, a3,b1,b2,b3,td, tmax,k1,k2,k3)

K_1   = (k1*k2)/(k2+k3);
K_2   = (k1*k3)/(k2+k3);

c_t = zeros(size(t));

ind = (t > td) & (t < tmax);

c_t(ind)= conv(
    ((t(ind) - td) ./ (tmax - td) * (a1 + a2 + a3)),
    (K_1*exp(-(k2+k3)*t(ind)+K_2)),'same');

ind = (t >= tmax);

c_t(ind)= conv(
    (a1 * exp(-b1 * (t(ind) - tmax))+ a2 * exp(-b2 * (t(ind) - tmax))) + a3 * exp(-b3 * (t(ind) - tmax)),
    (K_1*exp(-(k2+k3)*t(ind)+K_2)),'same');

plot(t,c_t);
end

以下是我手动分配的输入值

output_function_conv(0:0.01:50,2501,18500,65000,0.9,0.2,0.5,0.7,0.3,0.036,0.02,0.12)

我想估计输出函数特征图的95%置信度值。

请告诉我如何进行估算

以下是曲线拟合的数据点

Output [ 0            0            21292.6393733205         20834.1763999840         20385.7118816737   19947.0305575470    19517.9214023497    19098.1775712551    18687.5963435309    18285.9790651943    17893.1310908080    17508.8617245528    17132.9841607124    16765.3154236868    16405.6763076516    16053.8913159642    15709.7886004177    15373.1999004294    15043.9604822502    14721.9090782703    14406.8878264928    14098.7422102414    13797.3209981621    13502.4761845740    13214.0629302211    12931.9395034707    12655.9672220004    12386.0103950142    12121.9362660198    11863.6149562013    11610.9194084135    11363.7253318255    11121.9111472338    10885.3579330675    10653.9493721007    10427.5716988901    10206.1136479486    9989.46640266844    9777.52354500148    9570.18100590553    9367.33701656270    9168.89206037408    8974.74882573439    8784.81215958863    8598.98902177138    8417.18844012873    8239.32146642148    8065.30113300742    7895.04241029970    7728.46216499746    7565.47911908413    7406.01380958819    7249.98854910055    7097.32738704227    6947.95607167558    6801.80201285096    6658.79424548257    6518.86339374380    6381.94163597454    6247.96267029150    6116.86168089246    5988.57530504527    5863.04160075221    5740.20001507995    5619.99135314564    5502.35774774896    5387.24262964033    5274.59069841522    5164.34789402439    5056.46136888997    4950.87946061717    4847.55166529148    4746.42861135114    4647.46203402467    4550.60475032357    4455.81063457978    4363.03459451807    4272.23254785336    4183.36139940305    4096.37901870450    4011.24421812800    3927.91673147547    3846.35719305551    3766.52711722518    3688.38887838929    3611.90569144786    3537.04159268280    3463.76142107467    3392.03080004070    3321.81611958540    3253.08451885496    3185.80386908720    3119.94275694843    3055.47046824929    2992.35697203117    2930.57290501549    2870.08955640789    2810.87885304966    2752.91334490887    2696.16619090368    2640.61114505071    2586.22254293112    2532.97528846746    2480.84484100443    2429.80720268671    2379.83890612722    2330.91700235940    2283.01904906694    2236.12309908497    2190.20768916629    2145.25182900688    2101.23499052463    2058.13709738563    2015.93851477229    1974.62003938789    1934.16288969200    1894.54869636156    1855.75949297240    1817.77770689617    1780.58615040766    1744.16801199767    1708.50684788667    1673.58657373467    1639.39145654262    1605.90610674094    1573.11547046102    1541.00482198505    1509.55975637042    1478.76618224438    1448.61031476500    1419.07866874474    1390.15805193257    1361.83555845114    1334.09856238523    1306.93471151803    1280.33192121178    1254.27836842933    1228.76248589333    1203.77295637992    1179.29870714364    1155.32890447051    1131.85294835633    1108.86046730722    1086.34131325951    1064.28555661621    1042.68348139733    1021.52558050131    1000.80255107504    980.505289989895    960.624889421189    941.152632528815    910.093552396909    880.074844716944    851.060744250693    823.016766773700    795.909660251508    769.707358052245    744.378934099714    719.894559876329    696.225463190064    673.343888624288    651.223059593511    629.837141932191    609.161208947531    589.171207870732    569.843927644531    551.156967988015    533.088709682665    515.618286026374    498.725555404831    482.391074932134    466.596075114855    451.322435495995    436.552661237327    422.269860600652    408.457723290306    395.100499621077    382.182980477300    369.690478030556    357.608807184818    345.924267719382    334.623627101217    323.694103939659    313.123352057611    302.899445154510    293.010862037469    283.446472397999    274.195523112734    265.247625047485    256.592740344874    248.221170176634    240.123542942462    232.290802898093    224.714199195994    217.385275322762    210.295858918002    203.438051960061    196.804221304642    190.386989562840    184.179226305776    178.174039583434    172.364767745896    166.744971555592    161.308426579671    156.049115852013    150.961222794856    146.039124390369    141.277384592926    136.670747973167    132.214133585317    127.902629049538    123.731484841434    119.696108781123    115.792060714591    112.015047380319    108.360917454464    104.825656768093    101.405383690273    98.0963446710064    94.8949099382621    91.7975693435645    88.8009283507997    85.9017041631206    83.0967219830068    80.3829114007349    77.7573029066858    75.2170245230854    72.7592985509469    70.3814384281314    68.0808456946014    65.8550070610841    63.7014915775029    61.6179478976678    59.6021016368462    57.6517528189581    55.7647734102607    53.9391049364990    52.1727561806128    50.4638009581927    48.8103759679823    47.2106787148207    45.6629655025121    44.1655494942032    42.7167988379332    41.3151348551059    39.9590302897151    38.6470076162314    37.3776374041319    36.1495367371296    34.9613676852239    33.8118358277656    32.6996888257886    31.6237150419265    30.5827422062891    29.5756361267334    28.6012994420155    27.6586704163679    26.7467217740917    25.8644595728099    25.0109221140670    24.1851788900145    23.3863295649593    22.6135029905981    21.8658562538011    21.1425737558466    20.4428663220491    19.7659703407560    19.1111469307271    18.4776811359438    17.8648811469268    17.2720775476747    16.6986225873647    16.1438894759878    15.6072717031179    15.0881823790414    14.5860535975035    14.1003358193474    13.6304972763527    13.1760233945998    12.7364162367108    12.3111939623395    11.8998903063055    11.5020540737853    11.1172486519962    10.7450515378264    10.3850538808823    10.0368600414446    9.70008716283935    9.37436475774730    9.05933430799276    8.75464887736619    8.45997273705098    8.17498100323961    7.89935928653744    7.63280335276621    7.37501879479276    7.12572071502023    6.88463341819175    6.65149011416815    6.42603263035222];

输入功能值:

input = [
10      -1          1
20      17956   1
30      61096   1
40      31098   1
50      18446   1
60      12969   1
95      7932    1
120     6213    1
188     4414    1
240     3310    1
300     3329    1
610     2623    1
1200    1953    1
1800    1617    1
2490    1559    1
3000    1561    1
3635    1574    1
4205    1438    1
4788    1448    1
];
calibrationfactor_wellcounter =1.841201569;

上述值的输入函数校准如下

function c = Input_function(t, a1, a2, a3, b1, b2, b3, td, tmax)

...some code to model the input function from the Above vector Input

 Plot(t,c);

1 个答案:

答案 0 :(得分:1)

我假设您想要对函数f(t; a,b,c,d,e,f)=y进行线性拟合(单输入 - >单输出)。在这里,t是您的输入,y是您的输出。现在,您有一组数据点,就像这样

data = [t1 ,y1;
        t2, y2;
        t3, y3;
        ......];

如果您scatter(data(:,1),data(:,2)),您应该能够看到您的数据点分布。通过数据拟合,您将估算最小化曲线与数据点之间距离的参数a,b,c,d,e,f。我认为MATLAB通常使用最小二乘法。现在定义辅助函数以提供给MATLAB的数据拟合例程

F = @(x,xdata) f(xdata, x(1),x(2),x(3),x(4),x(5),x(6) );

请注意,我们刚刚重新定义了a=x(1),b=x(2),依此类推。然后定义您的初始猜测x0并进行非线性最小二乘拟合

x0 = [1 1 1 1 1 1];
[x,resnorm,~,exitflag,output] = lsqcurvefit(F,x0,data(:,1),data(:,2))

您可能需要调整初始猜测,收敛条件等,但如果成功,则会在向量a,b,c,d,e,f中获得x值。所以,你可以绘制

scatter(data(:,1),data(:,2))
hold on
plot(data(:,1),F(x,data(:,1));
hold off

你应该能够看到你的数据点和你的曲线。

您需要做的就是修改output_function_conv,以便每个t值获得一个c_t值,因为现在您的函数似乎返回了一个向量。此外,您的初始猜测和收敛标准对于使最小平方收敛非常重要。

参考:http://www.mathworks.com/help/optim/examples/nonlinear-data-fitting.html