Why do I get an erro when using the built-in function gradient() ?
조회 수: 9 (최근 30일)
이전 댓글 표시
Hi.
I can't get an ideal why the following codes using gradient() turn out to be erroneous.
01.F=@(X)(4*X(1)^2+X(2)^2-X(1)^2*X(2))
02.F =
03. @(X)(4*X(1)^2+X(2)^2-X(1)^2*X(2))
04.>> gradient(F)
05.??? Error using ==> zeros
06.Trailing string input must be a valid numeric class name.
07.Error in ==> gradient at 64
08. g = zeros(size(f),class(f)); % case of singleton dimension
please point out why it's an erro using !
Best regards.
David
댓글 수: 0
채택된 답변
dpb
2014년 6월 4일
Because you call F w/o any argument list.
Try
x=1:3;
gradient(F(x))
instead. However, I suspect this isn't doing what you are thinking it might (altho I'm not positive what that might be, I'm guessing a little on that point).
댓글 수: 3
dpb
2014년 6월 4일
I don't understand what
x=[ x(1), x(2) ]
is supposed to represent. What it is is a 2-vector. But by definition gradient is just the first difference of the input vector so while you can call it using F(x) as the argument it's only going to evaluate the difference evaluated from the function evaluated over the inputs.
Now you could write the function definition to handle a vector input perhaps; but you would need to use different notation--like F(x,y) if the intent of x is to be a 2-column array of two different x-vectors. Again, that's just a guess as to what you may be intending...
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!