[Scilab-users] evaluate matrix in a function

Hermes herozigle at gmail.com
Fri Oct 13 10:11:33 CEST 2017


Hi Philippe:
Where this error?

// The function to differentiate
function val = HH(z)
    x=z(1);
    y=z(2); 
    val=(1.25*y-sqrt(abs(x))).^2+x.^2-1; 
endfunction;
// The exact gradient
function Sys=ge(x)
  gx=x(:,1);
  gy=x(:,2);  
g1=2*gx-(gx.*(1.25*gy-sqrt(abs(gx))))./abs(gx).^(3/2);
g2=2.5*(1.25*gy-sqrt(abs(gx)));
  Sys(:,1)=g1;
  Sys(:,2)=g2;
endfunction
// Compute the approximate Jacobian
t=[3,1]; //for function f, which does not allow multiple inputs [x1,1 x2,1
x3,1; ...; x1, n x2, n x3, n]
t1=[3,1;3,1];//for function f,  allow multiple inputs [x1,1 x2,1 x3,1; ...;
x1, n x2, n x3, n]

*// test function*
function z=f(x)
z=diffcode_jacobian(HH,x) endfunction

disp(f(t)',ge(t1),HH(t))

function z=feval2(x,y,g)
    //  eval f on the curve t->(x(t),y(t))
    // and on the grid defined by x,y
    deff('z=newf(k)',['a=[x(k),y(k)]';'z=g(a)'])
    // x,y are global variables for the "newf" function
    z=feval(1:length(x),newf)
    // "newf" is a local variable for "feval2"
endfunction
// Compute the approximate Jacobian
x=-3:3;y=x;

z=feval2(x,y,f) // curve evaluation
disp(z ," feval2");

*in builtin                
feval2 ( C: \Curve11.sce line 47 )
newf: Wrong size for output argument #1: A Scalar expected.
敦慶l: An error occured in '硥捥敆慶䙬' subroutine.
*
Gracias
Hermes



--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html



More information about the users mailing list