Least square fitting of experimental data

4 ビュー (過去 30 日間)
Zine
Zine 2013 年 12 月 12 日
コメント済み: Zine 2013 年 12 月 14 日
I have experimantal data xdata,ydata; and I want to fit a model to these data, the model shape is like Y(xdata)=[A*exp(C*D/xdata)]/[E+F*exp(C*D/xdata)+...]; where Y should be very near to ydata (curve fitting), my problem is that the parameters A B C D... are function of xdata too with sub-parameters to be determined, I proceeded to write a huge function of sub-parameters but the process takes time of writing code and checking and if there is error it is difficult to locate it, so my question is : can I declare these parameters as parametric variables and how to do it if possible? and; is there other shortcut to bypass the long functions which increase the possibility of typing errors and facilitate the replacement of the variable function like I input A=exp(a-c); and if does not give good results I change easily to A=(1/d+e)?... thanks in advance

採用された回答

Alan Weiss
Alan Weiss 2013 年 12 月 12 日
編集済み: Alan Weiss 2013 年 12 月 12 日
If you have Symbolic Math Toolbox, you can use matlabFunction to generate your function handles or program files. For examples related to optimization (not exactly curve fitting, but close, you would use lsqnonlin or lsqcurvefit instead of fmincon), see this example or this example. There is also an example on the file exchange that uses data in a symbolic test, and might be somewhat relevant.
Alan Weiss
MATLAB mathematical toolbox documentation
  3 件のコメント
Alan Weiss
Alan Weiss 2013 年 12 月 13 日
Did you look at the use of matlabFunction in the examples I linked? It converts symbolic variables to function handles or MATLAB files that then use numeric variables.
Alan Weiss
MATLAB mathematical toolbox documentation
Zine
Zine 2013 年 12 月 14 日
thanks very much, solved

サインインしてコメントする。

その他の回答 (1 件)

John D'Errico
John D'Errico 2013 年 12 月 12 日
編集済み: John D'Errico 2013 年 12 月 12 日
This just seems a problem of modular programming. It means you need to learn a good programming style, so that you CAN modify component parts of your function. But there is very little we can do for you in that respect.
  • Break the problem into pieces.
  • Learn to use nested functions.
  • Test every piece separately. If they all work separately, then they will work as a whole.
  • Document your code, so it will be easy to debug. If the code is easy to read, it will be easy to repair too.
Beyond that, there is no magic. There are no shortcuts to writing good code.

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by