acer

32333 Reputation

29 Badges

19 years, 326 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Replace (e)^(x) with exp(x) .

Also, define your operator like,

f := x -> -ln(x)+exp(x)

But don't put f(x) on the left-hand-side of an assignment statement. It's an abomination.

acer

How about just using the older mechanism, for which ~ is a newer short syntax?

map(int8,map(round,S))

acer

You problem seems to be that you were expecting subs to do an evaluation, following syntactic substitution. It doesn't. Use eval instead. This is a frequently asked question.

restart;

f := diff(y(x),x,x) + y(x) = sin(x):

subs(y(x) = sin(x), f);

                       /  2        \                  
                       | d         |                  
                       |---- sin(x)| + sin(x) = sin(x)
                       |   2       |                  
                       \ dx        /                  

%; # an evalution

                                 0 = sin(x)

eval(f, y(x) = sin(x));

                                 0 = sin(x)

acer

Why not make Track a submodule of Lattice? If you give submodule Track its own ModuleApply then you can continue to call it as before. But it could then have trackElement as its own module local.

Btw the example you posted would work if you hade trackElement defined prior to using it, inside the body of Track. One reason that's undesirable is that Maple has to recreate trackElement each time Track is called, which is a waste of resources.

acer

It isn't clear to whether you are asking for a way merely to display the list r and the list of its type-checked results in an aligned and tabulated manner.

Other have shown how to print a sequence of lists of lists, which displays horizontally across the worksheet.

But it occurs to me that you might instead be asking for ways to print the pairwise, vertically stacked, and horizontally aligned, results. That is, with a row of entries of r displayed on top of a row of the type-check results. It occurs to me that you may be looking for such a particular form of display, for the sake of your students, say.

So, on the chance that I've guessed rightly, here are a few ways to get that effect without the need to clutter the worksheet with the fenced boundaries of a pretty-printed Matrix. Note that in the examples below there is no returned value from the code which does the display. It's just an act akin to printing.

If current and older Maple you can use the printf command for such formatted display. A drawback here is that there is not prettyprinting of 2D Math.

In Maple 2015.1, using the Standard Java GUI you can also get a variety of effects from an embedded GUI Table, using the DocumentTools:-Tabulate command. Again, please note that neither of these commands return a value, and moreover you can't interleave all of this display amongst other regularly printed output in the same Execution Group.


restart;

r := [-3, -2.5, 0, 1, 3/2, Pi, sqrt(5)]:

printf("%{}9a\n\n%{}9a\n\n", <r>, <type~(r,nonnegint)>);

       -3      -2.5         0         1       3/2        Pi   5^(1/2)


    false     false      true      true     false     false     false

L := [r, type~(r,nonnegint)]:

oldsetting := interface(typesetting=extended):
DocumentTools:-Tabulate(L, width=500, widthmode=pixels, alignment=left,
                        interior=none, exterior=none);
interface(typesetting=oldsetting):

-3

-2.5

0

1

3/2

Pi

sqrt(5)

false

false

true

true

false

false

false

 

 
  By using strings for true and false we can get them shown with an upright font.

LL := [r, convert~(type~(r,nonnegint),string)]:

oldsetting := interface(typesetting=extended):
DocumentTools:-Tabulate(LL, width=500, widthmode=pixels, alignment=left,
                        interior=none, exterior=none);
interface(typesetting=oldsetting):

-3

-2.5

0

1

3/2

Pi

sqrt(5)

false

false

true

true

false

false

false

 

LLL := [["",r[]],
     ["nonnegint",convert~(type~(r,nonnegint),string)[]],
     ["numeric",convert~(type~(r,numeric),string)[]],
     ["realcons",convert~(type~(r,realcons),string)[]]]:

oldsetting := interface(typesetting=extended):
DocumentTools:-Tabulate(LLL, width=500, widthmode=pixels, alignment=left,
                        interior=none, exterior=none,
                        color=((T,i,j)->`if`(j=1,black,
                               `if`(T[i,j]="true","#009900","#bb0000"))),
                        fillcolor=((T,i,j)->`if`(i=1 or j=1, "#dddddd", "#cccccc")));
interface(typesetting=oldsetting):

 

-3

-2.5

0

1

3/2

Pi

sqrt(5)

nonnegint

false

false

true

true

false

false

false

numeric

true

true

true

true

true

false

false

realcons

true

true

true

true

true

true

true

 

 


tabled.mw

acer

@yellowcanary Be more careful with your implicit multiplication when using 2D Math.

