Create function multiple variables with using constant in matrix?

i have 2 matrix 1000:1 (A= value and T- time) i want to create multiple variables function f(x(1),x(2),x(3)) like this:
f=0;
for i=1:1000
f= f+ (A(i) - x(1)T(i)^x(2) + x(3))^2;
end
Then i want to use x=fminsearch(@(x),f,[1,1,1]) to find (x(1),x(2),x(3)). Please show me how can i do this? I did this in mathcad, now i want to check this in Matlab. Thanks!

回答 (1 件)

Roger Stafford
Roger Stafford 2014 年 3 月 17 日

0 投票

Indeed you can use 'fminsearch' to minimize 'f'. However, since we have linearity with respect to the x(1) and x(3) parameters, this problem can be solved using only 'fzero' which would probably be more efficient. For any fixed value of x(2), this is a problem in linear regression for which there are explicit formulas for the minimum value that require no iteration. Therefore the only iteration that is needed is with 'fzero' in searching for the best value of x(2), and that should be much faster than with 'fminsearch'. Searching in one dimension is much easier than searching in three dimensions.

1 件のコメント

nguyenquoc uy
nguyenquoc uy 2014 年 3 月 17 日
編集済み: nguyenquoc uy 2014 年 3 月 17 日
Thank you so much. But i'm newbie with matlab, so please show me how to do these things? If u can, please write a full script please. And one more thing, i don't know how to write function f within loop for. I tried, but always got error.

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

カテゴリ

ヘルプ センター および File ExchangeSpline Postprocessing についてさらに検索

質問済み:

2014 年 3 月 17 日

編集済み:

2014 年 3 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by