"Error not enough input arguments "
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
ananya mittal
il 13 Giu 2020
Commentato: Walter Roberson
il 14 Giu 2020
This is my code and I am getting error" not enough input parameters" in line 4 .Can anyone please rectify the problem ?
function[jval, gradient]= costfuntion(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', 'MaxIte', 100);
initialTheta= zeros(2,1);
[optTheta,funcval, exitFlag]= fminunc(@costfunction, initialTheta, options);
2 Commenti
Aditya Verma
il 13 Giu 2020
Hi! May I know how you're trying to call this function? According to my understanding, you're trying to operate on a matrix with two elements. A possible call to this function could be:
costfuntion([10 20])
Walter Roberson
il 14 Giu 2020
The lines start from options need to be either before the function or else in a different file.
Risposta accettata
KSSV
il 13 Giu 2020
I think you are running your code by using either run button or F5 button. This is a function, you cannot run like that. You need to save it in a directory on the name costfunction.m. And call it in command window.
theta = rand(1,2) ; % some random values for demo
[jval, gradient]= costfunction(theta) ;
I have checked the code, it is running fine.
Più risposte (0)
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!