Error: "Difference order N must be a positive integer scalar" when called symbolic gradient function
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Lu zhang
el 5 de Dic. de 2016
Comentada: Lu zhang
el 6 de Dic. de 2016
In my program, I first use command jacobian generate a symbolic gradient of my objective function.Then I call the function(gradient.m) and feed it with numeric value. But Matlab warned me like
Warning: Function "diff" is not verified to be a valid MATLAB
function.
Warning: Function "diff" is not verified to be a valid
MATLAB function.
Warning: Function "diff" is not verified to be a valid
MATLAB function.
Error using diff
Difference order N must be a positive integer scalar.
Error in gradient (line 10)
t4 = diff(t2,B1);
Error in mini_dist_noheter (line 60)
dfb = gradient(b(1),b(2),b(3));
The gradient function file, main file and data see the attachment.
2 comentarios
Respuesta aceptada
Walter Roberson
el 5 de Dic. de 2016
You appear to have a problem with your MATLAB path. I suggest using
resetdefaultpath
and seeing if that helps.
5 comentarios
Walter Roberson
el 6 de Dic. de 2016
I did not realize you were using such an old version.
The messages about diff not being verified to be a MATLAB function are coming from your matlabFunction() call applied to the result of jacobian(temp,v) . The jacobian that is generated has a bunch of diff() calls in it, and matlabFunction is warning that converting them into numeric calls might fail. Which indeed happens.
The diff() calls that are being left in are of the form
diff(conj(VARIABLE), VARIABLE)
because it that MATLAB version, the symbolic engine does not know how to take that derivative.
My research suggests that if the variable is permitted to be complex valued then that derivative does not exist; see https://www.quora.com/What-is-the-differentiation-dz%CC%85-dz-of-a-complex-conjugate-by-the-complex-variable-If-it-is-zero-how-does-it-become-so for two proofs.
Why does the jacobian have a bunch of diff(conj(VARIABLE),VARIABLE) calls in it? It is because your variable temp has a bunch of conj(VARIABLE) in it.
Why does your variable temp have a bunch of conj(VARIABLE) in it? It is because in fcn_noheter near the end you have
trans = dif';
and ' is the complex conjugate transpose operation.
You need to ask yourself whether you instead wanted just
trans = dif .';
for the regular transpose. If you do not want just regular transpose, then when you create B1, B2, B3 you need to also
assume(B, 'real')
Más respuestas (0)
Ver también
Categorías
Más información sobre Symbolic Math Toolbox 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!