[Scilab-users] numderivative Heart function

Hermes herozigle at gmail.com
Sun Dec 10 08:52:00 CET 2017


Thanks Rafael,
with your solution the final script, it seems to me more elegant, and it is
of the following form:
*
funcprot(0);
function val = Hxy(x,y)
    val=(1.25*y-sqrt(abs(x))).^2+x.^2-1;
endfunction;
x = -1:0.01:1;
contour2d(x, 2*x, Hxy, [0 0]);
replot([-1.415,-1,1.415,1.415]);

function Jpx=dfx(v)  //v:(x,y)
Jpx=numderivative(Hxy,v);
Jpx=Jpx(1);
endfunction

//Find the local maxima.
function Z = flm(v)//v:(y,x)
    x=v(1);y=v(2);
   Z = [ Hxy(x,y)
         dfx(v)
       ]
endfunction
//v:(x,y)
xlm1=fsolve([-0.4;1.4],flm)
disp(xlm1)
xlm2=fsolve([0.4;1.4],flm)
disp(xlm2)
plot([xlm1(1) xlm2(1)],[xlm1(2) xlm2(2)],'gx')

//Find the y-intercepts. Hxy(x,y) 
//To find solutions of Hxy(x,y) with fsolve along the x=0 slice, it might be
easier to use a sliced function H0y as input:
function z=H0y(y)   // slice of Hxy along x=0
    x=0;
    z= Hxy(x,y);
endfunction;

yint1=fsolve(1,H0y)// --->Hxy(y,x)=>1.5625*y^2-1 
disp(yint1) 
yint2=fsolve(-1,H0y)// ---> Hxy(y,x)=>1.5625*y^2-1 
disp(yint2) 
x=0;
plot([x x],[yint1 yint2],'rx')

*
Once again Thanks to you and all those who with their comments have
initiated me in SCILAB.

Before your solution I had written the following script, with the same
results:

*
function val = Hxyg(x,y)
    val=(1.25*y-sqrt(abs(x))).^2+x.^2-1;
endfunction;
x = -1:0.01:1;
contour2d(x, 2*x, Hxyg, [0 0]);
replot([-1.415,-1,1.415,1.415]);

//We define the Hxy function with x as additional input argument( as a
parameter)
//Since y, will be our unknown, we have interposed x and y in the argument
list of the Hxy function 
//(y it is the unknown and x is the parameter). 
//This will be necessary to determine the intersects on the Y axis
function val = Hxy(y,x)
    val=(1.25*y-sqrt(abs(x))).^2+x.^2-1; // switched .^ to ^ to handle
vectors
endfunction;

function Jpx=dfx(v)//v:(y,x)
Jpx=numderivative(Hxy,v);
Jpx=Jpx(2);
endfunction

//Find the local maxima.
function Z = flm(v)//v:(y,x)
   Z = [ HH(v)
         dfx(v)
       ]
endfunction
//v:(y,x)
xlm1=fsolve([1.4;-0.4],flm)
disp(xlm1)
xlm2=fsolve([1.4;0.4],flm)
disp(xlm2)
plot([xlm1(2) xlm2(2)],[xlm1(1) xlm2(1)],'gx')

//Find the y-intercepts. Hxy(y,x) 
//the Hxy function uses x as a parameters.
//We define the Hxy function with x as additional input argument( as a
parameter),
//which is declared after the y unknown. Then we pass a list as the second
input argument
//of the  fsolve function after initial value of  Hxy function argument; in
this situation only  variable y.
//The first element of the list is the Hxy function. The additional variable
x is directly passed to the Hxy function.
x=0.0; 
yint1=fsolve(1,list(Hxy,x))// --->Hxy(y,x)=>1.5625*y^2-1 
disp(yint1) 
yint2=fsolve(-1,list(Hxy,x))// ---> Hxy(y,x)=>1.5625*y^2-1 
disp(yint2) 
plot([x x],[yint1 yint2],'rx')

*
Note, I still can not put the codes the way you do. my email is in HTML
format

10^6 Gracias!!!



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



More information about the users mailing list