Why do I get an erro when using the built-in function gradient() ?
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
David W.
el 4 de Jun. de 2014
Comentada: David W.
el 7 de Jun. de 2014
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 comentarios
Respuesta aceptada
dpb
el 4 de Jun. de 2014
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 comentarios
dpb
el 4 de Jun. de 2014
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...
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!