心脏功能diff等于零

时间:2017-10-02 08:04:06

标签: diff zero scilab

我想找到其导数等于零的函数的值。

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

我已尝试使用numderivative功能。 格拉西亚斯。

2 个答案:

答案 0 :(得分:1)

Scilab无法以当前定义函数的方式解决此问题,因为Heart()是一个隐式函数。正如here所回答的那样,Scilab无法进行隐式区分。此外,您的等式实际上定义了一个3D表面,因此您可以计算的实际上是偏导数。

如果要查找与隐式曲线x1的{​​{1}}相关的导数为零的x1值,可以使用{{3}中显示的方法从你自己以前的问题来解决这个问题。

如果你检查心脏曲线图,你会发现只有两个点,其中导数为零(两个最大值):它们位于曲线的上半部分并且接近{{1分别是}和0=Heart(x1,x2)。要查找这些点的更多近似值,您应该执行以下操作:

  1. 抓住心脏的上半部分(使用this answer找到它)并定义一个新功能。
  2. 使用x1=-0.6定义其衍生产品x1=0.6。我们要找的答案是这个函数的零。
  3. 使用numderivative()解决d_heart()。你应该输入两个猜测,它们可以是-0.6和0.6。
  4. 这样的事情:

    fsolve()

    您可以想象0=d_heart(x1)确实是心脏的上半部分,并且通过绘制它们的结果是正确的:

    function y = heart_up(x1)
        y = 4/5 * (sqrt(abs(x1))+sqrt(1-x1.^2))
    endfunction
    
    function y = d_heart(x1)
        y = numderivative(heart_up, x1);
    endfunction
    
    x1 = fsolve(-0.6, d_heart); y1 = heart_up(x1);
    x2 = fsolve( 0.6, d_heart); y2 = heart_up(x2);
    

    4

答案 1 :(得分:0)

是否可以缩短(改进)此脚本?我想到雅可比心脏功能,评估它并找到它为零的点。一些游乐设施!!!

遵循 luispauloml 的指示:

[function val = Heart(x1, x2) 
    val=(1.25*x2-sqrt(abs(x1))).^2+x1.^2-1;
endfunction;


function y = heart_up(x1)
    y = 4/5 * (sqrt(abs(x1))+sqrt(1-x1.^2))
endfunction
function y = heart_down(x1)
    y = 4/5 * (sqrt(abs(x1))-sqrt(1-x1.^2))
endfunction

function y = du_heart(x1)
    y = numderivative(heart_up, x1);
endfunction
function y = dd_heart(x1)
    y = numderivative(heart_down, x1);
endfunction

x1 = fsolve(-0.6, du_heart); y1 = heart_up(x1);disp(y1,"y1",x1,"x1");
x2 = fsolve( 0.6, du_heart); y2 = heart_up(x2);disp(y2,"y2",x2,"x2");
x3 = fsolve( 0.0, du_heart); y3 = heart_up(x3);disp(y3,"y3",x3,"x3");
x4 = fsolve( 0.0, dd_heart); y4 = heart_down(x4);disp(y4,"y4",x4,"x4");

x = -1:0.01:1;
contour2d(x, 2*x, Heart, \[0 0\]);
plot(\[x1 x2\],\[y1 y2\],'gd');
plot(\[x3 x4\],\[y3 y4\],'rx');
replot(\[-1.415,-1,1.415,1.415\]);][1]

另一种可能的解决方案是: 通过此功能,我们开始熟悉Scilab。 在我提出的脚本中,我们已经找到了Heart函数的关键或极端点。 我们在阅读评论时请您注意!!!!

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 [val] = HH(v)//v:(y,x)
    x=v(2);
    y=v(1); 
    val=Hxy(y,x);
endfunction;

function Jpx=dfx(v)//v:(y,x)
Jpx=numderivative(HH,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')

Heart Critical points or extreme points