How to use vectors inside the fittype function

5 ビュー (過去 30 日間)
ITAI EPSTEIN
ITAI EPSTEIN 2017 年 12 月 1 日
回答済み: ITAI EPSTEIN 2017 年 12 月 4 日
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.

回答 (2 件)

Elizabeth Reese
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)
You can read more about this option here .

ITAI EPSTEIN
ITAI EPSTEIN 2017 年 12 月 4 日
Thank you Liz. I will try it. As my code is already in string form, is it possible to combine this with a string to get the final fit model?
Thanks, Itai.

カテゴリ

Help Center および File ExchangeLinear and Nonlinear Regression についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by