acer

32510 Reputation

29 Badges

20 years, 12 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Is this what you're after?

FirstList:=[A,B,C,D,E,F]:

combinat:-choose(FirstList,4);
   [[A, B, C, D], [A, B, C, E], [A, B, C, F], [A, B, D, E], 

     [A, B, D, F], [A, B, E, F], [A, C, D, E], [A, C, D, F], 

     [A, C, E, F], [A, D, E, F], [B, C, D, E], [B, C, D, F], 

     [B, C, E, F], [B, D, E, F], [C, D, E, F]]

nops(%);
                               15

acer

 Another possibility might be to use Maple's CodeGeneration[Matlab] command to produce code for a Matlab .m function from the Maple procedure `symb_sol` (then written out to a file), so that all the subsequent pieces are done right in the running Matlab session. 

We haven't been shown the equations which are solved ( via eliminate) so its not possible to tell yet whether all of `symb_sol` can be so handled.

acer

It's difficult to figure out the whole situation, as we do not seem to know what SystemEquations_NoDriver are.

But I don't under stand why you are forming all the symbolic input equations and holding BB_Driverlist_set(i) for all `i` in Maple memory at the same time.

You run (in Matlab), a first loop to store every symbolic equation set, in the BB_Driverlist_set(i). This is the step you've described as loading the control points into Maple.

Then you run another loop (in Matlab), to apply the Maple symb_sol function to every data set previously stored. Each time through the loop this produces a set of results as equations. And then you take rhs's and stuff the numeric results into the next part of a single Matrix. It's a bit dodgy about ordering of equations in a set, according to the name on the lhs, but it works.

Using a single Matrix is probably a good idea. How about a single loop which takes the input set (for a given time point), applies symb_sol, and then puts the result into the appropriate slot in the single result Matrix. And do not store or assign BB_Driverlist_set(i) for all i or for all SimNum.

And especially do not ever create any equation of the form name=expression, in a loop.

I also do not understand why you have to form the symbolic equations in sets. Perhaps I misunderstand the inputs. (Recall that we don't know what your SystemEquations_NoDriver is.)

As I understand it, you are calling from a running Matlab session into Maple to execute various steps of solving and manipulation. By "solving" you seem to mean that you generate an explicit general symbolic solution, and then evaluate this at each timestep's input data. (We'll have to take your word on this being more desriable than repeated numeric solving.)

It seems to me that you are doing something a bit like this,

pars:={ICE_T, BAT_P, EM2_T, EM2_W}:

eqs:={ICE_T=var1+cos(var2),BAT_P=sin(var1),EM2_T=var1^2,EM2_W=var3^2};

                 /                               2              2  
         eqs := { BAT_P = sin(var1), EM2_T = var1 , EM2_W = var3 , 
                 \                                                 

                                   \ 
           ICE_T = var1 + cos(var2) }
                                   / 

symb_sol:=unapply(eqs,[var1,var2,var3]):

ansMat := Matrix(nops(pars), 50000): #Matrix(m, numtimesteps):

# Loop over these next steps...

for i from 1 to 1 do

  ans := symb_sol(1.1,2.3,3.7);  print(ans);

  ansMat[..,i] := Vector([seq( rhs(ans[i]), i=1..nops(pars) )]):

end do:

  {BAT_P = 0.8912073601, EM2_T = 1.21, EM2_W = 13.69, ICE_T = 0.4337239787}

ansMat[..,1];

                               [0.8912073601]
                               [            ]
                               [        1.21]
                               [            ]
                               [       13.69]
                               [            ]
                               [0.4337239787]

How about making it a bit more like this,

pars:={ICE_T, BAT_P, EM2_T, EM2_W}:

eqs:={ICE_T=var1+cos(var2),BAT_P=sin(var1),EM2_T=var1^2,EM2_W=var3^2}:

exprs:=eval([BAT_P, EM2_T, EM2_W, ICE_T], eqs);

                     [               2      2                  ]
            exprs := [sin(var1), var1 , var3 , var1 + cos(var2)]

symb_sol:=unapply(exprs,[var1,var2,var3]):

ansMat := Matrix(nops(pars), 50000): #Matrix(m, numtimesteps):

# Loop over these next steps...

for i from 1 to 1 do

  ans := symb_sol(1.1,2.3,3.7);  print(ans);

  ansMat[..,i] := Vector(ans,datatype=float[8]):