The expression assigned to `Profit`, and the (unassigned) third expression on your original Worksheet are both missing a space (or explicit multiplication symbol) in the first occurence of the subexpression Pa(1-Pb) . What you have there is a function application rather than a product of terms. When Pa gets any numeric value (eg. while plotting) this subexpression evaluates to just that value.

Tom Leslie inadvertantly copied and used this mistaken variant of the `Profit1` expression, I believe.

So correct this by adding in the missing space or an explicit multiplication symbol for this example. Or be safer and always use explicit multiplication, or learn to be safer still and use 1D Maple Notation input mode so that attempts at implicit multiplication gets flagged as a syntax error.

When `Profit1` is corrected, the two surfaces appear more different than before. This helps makes the plotted situation clearer.

You can also use lighting, tranparency, and orientation to try and make the whole thing more clear (given a single static viewpoint). It looks not so bad if plotted like this,

p1:=plot3d(Profit1, Pa=0..Pb, Pb=0..1, color=red, transparency=0.0):
  p2:=plot3d(Profit3, Pa=0..Pb, Pb=0..1, color="Blue", transparency=0.3):
  plots:-display(p1,p2, style=patchnogrid, glossiness=1.0,
                 lightmodel=Light3, orientation=[-150,75,0]);

Another possibility is to add a plot the difference, Profit1-Profit3 . You could even display that beside the original, (or separately, your choice) using something like,

with(plots):
p3:=plot3d(Profit1-Profit3, Pa=0..Pb, Pb=0..1, color=green):
display(Array([ display(p1,p2), p3 ]),
        style=patchnogrid, glossiness=1.0,
        lightmodel=Light3, orientation=[-150,75,0]);

There are several of ways to go.

Using 2D Math input mode, start typing out the equation. At the point where you've just typed the keys d i f f stop and use the simultaneous keystroke combination Ctrl-Tab-spacebar .

On MS-Windows that invokes command-completion on diff. It shows a popup menu of choices. It looks to me as if you want the 3rd entry down, for d/dt. Replace the purple placeholder in the inserted d/dt. For the second derivative raise the top "d" in the d/dt to the power of 2, to get d^2/dt, now all in blackMove the cursor left and continue typing x(t), etc. Use the same process for the other derivative.

This gives you a keyboard acceleration, to get prettyprinted 2D Input. The alternative is to use the palettes (which entails moving your hand off and on the keyboard and mouse pointer, repeatedly.)

Once you've entered you 2D Math ODE you can solve it by typing out a call to the command dsolve. But alternatively you can right-click on the 2D Math expression and use the so-called context-sensitive menu items. The item to choose in the right-click popup is "Solve DE", which offers the subchoice "x(t)".

You can use the right-click context-menus on the 2D Output or the 2D Input (if you have it, as you would here).

On other Operating Systems the keyboard accelerations can be a bit different. See here.

acer

Change that last line of SteamTables.mws to the following (with the file name changed appropriately, for your own computer).

save C00z, bz, A0z, EntropySaturatedLiquidWater, TriplePointPressureWater, bbz, lz,
 SubregionEntropy6z, Bz, CriticalTemperatureWater, SpecificVolumeSaturatedVaporWater,
 alphaz, zz, TriplePointTemperatureWater, C0z, SubregionVolume3z, wz,
 SubregionEntropy5z, SpecificVolumeWater, Lz, SubregionVolume2z, SubregionEnthalpy6z,
 SubregionEnthalpy4z, B00z, SaturationPressureWater, SubregionEnthalpy1z,
 SubregionEnthalpy2z, beta_LLz, alpha0z, beta_Lz, kz, Vz, betaz, Tz, beta_kz, Az, Cz,
 EnthalpySaturatedVaporWater, EntropyWater, SubregionVolume4z,
 SaturationTemperatureWater, EnthalpyWater, CriticalPressureWater, SatTempSubz,
 SpecificVolumeSaturatedLiquidWater, SubregionEntropy2z, nz, Xz,
 EnthalpySaturatedLiquidWater, thetaz, CriticalSpecificVolumeWater,
 SubregionVolume5z, SubregionEnthalpy3z, B0z, Pz, SubregionVolume6z,
 SubregionVolume1z, EntropySaturatedVaporWater, az, dz, SubregionEntropy1z,
 SubregionEntropy3z, SubregionEnthalpy5z, SubregionEntropy4z, "C:\\TEMP\\SteamTables.m";

After that I was able to do the example from Working-w-SteamTables.mws , in a new worksheet,

read "C:\\TEMP\\SteamTables.m";

