Question: Error with Array in procedure

Hello,

I've got this error in my code and I don't know why as I didn't get it when I used a different xn function. Any help would be greatly appreciated! Thank you in advance!

Kind regards,

Gambia Man

restart

with(plots):

boxcount := proc (data, N) local n, xmax, xmin, xrange, ymax, ymin, yrange, dx, dy, i, j, ix, iy, sum, res; n := (1/2)*ArrayNumElems(data); xmax := max(seq(data[i, 1], i = 1 .. n)); xmin := min(seq(data[i, 1], i = 1 .. n)); ymax := max(seq(data[i, 2], i = 1 .. n)); ymin := min(seq(data[i, 2], i = 1 .. n)); xrange := xmax-xmin; xmin := xmin+(-1)*0.1e-1*xrange; xmax := xmax+0.1e-1*xrange; xrange := 1.02*xrange; yrange := ymax-ymin; ymin := ymin+(-1)*0.1e-1*yrange; ymax := ymax+0.1e-1*yrange; yrange := 1.02*yrange; dx := xrange/N; dy := yrange/N; res := Array(0 .. N-1, 0 .. N-1, 0); for i to n do ix := trunc((data[i, 1]-xmin)/dx); iy := trunc((data[i, 2]-ymin)/dy); res[ix, iy] := 1 end do; add(add(res[i, j], i = 0 .. N-1), j = 0 .. N-1) end proc:

``

bicationplot := proc (N) local Nr, Nt, x0, rmin, rmax, bif, k, ir, r, xn, i; global pts; Nr := 100; Nt := 200; x0 := .1; rmin := .75; rmax := 3.5; bif := Array(1 .. Nr*N, 1 .. 2); k := 1; for ir to Nr do r := rmin+ir*(rmax-rmin)/Nr; xn := x0; for i to Nt do xn := xn^2-r end do; for i to N do xn := xn^2-r; bif[k, 1] := r; bif[k, 2] := xn; k := k+1 end do end do; pts := bif end proc:

bif

bif

(1)

fractaldimension := proc (Noofitterations::integer, Npoints::integer, Nmax::integer) local res, xv, yv, line, stderrors, avgstderrors, i, avgline; avgstderrors := 0; avgline := 0; for i to Noofitterations do bicationplot(Npoints); res := [seq([1.0/n, boxcount(pts, n)], n = 1 .. Nmax, 10)]; xv := [seq(log(res[i][1]), i = 1 .. nops(res))]; yv := [seq(log(res[i][2]), i = 1 .. nops(res))]; line[i] := Fit(m*x+const, xv, yv, x, output = [leastsquaresfunction]); stderrors[i] := Fit(m*x+const, xv, yv, x, output = standarderrors) end do; for i to Noofitterations do avgstderrors := avgstderrors+stderrors[i] end do; avgstderrors := avgstderrors/Noofitterations; for i to Noofitterations do avgline := avgline+line[i] end do; avgline := avgline/Noofitterations; return FD = -(diff(avgline, x)), avgline, avgstderrors, loglogplot(res) end proc:

fractaldimension(10, 100, 100)

Error, (in boxcount) bad index into Array

 

``

 

Download First_part_fractal_determination_.mw

Please Wait...