How can I run this costfunction optimization ?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Respuestas (1)
Anisha Mishra
el 22 de Ag. de 2020
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.
0 comentarios
Ver también
Categorías
Más información sobre Problem-Based Optimization Setup en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!