SpecificVolumeWater(.2*MPa,500*K);

                                      3
                         1.144220489 m 
                         --------------
                               kg      

 

(In passing, this post might be of some interest.)

acer

You can operate beforehand with the more modern Vector V, and then convert that to (deprecated, lowercase) vector VV just for the codegen operations.

This can alleviate (and centralize) the inconvenience, if your V is the result of some earlier computations involving commands which return the more modern Vector.

restart;

with(codegen, optimize, makeproc);

                            [optimize, makeproc]

V := Vector(4);

                                       [0]
                                       [ ]
                                       [0]
                                  V := [ ]
                                       [0]
                                       [ ]
                                       [0]

V[1] := x+y; 
                                V[1] := x + y

V[2] := x^2+y^2;

                                        2    2
                               V[2] := x  + y 

V[3] := x^3+y^3; 

                                        3    3
                               V[3] := x  + y 

V[4] := x^2+y^2+x+y;

                                    2    2        
                           V[4] := x  + y  + x + y

VV:=convert(V,vector);

                    [        2    2   3    3   2    2        ]
              VV := [x + y, x  + y , x  + y , x  + y  + x + y]

T := makeproc([optimize(VV, 'tryhard')], [x, y]);

                           T := proc(x, y)
                           local t1, t2, t5, t6;
                             t6 := x + y;
                             t1 := y^2;
                             t2 := x^2;
                             t5 := t1 + t2;
                             VV[1] := t6;
                             VV[2] := t5;
                             VV[3] := t1*y + t2*x;
                             VV[4] := t5 + t6;
                           end proc;

acer

@Lucas2310 

