フィルターのクリア

How can I run this costfunction optimization ?

1 回表示 (過去 30 日間)
payman khayree
payman khayree 2013 年 11 月 18 日
回答済み: Anisha Mishra 2020 年 8 月 22 日
I am trying to run this optimization:
function [jVal,gradient]=costfunction(theta);
jVal=(theta(1)-5)^2+(theta(2)-5)^2;
gradient=zeros(2,1),
gradient(1)=2*(theta(1)-5);
gradient(2)=2*(theta(2)-5);
options=optimset('Gradobj','on','MaxIter',100)
initialTheta=zeros(1,2)
[optTheta,functionVal,exitFlag]=fminunc(@costfunction,initialTheta,options)
But it says that you need more arguements for theta. How should I define theta for this function while I want matlab to calculate and minimize it?
TNX
  1 件のコメント
Walter Roberson
Walter Roberson 2013 年 11 月 18 日
Could you show the exact error message?

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

回答 (1 件)

Anisha Mishra
Anisha Mishra 2020 年 8 月 22 日
You have initialised initialTheta = zeros(1,2) which makes an empty 1x2 matrix , i.e , it has 1 row and two columns
where as the theta is a vector with 2 rows and 1 column ,i.e 2x1
So change your initialTheta as:
initialTheta=zeros(2,1);
This will solve your error.
Hope this helps.

カテゴリ

Help Center および File ExchangeProblem-Based Optimization Setup についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by