## 6568 Reputation

8 years, 103 days

## it's because you "..used t...

it's because you "..used the "``" things ..":

A correct writing is given -below for the first memmer of abCaseTest.
Below there is a conversion of abCaseTest into this correct writting

 [`0

 (1)

 (2)

 (3)

 (4)

## Here is a solution among many others Re...

Here is a solution among many others

Remark: You said nothing about the random character of the number of non null elements. So I arbitrary considered this number was a discrete uniform random variable between 3 and the dimension of the matrix.

 > restart;
 > Seed := randomize()
 (1)
 > # Matrix dimension N := 10:
 > # One needs at least 3 non zeros elements per row NZ := 3: # define a discrete uniform random variable # with values in [NZ..N] rnz := rand(NZ..N):
 > # There are different ways to generate the matrix # Here is one of them M := NULL: for n from 1 to N do   # build a random vector   R    := LinearAlgebra:-RandomVector(10, generator=-10..10);      # randomly choose the rank of null elements   Keep := sort(combinat:-randperm([\$1..N])[1..rnz()]);      # generate a vector V with some zeroes   V    := Vector[row](N, i -> `if`(i in Keep, R[i], 0));      # concatenate the Vs to form the matrix   M    := < M, V >: end do: M;
 (2)
 >

## Hi, it seems you need some additional co...

Hi, it seems you need some additional constraints about a, x and y (> 0 or < 0?)

 > restart:
 > Coneq1:=x=-a/surd((1+c^2)^3, 2); eq2:=y=a*c^3/surd((1+c^2)^3, 2)
 (1)
 > eq11 := expand(map(u -> surd(u^2, 3), eq1)); eq21 := expand(map(u -> surd(u^2, 3), eq2));
 (2)
 > c2sol := expand(solve(subs(c^2=c2, eq11), c2));
 (3)
 > simplify(subs(c^2=c2sol, eq21)); EQ1 := normal(subs(c^6=c2sol^3, %));
 (4)
 > simplify(EQ1) assuming a > 0, x > 0, y > 0; simplify(EQ1) assuming a < 0, x > 0, y > 0; simplify(EQ1) assuming a > 0, x < 0, y > 0; simplify(EQ1) assuming a < 0, x < 0, y > 0; simplify(EQ1) assuming a > 0, x > 0, y < 0; simplify(EQ1) assuming a < 0, x > 0, y < 0; simplify(EQ1) assuming a > 0, x < 0, y < 0; simplify(EQ1) assuming a < 0, x < 0, y < 0;
 (5)
 >

## I believe that the first thing to do is ...

I believe that the first thing to do is to simplify your equations...
You could take inspiration from this:

 >
 > restart:
 > # do not use with(CodeGeneration) but instead : #  1/ with(CodeGeneration, Matlab) #  2: at the end of your worksheet CodeGeneration:-Matlab(...)
 > # first simplification of dM1 dM1 := subs(sqrt(b^2+z^2)=R,  diff(M1(z), z) = (eval(((2*I)*exp(-sqrt(t^2*v^2+b^2)+(1/2*I)*v^2*t)/sqrt(t^2*v^2+b^2)-(2*I)*exp(-sqrt(t^2*v^2+b^2)-(1/2*I)*v^2*t)/sqrt(t^2*v^2+b^2))*t^2+2*h[1](z)*t+((-(4*I)*t/sqrt(t^2*v^2+b^2)-2)*exp(-sqrt(t^2*v^2+b^2)+(1/2*I)*v^2*t)+(-2+(4*I)*t/sqrt(t^2*v^2+b^2))*exp(-sqrt(t^2*v^2+b^2)-(1/2*I)*v^2*t))*t+h[2](z)+(2*t+(2*I)*t^2/sqrt(t^2*v^2+b^2))*exp(-sqrt(t^2*v^2+b^2)+(1/2*I)*v^2*t)+(2*t-(2*I)*t^2/sqrt(t^2*v^2+b^2))*exp(-sqrt(t^2*v^2+b^2)-(1/2*I)*v^2*t), t = z/v))/v): print(): # an even more simplified expression dM1 := diff(M1(z), z) = simplify(expand(rhs(dM1)));
 (1)
 >

## To understand where the abs(1, ...) come...

To understand where the abs(1, ...) comes from and to handle correctly the discontinuity of the dervative when
(.9*sqrt(-c^2+1)-.4358898944*c)/(-.9*sqrt(-c^2+1)-.4358898944*c)) = 0, please look this

 > restart:
 > diff(log(abs(c)), c)
 (1)
 > f := piecewise(c < 0, log(-c), c > 0, log(c))
 (2)
 > diff(f, c)
 (3)

 > I3 := -sqrt(-c^2+1)*piecewise(F(c) < 0, log(-F(c)), F(c) > 0, log(F(c)), undefined)
 (4)
 > diff(I3, c)
 (5)
 > eval(%, F(c) = (.9*sqrt(-c^2+1)-.4358898944*c)/(-.9*sqrt(-c^2+1)-.4358898944*c)):
 (6)
 >

## The limit is +infinity if x > 1 and h...

Unless I'm mistaken, the limit is +infinity if x > 1 and has a finite value if x < 1 (undefined for x=1):

 > restart:
 > J := Int(Int(exp(-(y-beta[0]-beta[1]*x-b0-b1*x)^2/(2*sigma^2))*exp(-b0)*exp(-b1),b0=0..infinity),b1=0..infinity)
 (1)
 > J0 := op(1,J)
 (2)
 > combine(op(1, J0), exp); T := Student:-Precalculus:-CompleteSquare(%, b0)
 (3)
 > T_e := op(T);
 (4)
 > Remainder := add(op(2..-1, T_e)): Gauss := op(1, T_e): J0 := exp(Remainder)*Int(exp(Gauss), b0=0..infinity);
 (5)
 > # the integral is obviously equal to 1/(2*sigma*sqrt(2*Pi)) J0_sol := exp(Remainder)/(2*sigma*sqrt(2*Pi))
 (6)
 > J1 := Int(J0_sol, b1=0..+infinity)
 (7)
 > J1 := expand(combine(J1, exp));
 (8)
 > J := value(%);
 (9)
 > eval(J) assuming x < 1
 (10)
 > eval(J) assuming x > 1
 (11)
 >

## Replace ; by : at the end of the command...

Replace ; by : at the end of the command

## https://www.maplesoft.com/support/help...

1. https://www.maplesoft.com/support/help/Maple/view.aspx?path=ProgrammingGuide/Chapter15
next choose Multithread programming and/or Parallel programming (it depends on what type of "parallelization" you are interested in).
2.  I'm sure there is a little two parts course on the Posts section of Mapleprimes (it was pretty well done... author dohashi ??? ).
Unfortunately iI couldn't retrieve it.

## @radaar "Will Grid:-Map use a ...

"Will Grid:-Map use a lot of memory? " : It depends on the way you have coded.
From experience, reducing the computation time with Grid is very easy, but avoiding used memory inflation can be a hard task.

The first thing to do is:

1. Run your code on a single proc and catch the memory used from the task monitor (if you use Wondows).
Look also to the runing process dubbed "mserver" and rnote the memory it uses ; let's notoe it S.

2. Do the same by using Grid on P processors. You will have P+1 mserver processes: look to the memory size they use (depending on your programming you could have P processors with size S and one "the parent one" with size P*S: this means you will have to search in your code why it consumes so many memory when run on P processors).

3. I don't have Windows right now to give you the correct command I use to use, but you can catch programmatically the total memory used (the command can be run with ssystem("command"))

More generally, if you are interested to use Grid, here are a few advices (from experience):

1. Avoid using convert(blablabla, X) where X is a set, list, array, matrix, ...; from experience this can dramatically inflate the memory. So think first to the good structure blablabla must have.

2. Avoid solve and prefer fsolve. I do not understand why solve tends to increase memory (maybe a point related to the remember table solve uses?) , but it seems to be the fact.

3. grid:-Run and Grid:-Launch seem to do the same thing, but it's not true and a code optimized for one of them can give poor results when run with the other one.

4. Forget garbage collector gc: it doesn't work on multiple processors

So, no real answers here, just be very careful: a code that requires a small amount of memory on a single processor can be very greedy on multiple processors (i already crashed my 64 Gb machine with "raw" coding when a good coding used less than 1Gb)

## Here are two ways to do this.  &nbs...

Here are two ways to do this.

 > restart:
 > with(Statistics):
 > C := RandomVariable(Cauchy(0, 1)):
 > # The easiest way N := 10^4: C_sample := Sample(C, N, method=[envelope, range=-1..1]): Histogram(C_sample); [Mean, Variance](C_sample); CodeTools:-Usage( Sample(C, N, method=[envelope, range=-1..1]) ):
 memory used=507.56KiB, alloc change=0 bytes, cpu time=7.00ms, real time=7.00ms, gc time=0ns
 > # A lengthy way p := Probability(C < -1, numeric); q := 1-Probability(C > 1, numeric); U_sample := Sample(Uniform(p, q), N): C_cdf  := unapply(CDF(C, z), z): C_icdf := unapply(solve(C_cdf(u)=z, u), z); C_sample := C_icdf~(U_sample): Histogram(C_sample); [Mean, Variance](C_sample); CodeTools:-Usage( C_icdf~(U_sample) ):
 memory used=2.21MiB, alloc change=0 bytes, cpu time=30.00ms, real time=30.00ms, gc time=0ns
 >

## Completing Carl Love's reply: if you...

Completing Carl Love's reply: if you want to pick "without replacement" and "without order constraints" (that is the nth picked number is not necessarily greater than the previous one) P numbers from a list L you must use combinat:-randperm

 > restart
 > L := [\$1..100]:
 > P:= 3: combinat:-randperm(L)[1..P]
 (1)
 > # compare this for k from 1 to 10 do   combinat:-randcomb([\$1..5], 5) end do;
 (2)
 > # to this for k from 1 to 10 do   combinat:-randperm([\$1..5], 5) end do;
 (3)
 >

## If you really want to use colorscheme yo...

If you really want to use colorscheme you can use this (the key point is style=point)

N  := numelems(x1):
xy := convert(Matrix(2, N, [x1, y1])^+,listlist):

plot(xy, style=point, colorscheme=["zgradient", ["Orange", "Red", "NavyBlue"]]);  # for instance

Another way to blavk/Blue coloring:

with(plots):
display(seq(pointplot([x1[k], y1[k]], color=piecewise(z1[k]<0.5, "Black", "RoyalBlue")), k=1..N))

## ...

 > restart
 > fe := Int(sqrt(1+(-5.557990765*sin(5.557990765*x)-7.3*cos(5.557990765*x)-5.6*sinh(5.557990765*x)+7.3*cosh(5.557990765*x))^2), x = 0 .. al)
 (1)
 > # this to have a broad idea of a search interval plot(evalf(subs(al=a, fe)), a=0..1, gridlines=true)
 > g := proc(a)   evalf(subs(al=a, fe))-0.5 end proc;
 (2)
 > fsolve(g(al), al=0..1);
 (3)
 > evalf(subs(al=%, fe))
 (4)
 >

## What do you mean by "surrogate optimiza...

@Carl Love

What do you mean by "surrogate optimization built in function"?
A surrogate can be as simple as the linear model Statistics:-LinearFit returns, or as complex as a neural network (Maple 2018 and later) with, in between GPE (gaussian process emulation such as kriging for instance).
Surrogate-based optimization generally uses GPE

As Carl wrote you could use the Kriging interpolation (I think this requires Maple 2018 or later).
But this implementation of the kriging method is more related to geostatistics than to surrogate modeling of an expensive code (mainly: correlation functions not well adpated).

There also exists a (commercial) toolbox dubbed "GlobalOptimization" which  is supposed to implement the EGO (Efficient Global Optimization method based on kriging surrogates).... unfortunately it gives poor results and doesn't work as claimed (in particular it can't be parameterized as described in the help pages; I posted a question about it a few weeks ago).

My personal (and thus questionable) opinion is that Maple is not yet adpated to do Surrogate-based optimization.

## I can't picture out what your proble...

I can't picture out what your problem really is...

1. Were did you find this procedure "print", is it one you wrote somewhere else?
2. Use Matrix instead of matrix with strng type elements.

 > restart:
 > problems := Matrix(5, 1, [M1, M2, M3, M4, M5])
 (1)
 > # g := "negative effect on the health of the consumer"
 > PA := "probability occurrence of each problems"
 (2)
 > g := Matrix(1, 3, [1, 2, 3])
 (3)
 > Criteria := Matrix(1,3,[ "not serious",  "moderately serious", "very serious"]); #` For each value of g we print the corresponding adjective from the matrix Criteria ` for i from 1 by 1 to 3 do   if  g(i)=i  then        print(Criteria(i));     end if    end do
 (4)
 > IN := Matrix(1, 3, [1, 2, 3])
 (5)
 > A := Matrix(1, 3, ["without risk", "occasional dange", "very common danger"])
 (6)
 > for i to 3 do   if IN(i) = i then     print(A(i))   end if end do
 (7)
 >