How to use vectors inside the fittype function
5 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I am using the fit function in order to take experimental data and fit it with an expression. The expression that I need to use also uses multiplication of variables which are vectors, within the expression. The problem is that the fittype is a string, which only "knows" the independent variable and the coefficients, as far as I understand. So it does not work, and I dont know how to send these vectors into the expression so fittype can use it. It is best to give a simplified example:
lets say I have only two data points (x1,y1),(x2,y2), and I have another vector, V, which has two elements in it. Mathematically, the expression I want to fit is A1*V./x ( where x is (x1,x2) ), and as a function this will give an answer which is a vector with 2 elements. But the fittype string would be 'A1*V./x' and the symbol V has no meaning since it is not the dependent variable x, and it is not a coefficient.
how can I solve this?
Thank you, Itai.
0 件のコメント
回答 (2 件)
Elizabeth Reese
2017 年 12 月 4 日
You can do this by supplying an anonymous function for the expression in fittype instead of a string.
For example
g = fittype( @(a1,v,x) a1*v./x, 'problem', 'v' );
f = fit(xdata,ydata,g,'problem',V)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Linear and Nonlinear Regression についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!