I used simplex[maximize] instead of Optimization:-Maximize, to get an exact rather than a floating-point result. (I don't understand why you post all your inequaties in calls to PolyhedralSet.)

kernelopts(version);

          Maple 16.02, X86 64 WINDOWS, Nov 18 2012, Build ID 788210

S:=[0 <= (1/25)*b11, 0 <= (1/25)*b22, 0 <= (1/25)*b33, 0 <= (1/25)*b44,
    0 <= -(12/25)*b44+(1/25025)*b99+(4/275)*b2020-(306/5)*b11-(544/35)*b22-(16/5)
    *b33+17050058028932207659/392694612710400000, 0 <= (63/25)*b44-(2/3575)*b99
    -(9/55)*b2020+(12852/25)*b11+(612/5)*b22+(112/5)*b33
    -1859886463352366249/5342783846400000, 0 <= -(182/25)*b44+(1/275)*b99
    +(42/55)*b2020-(9282/5)*b11-(10608/25)*b22-(364/5)
    *b33+10569449395416434161/8630650828800000, 0 <= (273/25)*b44-(4/275)*b99
    -(91/55)*b2020+(15912/5)*b11+(3536/5)*b22
    +(2912/25)*b33-8902222402551338533/4315325414400000, 0 <= (1/25)*b99,
    0 <= -(1001/25)*b44-(2/25)*b99+(273/25)*b2020-(68068/5)*b11-(14586/5)*b22
    -(2288/5)*b33+6773030323238725459/784604620800000,
    0 <= (2574/25)*b44+(3/25)*b99-(182/5)*b2020+(918918/25)*b11
    +(38896/5)*b22+(6006/5)*b33-6049870521396536773/261534873600000,
    0 <= -(3861/25)*b44-(24/175)*b99+(351/5)*b2020-(286416/5)*b11-(2100384/175)*b22
    -(9152/5)*b33+5465968075214691641/152562009600000, 0 <= (4004/25)*b44+(3/25)*b99
    -712028368745424949/18681062400000-(468/5)*b2020+(306306/5)*b11+(63648/5)*b22
    +(48048/25)*b33, 0 <= -(3003/25)*b44-(2/25)*b99+91*b2020-47124*b11-9724*b22
    -1456*b33+4579528093219020391/156920924160000, 0 <= (1638/25)*b44+(1/25)*b99
    -(1638/25)*b2020+(131274/5)*b11+(26928/5)*b22+(4004/5)*b33
    -4234170109213463609/261534873600000, 0 <= -(637/25)*b44-(4/275)*b99
    +(1911/55)*b2020-(259896/25)*b11-(10608/5)*b22-(1568/5)*b33
    +3935028629902940653/616475059200000, 0 <= (168/25)*b44+(1/275)*b99
    -(728/55)*b2020+(13923/5)*b11+(14144/25)*b22+(416/5)*b33
    -3671189442456764071/2157662707200000, 0 <= -(27/25)*b44-(2/3575)*b99
    +(189/55)*b2020-(2268/5)*b11-(459/5)*b22-(336/25)*b33
    +3432194498564787803/12466495641600000, 0 <= (2/25)*b44+(1/25025)*b99
    -(6/11)*b2020+34*b11+(48/7)*b22+b33-3183161946172621261/157077845084160000,
     0 <= (1/25)*b2020]:

sol:=simplex[maximize](-x, S); # if not, then try simplex[maximize](x, S);

           /      3699816803902151           93598739500223  
    sol := { b11 = -----------------, b2020 = --------------, 
            \      12544650979660800          92417930035200  

            74493639125039        53122892719699        2058358715156147           
      b22 = --------------, b33 = --------------, b44 = ----------------, b99 = 0, 
            50235360215040        87574556160000        3314169918259200           

           \ 
      x = 0 }
           / 

map(evalb, eval(S, sol));

    [true, true, true, true, true, true, true, true, true, true, true, true, true, 

      true, true, true, true, true, true, true]

Use Matrix with a capital letter M.

A (lowercase) matrix is of type last_name_eval , which is why you are seeing just that name RES.

Note also that the matrix command is deprecated.

acer

f:=[a,b,c,a,a];

                        [a, b, c, a, a]

[ListTools:-SearchAll(a, f)];

                           [1, 4, 5]

acer

If you have only Maple 16, then could you replace the strict inequalities with nonstrict inequalities to obtain a system for which the simplex[feasible] command could provide a preliminary test?

By "preliminary test" I mean that a false result using the nonstrict constraints would imply an empty feasible set for the tighter, strict constraints. Of course, a true result using the looser nonstrict constraints would not mean that the stricter constraints had any feasible point. (I only mention this weak kind of test because you have Maple 16.)

Let S be the set of (possibly mixed strict and nonstrict) inequalities,

   simplex[feasible](subsindets(S,`<`,u->op(1,u)<=op(2,u)));

The above command quickly returned false in my Maple 16.02 for both your original (smaller) and your first followup (larger) sequence of strict inequalities. 

acer

I'm not exactly sure what output you want. Is it something like this? (If so, then I feel there ought be a more efficient way of generating the frames.)

restart

with(plots):

farey := proc (N::posint) local a, b; sort([op({seq(seq(a/b, a = 0 .. b), b = 1 .. N)})]) end proc:

L := farey(50):

F := []:

for k to nops(L) do F := [op(F), [[L[k], 0], [L[k], 1/denom(L[k])]]] end do:

Ox := 1/2;

1/2

0

M := 1;

1

M1 := M;

1

M2 := 10;

10

N := 10;

10

dM := abs(M2-M1+1)/N;

1

P := [];

[]

N-1

9

for k from 0 to N-1 do print("Frame:", k); M := dM*k+M1; w := 1/(2*M); trule := plottools:-transform(proc (a, b) options operator, arrow; [(1/2)*(a+w-Ox)/w, (1/2)*(b-Oy)/w] end proc); P := [op(P), display(trule(plot(F, Ox-w .. Ox+w, Oy .. Oy+2*w, view = [Ox-w .. Ox+w, Oy .. Oy+2*w], color = black), view = 0 .. 1, axes = none, gridlines = false))] end do:

"Frame:", 0

"Frame:", 1

"Frame:", 2

"Frame:", 3

"Frame:", 4

"Frame:", 5

"Frame:", 6

"Frame:", 7

"Frame:", 8

"Frame:", 9

display(P, insequence = true, axes = none, gridlines = false);

 

NULL

 

Download FareySeq_modif.mw

I can imagine another reasonable interpretation of your question: that you want the first frame to consist of the full shape taking up all the plotted area, and then as it "zooms" the view of the shape gets more and more restricted (in step with the ongoing rescaling) so that for every frame the (shrinking) displayed view takes up precisely the whole plotting area. If this is in fact the case then it is a sort of opposite to what I showed above -- though both zoom in, of course. 

But if you do actually want that other version of "zooming in" then it should not be difficult to use the same basic idea: plottools:-transform and modification of the view.

acer

If T has already been assigned that expression then short and simple is,

V := [2,8,14]:
T := 440*(1-exp(-1/tau)):

evalf(seq(T, tau=V));

              173.1265097, 51.7013629, 30.3323769

And if you want it as a list,

evalf([seq(T, tau=V)]);

             [173.1265097, 51.7013629, 30.3323769]

The stated example problem needs neither eval (or subs) nor unapply.

acer

First 219 220 221 222 223 224 225 Last Page 221 of 336