acer

32333 Reputation

29 Badges

19 years, 320 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

This looks like a question asked here a few days ago.

ee:=2/3*37^(1/2)*sin(1/6*Pi+1/3*arccos(55/1369*37^(1/2)))+2/3:
radnormal(expand(convert(ee,expln)));

                                         4

acer

Do you think that your original attempt did not work? You did not reassign to `u` in that last line. But otherwise, why isn't the rhs of the last line's output not what you want?

You may wish to achieve that without having to explicitly enter all the substitutions.

evalc(u);

subsindets(u,specfunc(anything,conjugate),z->op(z));

acer

It looks like some strange bug, that `subs` or 2-argument `eval` are not mapping automatically across M.

It seems to depend on the line,

M:=M(2..,..);

right after the call to `myM`.

One of the effects of the programmer (round bracket) indexing here is that the chopped Array has its indices start from 1. So the first index starts from 1 rather than from 2.

The following gets an Array similarly indexed from 1..4,1..3, using regular square bracket indexing following by redimensioning. And it does not seem to exhibit the bug.

M:=M[2..,..];
rtable_redim(M,1..4,1..3);

But this is also a little strange, maybe, since the entries of the result from the final subs(ans,M) now print as if there were fully evaluated. And, as discussed a few weeks ago, this is just an artefact of `rtable/print`, since lprinting reveals that the final entries still contain unevaluated `exp` calls as expected.

Of course, Alejandro's suggestion to map  `subs` also gets it done. Note the expected display of the unevaluated `exp` calls in the final result of the `map2` call.

(A wild guess is that the flag normally only toggled by rtable_eval(...,inplace) might have been set on the offending Array M, perhaps somehow interfering with subsequent evaluation of it.)

acer

Maple does a better job with simplifying these as expressions involving radicals, and one way to get such here is via intermediate conversion to `expln` and expanding.

restart;
poly:=2*x^3-4*x^2-22*x+24:

{solve(poly,x)};

                           {-3, 1, 4}

r1:=2/3*37^(1/2)*sin(1/6*Pi+1/3*arccos(55/1369*37^(1/2)))+2/3:
r2:=-1/3*37^(1/2)*(sin(1/6*Pi+1/3*arccos(55/1369
    *37^(1/2)))+3^(1/2)*sin(1/3*Pi-1/3*arccos(55/1369*37^(1/2))))+2/3:
r3:=-1/3*37^(1/2)*(sin(1/6*Pi+1/3*arccos(55/1369*37^(1/2)))-3^(1/2)
    *sin(1/3*Pi-1/3*arccos(55/1369*37^(1/2))))+2/3:

map( p-> radnormal(expand(convert(p,expln))), {r1,r2,r3} );

                           {-3, 1, 4}

acer

Would it suffice for your purposes to have a wrapping procedure which itself calls plot?

Eg,

sine:=(Amp,freq,phase,t)->Amp*sin(2*Pi*freq*t+phase):
makeit:=freq->plot(sine(1,freq,0,t),t=0..1,title=cat(freq," sine wave cycles")):
makeit(2);

I don't know what exactly you want to do with it, but one possibility in Maple 17 is,

Explore(makeit(freq),parameters=[freq=1..5]);

You of course change the (dummy) parameter name in that last example to something else. Or you could make a wrapping procedure which also accepted aditional arguments for, say, amplitude and phase.

ps. apologies to Carl, who answered similarly during the time I was writing this...

acer

In Maple 17 the so-called "action code" behind an embedded component is accessible using right-click context-menu items like "Edit Value Changed Action" on the component themselves.

In Maple 16 all the action codes were accessible only from the Properties popup panel, which itself is accessed via right-click context-menu of the components.

When an embedded component is inserted into the worksheet from the Components palette its action code is essentially empty; it usually just contains this fragment (with its rather poor advice to use DocumentTools:-Do),

use DocumentTools in 
# Enter Maple commands to be executed when the specified
# action is carried out on the component.
# Use: 
#    Do( %component_name );
# and
#    Do( %component_name = value );
# to set and get properties of the component.
# You can also use arbitrary expressions
# involving components, e.g.:
#    Do( %target = %input1 + 2*%input2 );
# Note the %-prefix to each component name.
# See ?CustomizingComponents for more information.

end use; 

I find DocumentTools:-Do to be quite inadequate for serious work; its special evaluation rules hinder more than help, and it lacks the full power of DocumentTools:-GetProperty and SetProperty.

A somewhat common practice is to put just a one or a few function calls behind in the components -- as such action code -- with the procedures defined in the Startup or Code-edit regions. That makes it easier to edit them all at once, and easier to share common controlling code amongst several similar components.

acer

You are assigning to `T` (the module local name) the numeric result from the first instance of calling fsolve.

But then the second time you call build the expression eqT it contains that numeric value instead of an unassigned symbol.

Try something more like this, using a separate name for the result.

test:=module()

   uses DT = DocumentTools;
   export suwak;
   local T;
	 

   suwak:=proc()
   local amb, solT;

      amb := evalf(DT:-Do(%SL_test)); #slider value
      eqT := 11728.59290-6.614552014*T
             = (T-amb)*(10+4.819840000*10^(-8)*(T^2+88804)*(T+amb)); #equation to fsolve
      solT:= fsolve(eqT, T = 0 .. 2000); #solution
      DT:-Do(%mc_test=amb); #slider value to mathcontainer
      DT:-SetProperty('LBL_test', 'caption',
                      cat("= ", sprintf("%.3f", solT))); # results from fsolve to label

   end proc;

