MATLAB Answers

Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#" onclick="window._kiq.push(['set', { 'event': 'Turn off MT' }]);">ここ</a>」をクリックしてください。

0

How to run lsqcurvefit with a function handle with 2 array-variables?

Robert Vigil さんによって質問されました 2019 年 3 月 7 日
最新アクティビティ Torsten
さんによって コメントされました 2019 年 3 月 11 日
For an easy reference I placed a provided Mathworks example below.
xdata = [0.9 1.5 13.8 19.8 24.1 28.2 35.2 60.3 74.6 81.3];
ydata = [455.2 428.6 124.1 67.3 43.2 28.1 13.1 -0.4 -1.3 -1.5];
fun = @(x,xdata)x(1)*exp(x(2)*xdata);
x0 = [100,-1];
x = lsqcurvefit(fun,x0,xdata,ydata)
I'll start off by mentioning that I am unfamiliar with creating a function handle with an array as a variable as you see with "xdata" which partially leads to my confusion. My issue is that my function has an additional array variable. "k" are my coefficients I'm solving for using lsqcurvefit while "C_TBA_H2O," "C_H2O" are arrays of data points. My x-axis for evaluation is in terms of "C_TBA_H2O." Any clarification or explanation on how to set this up would be greatly appreciated.
rao_H2O = @(k, C_TBA_H2O, C_H2O) k(1)*k(2)*C_TBA_H2O/(1+k(2)*C_TBA_H2O+(k(2)*C_H2O)^gamma(2))+k(3)*C_TBA_H2O;
K = lsqcurvefit(rao_H2O,guess,C_TBA_H2O,rao_norm)
My error:
Error in Lab3_155 (line 17)
K = lsqcurvefit(rao_H2O,guess,C_TBA_H2O,rao_norm)
Caused by:
Failure in initial objective function evaluation. LSQCURVEFIT cannot continue.

  0 件のコメント

サインイン to comment.

2 件の回答

回答者: Torsten
2019 年 3 月 7 日
編集済み: Torsten
2019 年 3 月 7 日

rao_H2O = @(k,x) k(1)*k(2)*C_TBA_H2O./(1+k(2)*C_TBA_H2O+(k(2)*C_H2O).^gamma(2))+k(3)*C_TBA_H2O;
xdata = zeros(size(rao_norm));
ydata = rao_norm;
K = lsqcurvefit(rao_H2O,guess,xdata,ydata);
Even
xdata = [];
might work, but I'm not 100% sure.
Best wishes
Torsten.

  2 件のコメント

No because you overwrote my "xdata" to be array of zeros which is weird.
Torsten
2019 年 3 月 11 日
Since you don't use "xdata" in the definition of "rao_H2O", the array is not necessary for your fitting task.

サインイン to comment.


回答者: Robert Vigil 2019 年 3 月 8 日

I figured out my issue. It was the lack of use of periods when multiplying or dividing arrays.

  0 件のコメント

サインイン to comment.



Translated by