end do:

                  [0.8912073601, 1.21, 13.69, 0.4337239787]

ansMat[..,1];

                             [0.891207360100000]
                             [                 ]
                             [ 1.21000000000000]
                             [                 ]
                             [ 13.6900000000000]
                             [                 ]
                             [0.433723978700000]

Those are just ideas for improvement. Better still might be to have no named equations, anywhere. Pass float[8] Vectors or Matrices of timestep data into Maple. Pump these directly into a procedure. (You may need help in altering your simple `unapply` into another kind of procedure...) And put the results directly into the slots of a float[8] answer Matrix. No equations, no calls to `rhs`, no sets, no lists.

How about passing a single float[8] Matrix of size numtimesteps-by-numinputs in one call from Matlab to Maple. Then make another call from Matlab to Maple which runs a Maple procedure (which you write) that evaluates the "solver" on each row of input data, and then places the results into a row of a results float[8] Matrix. Then pass the whole float[8] answer Matrix back to Maple. Ie, about one or three calls from Matlab to Maple, not 50000+.

acer

Note:

restart:             

'10.2^20';

                                              21
                               0.1485947396 10

Even special evaluation rules (to prevent premature evaluation of arguments in a procedure call, say) will not prevent automatic simplification. Having said that,

restart:

p := proc() 10.2^20; end proc;

                         p := proc() 10.2^20 end proc

evalf[50](p());
                                                             21
               0.14859473959783543420355740092833203224576 10


restart:       

evalf[50](`^`(10.2,20));

                                                             21
               0.14859473959783543420355740092833203224576 10

acer

Using the parameters and compile option of dsolve/numeric allows the same two last plots to be produced, with the overall computation time reduced from about 75 sec to 38 sec.

I also changed the 2D Math of the DE system to 1D Maple Notation. This seems to make the GUI use less resources (and respond better while editing). Your mileage may vary.

Benzene_mod.mw

acer

Note that one can generally ony display colors from what is displayable within the RGB colorspace, which is a smaller triangular region within the visible gamut of the CIE xyY colorspace (which you seem to be constructing).

But it's possible to get an approximation of the visible xyY gamut by shading the non-displayable points with colors obtained by regressing back to the edge of the displayable RGB gamut. Below, this is attempted for the given xy points (presumed as some approximation of the edge of the xyY gamut -- let me know it that's not right).

The final plot does not look fuzzy when run in my Maple 18 Standard GUI. I have used at least one command new to Maple 18 (ColorTools:-ToDisplayable), so this code wouldn't work in an earlier version.

In the followup interpolation I also added the line of purples to what I presume you intend as the spectral color edge.

 

restart:

L:=[[0.1733,0.0048],[0.1726,0.0048],[0.1714,0.0051],
    [0.1689,0.0069],[0.1644,0.0109],[0.1566,0.0177],
    [0.144,0.0297],[0.1241,0.0578],[0.0913,0.1327],
    [0.0454,0.295],[0.0082,0.5384],[0.0139,0.7502],
    [0.0743,0.8338],[0.1547,0.8059],[0.2296,0.7543],
    [0.3016,0.6923],[0.3731,0.6245],[0.4441,0.5547],
    [0.5125,0.4866],[0.5752,0.4242],[0.627,0.3725],
    [0.6658,0.334],[0.6915,0.3083],[0.7079,0.292],
    [0.719,0.2809],[0.726,0.274],[0.73,0.27],
    [0.732,0.268],[0.7334,0.2666],[0.7344,0.2656],
    [0.7347,0.2653]]:


# Procedure to regress a fully saturated, bright xyY colorspace
# point back to the edge of the RGB gamut.

f:=proc(x,y)
  local c,hsat;
  uses ColorTools;
  c:=Color("HSV",ToDisplayable(Color("xyY",[x,y,1.0])));
  hsat:=ToDisplayable(Color("HSV",[c[1],1.0,c[3]]));
  Color("RGB",hsat);
end proc:

plots:-pointplot(L,color=map(f@op,L),symbol=solidcircle,
                 symbolsize=15, scaling=constrained,
                 gridlines=false);


# We can do better, by interpolating the given data of the curve.
#
# Split the data, and sort, in preparation of interpolation.

L1T:=Matrix(sort(map(t->[t[2],t[1]],L[2..12]),(a,b)->a[1]<b[1]),
            datatype=float[8]):
