What exactly is the problem? Can you boil it down to a simple:

I ran expression X
I got result Y
I expected result Z

Thanks.

Björn Helgason wrote:
>    9!:12''
> 6
>    9!:14''
> j601/2006-11-17/17:05
> 
>    load 'c:\users\bjorn\jsoftware\j602\user\projects\leastsquare3.ijs'
> 5
> 
>    leysa testy
> 5
> 8 6.1 9.2 14.1 21.2 30.3 105.1 293.2 292.364
> ---------------- j602
> 
>    9!:12''
> 6
>    9!:14''
> j602/beta/2007-09-19/23:00
> 
>    load 'c:\users\bjorn\jsoftware\j602\user\projects\leastsquare3.ijs'
> 1
> 
>    leysa testy
> 1
> 8 6.1 9.2 14.1 21.2 30.3 105.1 293.2 103.612
> 
> -------------------- leastsquare3
>    log =: ^.   NB. Give the natural log function the name log
>    e =: ^ 1   NB. e = exp(1) is Euler's number
>    alpha =: 0.2
> 
>    f2 =: verb define
> 'a k' =. y
> yp =. a*vx^k
> +/(yp-vy)^2
> )
> 
>    Nwtn3 =: adverb def 'y - alpha*(u y)%.(u D.1 y)'
>    FindRoot3 =: adverb def 'u Nwtn3 ^: _'
> 
> 
> NB. leysa
> 
> leysa=: verb define
> ny=.#y
> vx=:1+ i. ny
> vy=:y
> xlg=.log vx
> ylg=.log vy
> n=.#vx
> num=.(+/xlg*ylg)-(+/xlg)*(+/ylg)%n
> den=.(+/xlg*xlg)-((+/xlg)^2)%n
> k1=.num%den
> b1=.((+/ylg)-k1*(+/xlg))%n
> a1=.e^b1
> try.
> 'a5 k5' =: f2 D.1 FindRoot3 a1,k1
>  smoutput 5
> (1+ny),y,(a5*ny^k5)
> catch.
> smoutput 1
> (1+ny),y,a1*ny^k1
> end.
> )
> 
> NB. testx =: 1 2 3 4 5 10 20
> testy =: 6.1 9.2 14.1 21.2 30.3 105.1 293.2
> leysa testy
> load'plot'
> plot testy,292.364
> NB. plot a5*(i.21)^k5

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to