2016-03-28 51 views
0

我有一組實驗點適合模擬到具有多個擬合參數

Xdata=[xd1 xd2...] 

Ydata=[yd1 yd2...] 

和一function y=myfunction(xsimul,a,b,c)間接模擬數據:

Ysimul=[ys1 ys2...] 

用於Xsimul=Xdata

通過間接我的意思是沒有直接計算y =函數(x,a,b,c)。它通過最小化另一個函數g = f(z)(使用fminsearch)跟隨Ysimul =(g(targetvalue))而在兩個for循環內獲得。

目標是將模擬擬合到實驗數據中,並通過最小二乘法檢索最佳的a,b和c值。 我可以對參數給出一個很好的初始猜測。然而,具有3個擬合參數以及確定Ysimul已經很大的計算時間使得這個問題非常麻煩。 所以我想知道的是:

這個問題是否可行使用像lsqcurvefit函數? 如果是這樣,你能提供關於如何去做的提示嗎?

+0

要在這裏確認:'Xdata'和'Ydata'是相同大小的載體? 'a','b'和'c'是標量?目標是找到'a','b'和'c'的最佳估計值以適應所提供的數據? – Pursuit

+0

是Xdata和Ydata大小相等,a,b,c是要估計的標量。我應該指出的。並感謝您的快速回復!我會嘗試基於你的提示來實現這個算法 – BMST

回答

0

只是解決方案

這是一個非常標準的使用lsqnonlin,你只需要得到它正確格式化。這意味着這樣的事情:

%First, define a function whose inputs are a single vector, and whose 
%outputs can be minimized 
funToMinimize = @(abc) myfunction(Xdata,abc(1), abc(2), abc(3)) - Ydata; 

%Define an initial guess of the values (including the size of the vector) 
abcInitial = [0 0 0]; %Or whatever your best guess is 

%Then use the nonlinear fit 
abcFit = lsqnonlin(funToMinimize , abcInitial); 

示範

我顯然不能產生一個解決您的myfunction問題,但我們還是可以通過的重要步驟走。

首先,我們定義一個函數來模擬您的myfunction,XdataYdata

%Define some complicated-ish "myfuction", with inputs that match yours 
myfunction = @(xsimul, a, b, c) sqrt(abs(xsimul))*a + sin(xsimul)*b*a^2 + c; 
%Define "Xdata" 
Xdata = linspace(0,10,100); 
%Define "Ydata", note that I'm sneaking in a set of (a, b, c) values here 
Ydata = myfunction(Xdata, 1, 2, 3); 

現在,讓我們運行在上面的答案的步驟:

funToMinimize = @(abc) myfunction(Xdata,abc(1), abc(2), abc(3)) - Ydata; 
abcInitial = [0 0 0]; 
abcFit = lsqnonlin(funToMinimize , abcInitial) 

最後一步應該返回[1 2 3],匹配(A,B,C)用於生成Ydata值。