L2:=Matrix(sort(L[11..-1],(a,b)->a[1]<b[1]),datatype=float[8]):
L3:=Matrix([L[1],L[-1]],datatype=float[8]):

N:=300:

# Interpolate three segments, each of N new xy points.
#
# Note the the first piece interpolates by y-value (since the curve is
# not steep in that orientation, and so that the new points are more
# evenly spread).

V1y:=Vector(N+1,(i)->min(L1T[..,1])+(i-1)*(max(L1T[..,1])-min(L1T[..,1]))/N,
            datatype=float[8]):
V1x:=CurveFitting:-ArrayInterpolation(L1T,V1y,method=cubic):
V2x:=Vector(N+1,(i)->min(L2[..,1])+(i-1)*(max(L2[..,1])-min(L2[..,1]))/N,
            datatype=float[8]):
V2y:=CurveFitting:-ArrayInterpolation(L2,V2x,method=cubic):
V3x:=Vector(N+1,(i)->L[1][1]+(i-1)*(L[-1][1]-L[1][1])/N,
            datatype=float[8]):
V3y:=CurveFitting:-ArrayInterpolation(L3,V3x,method=linear):

# Now form the pointplot, and use f(x,y) for the coloring.

opts:=symbol=solidcircle,symbolsize=15:

plots:-display(
   plots:-pointplot(<V1x|V1y>,color=[seq(f(V1x[i],V1y[i]),i=1..N+1)],opts),
   plots:-pointplot(<V2x|V2y>,color=[seq(f(V2x[i],V2y[i]),i=1..N+1)],opts),
   plots:-pointplot(<V3x|V3y>,color=[seq(f(V3x[i],V3y[i]),i=1..N+1)],opts),
              view=[0..0.8,0..0.9],scaling=constrained,gridlines=false);

 


Download cie_xyY_gamut.mw

 

A nice task would be to use Maple to produce an ImageTools image or a densityplot, with the whole gamut shaded.

acer

restart:

FF := Q-1+(1/5)*K*dp^3*h^5+(1/3)*dp*h^3+h+h1*h:
DDP:=[solve(FF,dp)]:
h:=1+phi*cos(2*Pi*x):
h1:=2*Pi*alpha*beta*phi*cos(2*Pi*x):
beta:=1:alpha:=0:
phi:=0.5:
dpdx:=evalf(DDP[1]):
dpp:=Int(Re(dpdx),x=0..1):

plot([subs(K=-0.1,dpp)],Q=-1..1,axes=box,color=[blue]);

acer

The answer is not the one you expected, but it is not completely invalid. Degrees can represent an absolute or a relative scale.

A temperature of 32.0 degC is the same as a temperture of 89.6 degF.

But if the temperature is increased by 32.0 degC then it is increased by 57.6 degF.

The context menu does the latter conversion. Perhaps it could be augmented with a way to do either.

 

convert( 32.0*Unit(degC), units, degF);

                57.60000000 Units:-Unit('degF')

convert( 32.0*Unit(degC), temperature, degF);

                 89.6000000 Units:-Unit('degF')

acer

Could you not transform the plots with cartesian coordinates?


restart:

sys := diff(x(t), t) = -y(t)+x(t)*(1-2*x(t)^2-3*y(t)^2),
       diff(y(t), t) = x(t)+y(t)*(1-2*x(t)^2-3*y(t)^2):

sys1 := diff(r(t), t) = r(t)*(1-2*r(t)^2-r(t)^2*sin(theta(t))^2),
        diff(theta(t), t) = 1:

conv:=plottools:-transform((a,b)->[a*cos(b),a*sin(b)]):

P0:=DEtools[DEplot]({sys1},[r(t),theta(t)],t=0..10,[[theta(0)=Pi,r(0)=2]],
           arrows=none,thickness=1,linecolor=burgundy):

plots:-display(conv(P0),axiscoordinates=polar);

q1 := dsolve([sys1, theta(0) = Pi, r(0) = 2], numeric, [theta(t), r(t)]):
P:=plots:-odeplot(q1, [r(t), theta(t)], t = 0 .. 10):

plots:-display(conv(P),axiscoordinates=polar);

 


Download polarde.mw

acer

eval(irem(m,4),m=21);

                               1

eval('`mod`'(m, 4), m=21);

                               1

