[Scilab-users] non linear optimization why produce Nan

classic Classic list List threaded Threaded
6 messages Options
karoli karoli
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] non linear optimization why produce Nan

hello team
why my optimization produce an Nan result, any help


[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  
 



--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
mottelet mottelet
Reply | Threaded
Open this post in threaded view
|

Re: non linear optimization why produce Nan

Helllo,

Start by testing your residual function *alone* with inital value of
your parameters

--> dyke_error(p0,Value, i, y)

S.

Le 27/03/2019 à 09:20, karoli a écrit :

> hello team
> why my optimization produce an Nan result, any help
>
>
> [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
>  
>
>
>
> --
> Sent from: https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
> _______________________________________________
> users mailing list
> [hidden email]
> https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
karoli karoli
Reply | Threaded
Open this post in threaded view
|

Re: non linear optimization why produce Nan

Hello mottelet
I tested it, residual results is ok
as bellow shown;
-->dyke_error(p0,Value, i, y)
 ans  =
 
    Nan        
  - 332.01567  
  - 312.19667  
  - 324.46484  
  - 328.8238  
  - 332.27738  
  - 336.82964  
  - 341.48485  
  - 343.24755  
  - 347.12254  
  - 353.11492  
  - 355.2301  
  - 359.47381  
  - 360.85216 ........ continue

but once I run leastsq function again, I got same results

-->[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  

I still don't understand what's wrong with my code.

regards
karoli



--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
mottelet mottelet
Reply | Threaded
Open this post in threaded view
|

Re: non linear optimization why produce Nan

Hello,

Le 02/04/2019 à 10:44, karoli a écrit :
> Hello mottelet
> I tested it, residual results is ok
No it is not ok
> as bellow shown;
> -->dyke_error(p0,Value, i, y)
>   ans  =
>  
>      Nan
you have a "Not a Number" in first component

>  
>    - 332.01567
>    - 312.19667
>    - 324.46484
>    - 328.8238
>    - 332.27738
>    - 336.82964
>    - 341.48485
>    - 343.24755
>    - 347.12254
>    - 353.11492
>    - 355.2301
>    - 359.47381
>    - 360.85216 ........ continue
>
> but once I run leastsq function again, I got same results
>
> -->[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
>
> I still don't understand what's wrong with my code.
>
> regards
> karoli
>
>
>
> --
> Sent from: https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
> _______________________________________________
> users mailing list
> [hidden email]
> https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users


--
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
mottelet mottelet
Reply | Threaded
Open this post in threaded view
|

Re: non linear optimization why produce Nan

You have to remove the first line of Value, because of the header "x,y" 
in your sheet:

--> Value
ans  =

    Nan    Nan   Nan
    0.     97.   Nan
    20.    74.   Nan
    40.    83.   Nan
    60.    84.   Nan
    80.    84.   Nan
    100.   85.   Nan
    120.   86.   Nan
    140.   84.   Nan
    160.   84.   Nan
    (...)
    2820.   585.    Nan
    2840.   303.    Nan
    2860.   28.     Nan
    2880.  -132.    Nan
    2900.  -205.    Nan
    2920.  -214.    Nan
    2940.  -170.    Nan
    2960.  -107.    Nan
    2980.  -62.     Nan
    3000.  -32.     Nan
    3020.  -2.      Nan
    3040.   22.     Nan
    3060.   40.     Nan
    3080.   54.     Nan

Just insert

Value(1,:) = []

after calling read_xls

S.


Le 02/04/2019 à 10:48, Stéphane Mottelet a écrit :

> Hello,
>
> Le 02/04/2019 à 10:44, karoli a écrit :
>> Hello mottelet
>> I tested it, residual results is ok
> No it is not ok
>> as bellow shown;
>> -->dyke_error(p0,Value, i, y)
>>   ans  =
>>        Nan
> you have a "Not a Number" in first component
>>      - 332.01567
>>    - 312.19667
>>    - 324.46484
>>    - 328.8238
>>    - 332.27738
>>    - 336.82964
>>    - 341.48485
>>    - 343.24755
>>    - 347.12254
>>    - 353.11492
>>    - 355.2301
>>    - 359.47381
>>    - 360.85216 ........ continue
>>
>> but once I run leastsq function again, I got same results
>>
>> -->[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
>>
>> I still don't understand what's wrong with my code.
>>
>> regards
>> karoli
>>
>>
>>
>> --
>> Sent from:
>> https://antispam.utc.fr/proxy/2/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
>> _______________________________________________
>> users mailing list
>> [hidden email]
>> https://antispam.utc.fr/proxy/2/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users 
>>
>
>

--
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
karoli karoli
Reply | Threaded
Open this post in threaded view
|

Re: non linear optimization why produce Nan

thanks a lot, Stéphane Mottelet, now it is working.



--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users