Input Argument Undefined for Passing a Parameter to a Function

Hello,
I apologize if I am asking a very simple question but it's been something that I have been trying to work out and so far have been unsuccesful.
I am trying to write code to employ the gradient descent method on the camel function. Displayed below is the code:
Gradient Descent:
function [ dx ] = grad_d(v,f,gamma )
[Fx, Gx, Hx]= f(v);
dx = A - gamma*Gx;
end
In this case I want to use the function 'camel':
function [ Fx, Gx, Hx ] = camel(vec)
V = num2cell(vec);
[x,y] = V{:};
Fx = 2*x^2 - 1.05*x^4 + (x^6/6) + x*y+y^2;
Gx = [ x^5 - (21/5)*x^3 + 4*x + y;
x+2*y];
Hx = [ 5*x^4 - (63/5)*x^2 + 4, 1;
1, 2];
end
When I try to run one evaluation with the above code I get the error below:
I run the code as follows:
vec = ones(2,1)
grad_d(vec,camel,.1)
and receive the following:
_Input argument "vec" is undefined._
I know that I am overlooking something small but I can't pin it down. Any help would be much appreciated.
Thank you,

 採用された回答

Image Analyst
Image Analyst 2015 年 2 月 16 日

0 投票

Well you wrote the function to take in vec. What values do you want to pass in for it? You have to assign them. It can't read your mind.

3 件のコメント

Peter
Peter 2015 年 2 月 16 日
Hi Image Analyst,
I completely understand your response - I made a mistake when copying over the command line codes above. I have vec as the vector of ones and get the issue I initially mentioned.
Thanks again.
James Tursa
James Tursa 2015 年 2 月 16 日
編集済み: James Tursa 2015 年 2 月 16 日
@Peter: Do you still have this line:
grad_d(vec,camel,.1)
The 2nd argument is camel. That will call the function camel without any input arguments to camel. Then when it gets inside the camel function and tries to use the variable vec, you get the error.
Image Analyst
Image Analyst 2015 年 2 月 16 日
Don't pass in camel (If you did you'd have to use a @ in front of it).
vec = ones(2,1)
grad_d(vec,.1) % Call it without camel
Just call camel() inside the function:
function dx = grad_d(v,gamma)
[Fx, Gx, Hx]= camel(v);
dx = A - gamma*Gx;
end

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

その他の回答 (1 件)

Peter
Peter 2015 年 2 月 16 日

0 投票

Hello,
I am still having this problem. I made a more simple function:
function [ fin] = testfunction( vec )
V = num2cell(vec);
[x,y] = V{:};
fin = x+y;
end
If I try to call it using feval I get the same error. Any other thoughts on this? I am sure that it is a very trivial problem but I don't see what it is.
Thanks again

カテゴリ

ヘルプ センター および File ExchangeDevelop Apps Using App Designer についてさらに検索

質問済み:

2015 年 2 月 16 日

コメント済み:

2015 年 2 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by