[Scilab-users] numderivative Heart function

Rafael Guerra jrafaelbguerra at hotmail.com
Thu Nov 30 19:23:32 CET 2017


Hi Hermes,



I do not recall your problem and it would help some explanation.

To plot the contours of a gradient with contour2d, you have to make it a scalar (otherwise look at champ, etc.).

Check out the edited code below.

Note that your gradient does not reach 0 and so a contour |g|=5 is plotted.



// START OF CODE

clear; clf;

funcprot(0);

function val=H(x1, x2)

    val=(1.25*x2-sqrt(abs(x1))).^2+x1.^2-1;

endfunction;

function [gx, gy]=g(x1, x2)

   gx= 2*x1-(x1.*(1.25*x2-sqrt(abs(x1))))./abs(x1).^(3/2);

   gy = 2.5*(1.25*x2-sqrt(abs(x1)));

endfunction



function val=HH(z)

    x1=z(1);

    x2=z(2);

    val=(1.25*x2-sqrt(abs(x1))).^2+x1.^2-1;

endfunction;



function z=dH(x)

    z=numderivative(HH,x)

endfunction



//test

x0=[0.2 -0.5];

disp(H(x0(1),x0(2)));

[gx,gy]=g(x0(1),x0(2))

disp(gx,gy);

disp(dH(x0));



x = linspace(-1,1,1002);

y = 2*x';

xx = x.*.ones(x');

yy = y.*.ones(y');

[gx,gy] = g(xx,yy);

g1= abs(gx + %i*gy);

contour2d(x, y, g1, [5 5]);



replot([-1.415,-1,1.415,1.415]);

// END OF CODE





[cid:image003.jpg at 01D36A10.B2E54FF0]



Regards,

Rafael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20171130/a26f45c5/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image003.jpg
Type: image/jpeg
Size: 5386 bytes
Desc: image003.jpg
URL: <https://lists.scilab.org/pipermail/users/attachments/20171130/a26f45c5/attachment.jpg>


More information about the users mailing list