Even if you were to obtain an unevaluated return from the call `mod`(m,4), then you'd still need an evaluation after substituting with `subs`.

acer

The time for the rank computation should dwarf time for the (uniform dist.) random float[8] Matrix creation as the dimension n gets large. So the two operations should have their timings done separately.

And CodeTools:-Usage is a more convenient way to demonstrate the performance in later Maple versions, IMHO.

I am seeing better results for LinearAlgebra:-Rank on float[8] Matrices in Maple 18.01 on 64bit Linux.

On 64bit MS-Windows I see Rank performing as in 18.00, although LinearSolve and MatrixInverse do a bit better better than in 18.00.

acer

Your original attempt is not so bad, and I believe you can get it to work without having to make temporary substitutions for `a` and `z`. But you did forget to map the `limit` command when assigning to H, since expr2 will also be a Vector.

Note that your post contained the invalid syntax,

  phi := -> z (l*z+a)/(1-l*conjugate(a)*z):

Was you intention that it instead be,

  phi := z -> z*(l*z+a)/(1-l*conjugate(a)*z):

or,

  phi := z -> (l*z+a)/(1-l*conjugate(a)*z):

I'll use the former, as Markiyan has. Using the latter and Omega becomes not just the zero-Vector.

> restart:    

> omega := z -> 2*<Re(z), Im(z), 1>/(1+abs(z)^2):
> phi := z -> z*(l*z+a)/(1-l*conjugate(a)*z):
> expr := omega(phi(1/e)):

> Omega := simplify(map(limit, expr, e = 0)) assuming l::real;

                                          [0]
                                          [ ]
                                 Omega := [0]
                                          [ ]
                                          [0]

> expr2 := (omega(phi(1/(e^2*conjugate(z))))-Omega)/e^2:

> H := simplify(map(limit, expr2, e = 0)) assuming l::real;

                               [       1     _2 _2  ]
                               [-2 Re(---) | z  a  |]
                               [      _ _           ]
                               [      z a           ]
                               [                    ]
                          H := [       1     _2 _2  ]
                               [-2 Im(---) | z  a  |]
                               [      _ _           ]
                               [      z a           ]
                               [                    ]
                               [         0          ]

I haven't yet been able to get Maple to simplify the difference of these two scalar expressions to zero, unless I substitute and evalc.

T1 := Im(a)*Im(z)-Re(a)*Re(z):

T2 := -Re(1/(conjugate(z)*conjugate(a)))*abs(conjugate(z)^2*conjugate(a)^2):

I obtained T1 in the result obtained with substituting fore and aft for `a` and `z` as Markiyan did.

acer

Are you saying that you know the nature of x at some juncture, and you want to find out what `f` will become there? Eg,

restart:

f := piecewise(x>0,1+x,x=0,2,x<0,1+x^2):

expr1 := eval(f) assuming x>0;

                             1 + x

expr2 := eval(f,x=0);

                               2

expr3 := eval(f) assuming x<0;

                              2    
                             x  + 1

Or do you need to extract out both the conditions and the subexpressions from `f` (which possibly you did not create yourself). For that you can use `op`, or indexed into it as a list. Eg,

flist := convert(f,list);

            [                                2    ]
            [0 < x, 1 + x, x = 0, 2, x < 0, x  + 1]

flist[1];

                             0 < x

flist[2];

                             1 + x

# ...and so on

Of course, if you built `f` yourself, explicitly, then you could simply assign the various conditions and pieces to names, beforehand. Eg,

restart:

cond1:=x>0:
expr1:=1+x:
cond2:=x=0:
expr2:=2:
cond3:=x<0:
expr3:=1+x^2:

f:=piecewise(cond1,expr1,cond2,expr2,cond3,expr3);

acer

restart; 
vvv:=n^2+3*m:
g:=(n,m)->vvv:

g(1,1);

                             2      
                            n  + 3 m

g:=unapply(vvv,[n,m]):

g(1,1);
                               4

Spamming this site by posting the same issue multiple times is irritiating. Please stop doing that. It's not the first time.

acer

How about something with `applyrule`, such as say,

  map2(applyrule, d^(n::And(posint,satisfies(t->t>=2)))=0, myeq);

I realize that `applyrule` is a command in the Library of interpreted procedures and not a compiled kernel builtin. I had the idea that by "builtin" you meant something else.

acer

First 241 242 243 244 245 246 247 Last Page 243 of 337