end module;

acer

While your OpenMaple programme is running, interrupt it. I mean, if you are running it in a commandline shell then try Ctl-c. If you've coded your program with suitable calls to `queryInterrupt` then you can make use of this as you see fit.

The purpose of the queryInterrupt, I believe, is to detect the interrupt-request in such a way that your OpenMaple code can handle it as you see fit.

This can also be useful for define_external (or call_external calls) used from regular Maple. While in some compiled "external" function Maple may not get enough control to halt, even if the user has emiited Ctl-c or pressed the red-button on the GUI menubar. But if the external code were to make periodic calls to `queryInterrupt` then that could provide the opportunity to detect the interrupt (and act how you wish... emit an error, or what have you...)

That's my rough understanding, at least.

acer

One consideration is the power to control the namespace. For example, allowing names used as exports from some packages to be used also (concurrently) as assigned names (in procedures as locals, or wherever).

Another consideration is convenience. How easily can the user specify that a package name is to be used. Especially relevant for convenience is the case where the user does not need or want to assign to the name.

Power and flexibility vs ease of use is an eternal struggle for software design. And each of the ways you mention can be considered in those two respects. How well they fare will also involve how often the package names get utilized in those scenarios.

ps. I prefer packagename:-packageexport over packagename[packageexport] in the case that the package has been implemented as a module. Some reasons relate to the colondash help-page and tragi-comic scenarios where packagename[':-packageexport'] might be needed over packagename[packageexport]. I believe it a great shame that the square-bracket indexing was used throughout the help of module based packages implemented back in Maple 6,7,8 just because not all table based packages had been updated to modules. I find the need to iterate programmatically over a package's exported routine names -- using the square bracket indexing form -- is rare in most people's usage and doesn't justify having suboptimal Help.

acer

This might work, even if `a` is assigned some indexable value (eg. a:=[3,4] or whatever).

   plot(sin(x), labels=[typeset('a[0]'), "some text"]);

acer

In Maple 17 your original example appears to work ok.

In Maple 16 you might be able to try one of these kinds of workaround (depending on your more involved situation),

restart:
with(Statistics):

probfunc := i->piecewise(i=1,0.25,i=2,0.4,i=3,0.35,0):

Y := RandomVariable(ProbabilityFunction=probfunc,Support=1..3):

Mean(Y);

                          2.100000000

Variance(Y);

                          0.5900000000

Z := RandomVariable(ProbabilityTable([0.25,0.4,0.35])):

Mean(Z);

                              2.10

Variance(Z);

                            0.590000

X := RandomVariable(EmpiricalDistribution(<1,2,3>,
                    probabilities=[0.25,0.4,0.35])):

Mean(X);

                        2.0999999999999996

Variance(X);

                          0.5900000000

acer

SetCoordinates not SetCoordinate.

acer

The Explore command has special evaluation rules on its first argument (so that your `plot` call doesn't evaluate before `k` gets a numeric value, etc.) This makes things awkward.

One way to work with this behaviour is to put evaluation of your expressions inside a procedure, and simplyexplore a function call of that procedure. There are a few examples using procedures calls on the Explore example worksheet.

restart:

k := 4* 10-5 ;
mpg[o] := 45;
mpg[ave] := mpg[o] - k*(md /2 );
mpg[mave] := mpg[o] - k*(m / 2);

F:=proc(MD)
  eval('plot'(7.28*m*((1/mpg[mave])-(1/mpg[ave])),m=0..200000),md=MD);
end proc:

F(15000);

Explore(F(md), parameters=[md = 150000..200000]);

Another way is to use GUI equation labels (if enabled, they appear on the right-hand side of your GUI displayed output, and are entered using Ctl-L I believe). In your original example you might instead have used the labels from the mpg[mave] and mpg[ave] assignment lines inside the first argument of your original Explore example, as replacements for appearances of mpg[mave] and mpg[ave].

The special evaluation rules on Explore's first argument are unfortunate, and have been there since its first inception (Maple 11, was it?). It gives the thing a rather un-Maple'ish feel, I think. It's not even really needed, to get the plot explorations possible using context-menu to launch the PlotBuilder on a given output expression. It would be more consistent with other parts of Maple such as the plots:-animate and `frontend` commands to allow a calling sequence something like (this won't work in Maple 17, or course):

   Explore( plot,
            [ 7.28*m*( (1/(mpgo - k*m/2 ) - (1/mpgo - k*md/2) ) ), m=0 .. 200000 ],
            parameters = [k=1/3000 .. 1/2000, mpgo = 40 .. 50] );

acer

For fun...

S := (a,n) -> Matrix([seq([seq(a^k*combinat[stirling2](i,k),
                          k=1..i),0$(n-i)],i=1..n)]):

S(1,3);

                                  [1  0  0]
                                  [       ]
                                  [1  1  0]
                                  [       ]
                                  [1  3  1]
S(a,5);

                        [a    0      0      0    0 ]
                        [                          ]
                        [     2                    ]
                        [a   a       0      0    0 ]
                        [                          ]
                        [      2     3             ]
                        [a  3 a     a       0    0 ]
                        [                          ]
                        [      2      3     4      ]
                        [a  7 a    6 a     a     0 ]
                        [                          ]
                        [       2      3      4   5]
                        [a  15 a   25 a   10 a   a ]

acer

`op` works for a list or a set.

`rtable_num_elems` works for a Vector, Matrix, or Array.

But `numelems` works for them all.

First 250 251 252 253 254 255 256 Last Page 252 of 336