• non linear optimization why produce Nan

    From mankarol10@gmail.com@21:1/5 to All on Wed Mar 27 02:11:40 2019
    hello team
    why my optimization calculation using leastsq produce an Nan result, any help from the code below.

    [fd,SST,Sheetnames,Sheetpos]=xls_open('D:\MAG2.xls') [Value,TextInd]=xls_read(fd,Sheetpos(1))

    y=45
    i=33
    p0=[53.8;1527;43.7;55.7;3424.7]

    function T= dyke(p,Value, i, y)
    h =1.0 - cosd( y )^2*sind( i )^2
    I= atand( tand( i )./sind( y ) )
    O=2*I - p(1) //P(1) = dip of the dyke(β) O is degree
    q1 = atand ( (( Value(:,1)-p(2)) - p(3) )./p(4) )
    q2 = atand ( (( Value(:,1)-p(2)) + p(3) )./p(4) ) //p(2) = horizontal location of the centre of top of dyke model, p(3)= the half width of dyke, p(4) = the depth to top of the model ,q1 and q2 are degrees
    Q = q1 - q2
    A=%pi*Q./180 // convertion to radisn
    r1 = sqrt ( p(4)^2 + ((Value(:,1)-p(2))-p(3))^2 )
    r2 = sqrt ( p(4)^2 + ((Value(:,1)-p(2))+p(3))^2 )
    R=r1./r2
    T = 2*h*p(5)*sind(p(1))*( sind(O)*A - cosd(O)*log(R)) //P(5) the intesity of magnetisation
    endfunction

    function e=dyke_error(p,Value, i, y)
    e= dyke(p,Value, i, y)-Value(:,2)
    endfunction.

    [f,p,g]=leastsq(dyke_error,p0)
    g =

    Nan
    Nan
    Nan
    Nan
    Nan
    p =

    53.8
    1527.
    43.7
    55.7
    3424.7
    f =

    Nan

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?iso-8859-1?Q?Vincent_Bela=EFche?=@21:1/5 to mankarol10@gmail.com on Tue Jun 11 06:01:28 2019
    mankarol10@gmail.com writes:

    hello team
    why my optimization calculation using leastsq produce an Nan result, any help from the code below.

    [fd,SST,Sheetnames,Sheetpos]=xls_open('D:\MAG2.xls') [Value,TextInd]=xls_read(fd,Sheetpos(1))

    y=45
    i=33
    p0=[53.8;1527;43.7;55.7;3424.7]

    function T= dyke(p,Value, i, y)
    h =1.0 - cosd( y )^2*sind( i )^2
    I= atand( tand( i )./sind( y ) )
    O=2*I - p(1) //P(1) = dip of the dyke(¦Â) O is degree
    q1 = atand ( (( Value(:,1)-p(2)) - p(3) )./p(4) )
    q2 = atand ( (( Value(:,1)-p(2)) + p(3) )./p(4) ) //p(2) = horizontal location of the centre of top of dyke model, p(3)= the half width of
    dyke, p(4) = the depth to top of the model ,q1 and q2 are degrees
    Q = q1 - q2
    A=%pi*Q./180 // convertion to radisn
    r1 = sqrt ( p(4)^2 + ((Value(:,1)-p(2))-p(3))^2 )
    r2 = sqrt ( p(4)^2 + ((Value(:,1)-p(2))+p(3))^2 )
    R=r1./r2
    T = 2*h*p(5)*sind(p(1))*( sind(O)*A - cosd(O)*log(R)) //P(5) the intesity of magnetisation
    endfunction

    function e=dyke_error(p,Value, i, y)
    e= dyke(p,Value, i, y)-Value(:,2)
    endfunction.

    [f,p,g]=leastsq(dyke_error,p0)
    g =

    Nan
    Nan
    Nan
    Nan
    Nan
    p =

    53.8
    1527.
    43.7
    55.7
    3424.7
    f =

    Nan

    Maybe you should check whether there aren't NaN in the Value variable, immediately after reading 'D:\MAG2.xls'. Usually speadsheets have text
    title rows that don't convert to numbers, so maybe this causes some NaN
    in the first element of Value.
    V.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?iso-8859-1?Q?Vincent_Bela=EFche?=@21:1/5 to mankarol10@gmail.com on Tue Jun 11 06:00:25 2019
    Copy: vincent.belaiche@gmail.com (=?iso-8859-1?Q?Vincent_Bela=EFche?=)

    mankarol10@gmail.com writes:

    hello team
    why my optimization calculation using leastsq produce an Nan result, any help from the code below.

    [fd,SST,Sheetnames,Sheetpos]=xls_open('D:\MAG2.xls') [Value,TextInd]=xls_read(fd,Sheetpos(1))

    y=45
    i=33
    p0=[53.8;1527;43.7;55.7;3424.7]

    function T= dyke(p,Value, i, y)
    h =1.0 - cosd( y )^2*sind( i )^2
    I= atand( tand( i )./sind( y ) )
    O=2*I - p(1) //P(1) = dip of the dyke(¦Â) O is degree
    q1 = atand ( (( Value(:,1)-p(2)) - p(3) )./p(4) )
    q2 = atand ( (( Value(:,1)-p(2)) + p(3) )./p(4) ) //p(2) = horizontal location of the centre of top of dyke model, p(3)= the half width of
    dyke, p(4) = the depth to top of the model ,q1 and q2 are degrees
    Q = q1 - q2
    A=%pi*Q./180 // convertion to radisn
    r1 = sqrt ( p(4)^2 + ((Value(:,1)-p(2))-p(3))^2 )
    r2 = sqrt ( p(4)^2 + ((Value(:,1)-p(2))+p(3))^2 )
    R=r1./r2
    T = 2*h*p(5)*sind(p(1))*( sind(O)*A - cosd(O)*log(R)) //P(5) the intesity of magnetisation
    endfunction

    function e=dyke_error(p,Value, i, y)
    e= dyke(p,Value, i, y)-Value(:,2)
    endfunction.

    [f,p,g]=leastsq(dyke_error,p0)
    g =

    Nan
    Nan
    Nan
    Nan
    Nan
    p =

    53.8
    1527.
    43.7
    55.7
    3424.7
    f =

    Nan

    Maybe you should check whether there aren't NaN in the Value variable, immediately after reading 'D:\MAG2.xls'. Usually speadsheets have text
    title rows that don't convert to numbers, so maybe this causes some NaN
    in the first element of Value.
    V.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)