Deadstar

197 Reputation

6 Badges

15 years, 362 days

MaplePrimes Activity


These are answers submitted by Deadstar

Perfect that does the job.

I have another question now...

Is there any way to make Maple 'more random'...

Strange question I know but if you consider this loop that acer gave me in my other thread...

Digits := trunc(evalhf(Digits)):
with(Statistics):
maxiter := 1000000:
n := 5:
A := Array(1..1000000,datatype=float):
C := Array(1..n,datatype=float):
lC := Array(1..n,datatype=float):
t_S := RandomVariable(Normal(0,1)):
 
myproc := proc(A::Array(datatype=float[8]),C::Array(datatype=float[8]),
               lC::Array(datatype=float[8]),all_t::Vector(datatype=float[8]),
               maxiter::integer,n::integer)
  local k::integer, kk::integer, temp::float, themax::float,
        tmean::float, tSD::float, kminusonen::integer, inf::float,
        j::integer, kkbest::float, jbest::float, fn::float;
  fn := 1.0*n;
  inf := 99999.9;
  for k from 1 to maxiter do
    kminusonen := (k-1)*n;
    tmean := 0.0;
    for kk from 1 to n do
      tmean := tmean + all_t[kminusonen+kk];
    end do;
    tmean := tmean/fn;
    tSD := 0.0;
    for kk from 1 to n do
      tSD := tSD + (all_t[kminusonen+kk]-tmean)^2;
    end do;
    tSD := sqrt(tSD/(fn-1.0));
    for kk from 1 to n do
      C[kk] := (all_t[kminusonen+kk]-tmean)/tSD:
    end do:
    # slowest sorter known to mankind
    for kk from 1 to n do
      kkbest := inf;
      for j from 1 to n do
        if C[j]<kkbest then
          kkbest := C[j];
          jbest := j;
        end if;
      end do;
      lC[kk] := kkbest;
      C[jbest] := inf;
    end do:
    for kk from 1 to n do
      lC[kk] := 1.0/2.0+(1.0/2.0)*erf((1.0/2.0)*lC[kk]*(2.0^(1/2)));
    end do:
    themax := 0;
    for kk from 1 to n do
      temp := max(abs(kk/fn - lC[kk]), abs((kk-1)/fn - lC[kk]));
      if temp>themax then themax:=temp; end if;
    end do;
    A[k]:=themax;
  end do;
  NULL;
end proc:
 
myproc_c := Compiler:-Compile(myproc):
 
all_t := Sample(t_S,maxiter*n):
myproc_c(A,C,lC,all_t,maxiter,n):

If I run it twice (after restarting, on different days, whenever), it gives me the exact same values each time.

However if I ran it with maxiter := 1000001 then I would get a new value which wasn't in any of the previous runs.

This will happen for as low as maxiter := 10000. Is there something I can put in the code or is this just the way it is...

Acer you're a genius thank you very much! Your post should be stickied as a guide on how to be efficient.

 

Erik Thank you as well you've both been incredibly helpful.

 

Deadstar.

Thanks Erik I've sent you a PM with more details.

Right well I did that on a smaller version (k goes to 100000) with gc()'s every 10000 but it didnt save much memory at all...

 

Basically what I'm trying to do is...

each loop ends with A[k] := (insert code here)... But that leaves quite a lot of 'garbage' from the calculations earlier in the loop.

What I am trying to do is remove this garbage so I'm only left with the values in the Array as thats all I need. Is this the right way to be doing it?

 

Putting gc() at the end of each loop seems to keep memory usage very low but maybe I've got this whole thing wrong and when I go to do it for k -> 10^7 or above then it will use the same amount of memory but just take longer...

Tnaks very much for the answer!

 

I think one of the problems is actually that my laptop is too slow.

I tried that code you gave that produces a 500MB sample but mine reached 1.5GB then just stayed on evaluating... until I had to close Maple.

Think I might upgrade my RAM. The code I've got written can do everything except find the standard deviation. The actual StandardDeviation command wouldn't work (just would go to evaluating... forever). So i thought about calculating it manually using the formula so I broke up a new array into 20 smaller arrays and worked with each of them as using another 10^7 array wasn't working. It was working much faster until I hit round about the 6500000+ entries then it would just crash. Ill figure it out... I think if I get more RAM it should be fine.

 

Thanks for your help.

Yes thats perfect! Thanks very much!

Ah hell whats happened there...
 

ignore the <p>'s and whatnot...

Hmm... This thread worries me because my phase portrait is nothing like the one doug has...

try  ICs := [ seq( Equate( V(0),[0,h] ), h=-0.4..0.5, 0.1 )  ] for the initial conditions but define a as something between -0.5 and 0.5 first.

Then change the '0' in [0,h] to values ranging from -1 to 1 for a look at whats going on.

 

Also try stepsize=0.01
 

And the V(0) stands for V := [u,v] that was defined earlier.

Thanks very much thats great!

Thanks very much guys very helpful. Its not an actual assignment or anything, just part of a maple tutorial im working through.

Gotta be honest, that hasn't really helped. Optional 3rd argument? You mean the third idea i stated? If the answers yes then i still have no clue. I know the sequence operator plays a part but im gonna need a bigger hint than that...

1 2 Page 2 of 2