acer

32395 Reputation

29 Badges

19 years, 344 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

If you are using Maple 2016 then you could try the undocumented
command Worksheet:-WorksheetToMapleText .

It will accept a file name as its argument (as a string). For example,

Worksheet:-WorksheetToMapleText( filenm );

where filenm is a quoted string such as, say, "C:\\\\TEMP\\foo.txt" on MS-Windows, etc.

It appears to return a string containing plaintext 1-D Maple Notation versions of input commands in the original. You could programmatically export such a string to a plaintext file using the FileTools:-Text package.

It appears to support both 1-D and 2-D input, as well as both Execution Groups in .mw format Worksheets and Document Blocks in .mw format Documents. It also seems to handle comments beginning with #. It also seems to support code in the .mw file's StartUp Region.

It does not seem to currently handle GUI Tables whose cells themseleves contain Execution Groups, except by placing such inputs into # comments, and in doing do it does not respect the Table property of execution-by-row versus execution-by-column.

docexample.mw

WToMapleT.mw

If you really want line numbers and the style of output that `showstat` produces then you could try using the procedure `p` in the attached worksheet instead. It seems to do what you want in my Maple 2015.2 and Maple 2016.0. (I've only tried it on 64bit Windows 7...)

showstat_writeto.mw

If you don't really need the line numbers, but you do want `printf` style output, then you could try the following instead, to get the body of procedure (assigned to `F`) into the file:

interface('prettyprint'=1):
interface('verboseproc'=3):
writeto(whateveryourtargetlocation)
print(F);
writeto('terminal'):

See the help page ?keywords

The single left-quote ` which is also known as a backtick, is a name quote. By using it you can use a reserved keyword ( or a symbol like * ) as a name.

Some of the reserved keywords ( and some symbols, like * and + ) are also the names of procedures (aka commands). In order to call those procedures you need to refer to them by name. Hence to do so you need to use these backtick name quotes. These are referred to as the operator form (of these keywords). The help page ?keywords lists 11 keywords that have an operator form.

Not all the reserved keywords are also the names of procedures. But there are still lots of other ways to use words as names in Maple, apart from using them for procedure calls. See the following attached sheet for some other examples of using these keywords as names.

You also mentioned unevaluation. The single right-quote ' is the unevaluation quote. and is sometimes referred to as the forward-quote. It serves a different purpose than the single left-quote ` which is the name quote. Using name quotes does not prevent evaluation of an expression or a name (in the case that the latter had been previously assigned a value).

Name-quotes can also be used to create names with spaces or some other non-alphanumeric characters.

restart;

type( :-x, `global` );
type( :-x, `local` );

temp := proc() local y; y; end proc();
type( temp, `global` );
type( temp, `local` );

true

false

y

false

true

type( :-x, global );

Error, reserved word `global` unexpected

cat( `in`, blech );

inblech

cat( in, blech );

Error, reserved word `in` unexpected

`if`( 3<4, foo, bar );

foo

if( 3<4, foo, bar );

Error, `;` unexpected

`*`(2, 3, 5);  # not a keyword, but same idea as previous example

30

*(2, 3, 5);

Error, `*` unexpected

op( 1, `union` );

proc () option builtin = `union`; end proc

op( 1, union );

Error, reserved words `union` or `minus` unexpected

help(`minus`);

help(minus);

Error, reserved words `union` or `minus` unexpected

seq(p, p=[`intersect`, `local`]);

`intersect`, `local`

seq(p, p=[`intersect`, local]);

Error, reserved word `local` unexpected

T[`while`];

T[`while`]

T[while];

Error, reserved word `while` unexpected

`then`:=sin; # gosh
`then`(Pi/6);
if 3<4 then foo; else bar; end if;

sin

1/2

foo

then:=sin;

Error, reserved word `then` unexpected

unprotect(`stop`);
`stop`:=11; # gosh
`stop`:='`stop`';

11

`stop`

proc() local `stop`; `stop`:=15; end proc(); # gosh

15

 

Download keywordexamples.mw

After some attempts with both NLPSolve and DirectSearch v.2 I got a 15-digit result. (Actually, even the 10-digit evaluation of this result seems to be effectively "as good".)

Both solvers seemed to be helped by forcing the particular values psi1=0, psi2=0, psi3=1. I could sometimes get a close objective value otherwise, but it was more effort, and if I recall psi3 was then close to 1 and psi1 and psi2 were very small and positive. Of course it might possible that there is some better solution, including where these special values for psi1, psi2, and psi3 do not hold. But I've been unable to find such (and I've obtained quite a few measurably worse results).

I had to convince NLPSolve not to bail upon finding a nonreal intermediate result. It helped to specify additional bounds on the variables so that they were greater than a small number, and also to set the feasibilitytolerance. Both those values had to hinge on Digits the working precision, for which I eventually attained success at about Digits=25.

The values for m3 and sigma3 below appear to characterize the objective value, though I don't have the time to investigate that. The other values may even vary...

sol := [m1 = 132.230870980192, m2 = .235777926135309, m3 = 83.8783484167608,
        sigma1 = 1.38646084816784, sigma2 = 56.2598001093216,
        sigma3 = 11.1080802815944,
        x = 83.4706268673915, psi1=0.0, psi2=0.0, psi3=1.0]:

Digits,oldDigits := 1000,Digits:
andmap(op(eval(constr, sol)));
Digits := oldDigits:
                              true
Digits,oldDigits := 1000,Digits:
eval(fungsikerugian, sol):
evalf[15](%);
Digits := oldDigits:
                        10.3625246173745

Yes, that's what's happening. I'm deleting a handful of such spam Comments each day for the past week or two.

I haven't figured out what exactly is going on with your attempt yet. But how about changing the vertical computational range, while enforcing a `view`?

Also, the `restricttoranges` option forces the bounds precisely.
 

restart;

a:=0: b:=1:

plots:-densityplot(z, dummy = 0 .. 1, z = b-360/240*(b-a) .. b,
                   view=[0 .. 1, a .. b],
                   grid = [2, 10], size = [90, 100],
                   colorscheme = ["zcoloring",
                                  [z -> -z,
                                   z -> 1, z -> 1],
                                  colorspace = "HSV"],
                   style = surface, axes = frame, labels = ["", ""],
                   axis[1] = [tickmarks = []], title = "Test",
                   titlefont = ["Calibri", "Bold", 16],
                   axesfont = ["Arial", 14],
                   size = [100, 500], restricttoranges);

kernelopts(version);

`Maple 2016.1, X86 64 LINUX, Apr 22 2016, Build ID 1133417`

 


 

Download coolhot.mw

If you want to avoid the use of a custom (user-defined) procedure (ie. to have it use only kernel builtins for efficiency) then you could use the shorter syntax,

map2(`.`,A,LM)

FWIW, the call,

[A,A] .~ LM;

is more like the following,

zip(`.`,[A,A],LM);

I note that `zip` does have a nicer error message when the container types do not agree. (In a sense your original attempt using .~ is a bit more like the next failing example below.)

zip(`.`,A,LM);
Error, (in zip) both arguments being zipped must be of the same type

zip(`*`,[1,2,3,4],A);
Error, (in zip) both arguments being zipped must be of the same type

If you are willing to allow all the computations to be done within a single procedure call (ie. you don't need to quit early if, say, some target value is attained) then you could construct such a procedure and utilize the codegen[optimize] command.

You can try it with and without the option `tryhard` to that command. It can sometimes produce better results, but with a longer runtime to produce it.

Naturally, you'd likely want to automate the steps which generate all the variable names (and the placeholders for the high and low values, etc). You may already ha a mechanism for that.

Download opt.mw

Here are a few ideas. (I used Maple 2016.)

wideoutput.mw

[edited] In at least Maple 2017.0 the first of the four methods in the attachment (interface labelling, etc) also requires interface(typesetting=standard) in order to work.

 

In a paragraph (Document Block) of a Document the left-hend-side of an assignment is not echoed. But it is echoed when done in an Execution Group (whether done in 2-D Math input mode or 1-D Maple Notation input mode).

The simplest way to get (all) Execution Groups for your inputs is to use the main menubar File->New->Worksheet Mode, rather than the normal new-user default File->New->Document Mode. (You can also set that preference for new sheets, under Tools->Options.)

But even in a Document you can still force open an Execution Group using the menubar item Insert->Execution Group.

As I mentioned, inside an Execution Group you have the choice of 2-D or 1-D input modes. The F5 key toggles between them.

In 2-D Math input mode (in the Standard GUI of recent Maple versions) that is available by command-completion on the name eval (or its inert variant Eval).

For example, on MS-Windows, in 2-D Math input mode, type as input the word eval and then hit the Esc (Escape) key. That should bring up a popup dialogue menu, the first item of which is the one you are after.

See also the Help Topic worksheet,expressions,completecommand

For your example the active variant with lowercase eval will compute eval(H1, t=0.45) which evaluates H1 at t=0.45.

The active variant eval and the inert variant Eval differ in how they look in this 2-D Math format: the active eval form has a black vertical bar and the inert Eval form has a gray vertical bar.

If you decrease the grid size by using, say, the option grid=[10,10] then there will be less hatching but also the surface with be less accurate.

So, instead, use the option style=patchnogrid or style=surface which will make maple utilize the same grid size but not show the hatching.

See the help page topic  plot3d,options 

@tsunamiBTP At least one of your attached worksheets seems to have been last saved with Maple 12.02. If that is the version you are using then you could use the zip command.

M := Matrix([[1,2],[3,5]]):

N := Matrix([[3,7],[-1,-2]]):

zip(`*`,M,N);

                                    [ 3     14]
                                    [         ]
                                    [-3    -10]

It bothers me (a little bit) when people use constructions like rhs(TOV[1]) and rhs(TOV[5]) for TOV the result from numeric dsolve with option output=listprocedure. It's awkward, because it forces the user to remember (or check) the order of the items in TOV.

In my opinion it is better to do it like,

  TOVv := eval(v(r),TOV):

than

  TOVv := rhs(TOV[5])):

It is better because it explicitly details that the procedure for v(r) is obtained.

As for your question, you could do it like so,

TOVv := eval(v(r),TOV);
offset := TOVv(608529.7)+.36555;
odeplot(TOV, [r, v(r) - offset ]);

# or even
plot(TOVv-offset, 0.0 .. 600000.0);

How about combining the trig terms, before solving?

restart:
 
eq1 := cos(lambda*ln(r1))*cos(lambda*ln(r2))
       + sin(lambda*ln(r1))*sin(lambda*ln(r2)) - 1 = 0:

combine(eq1);

                  cos(lambda ln(r1) - lambda ln(r2)) - 1 = 0

solve( combine(eq1), lambda, allsolutions );

                                2 Pi _Z1~
                             ---------------
                             ln(r1) - ln(r2)

You could also utilize those assumptions. For example, using them at the combining stage, before solving.


alt := combine(eq1) assuming r1>0, r2>r1;

                                              r1
                        alt := cos(lambda ln(----)) - 1 = 0
                                              r2

solve( alt, lambda, allsolutions );

                                     2 Pi _Z3~
                                     ---------
                                         r1
                                     ln(----)
                                         r2

Or you could use them afterwards, for this particular problem.

solve( combine(eq1), lambda, allsolutions ):

combine(%) assuming r1>0, r2>r1;

                                      2 Pi _Z5~
                                    - ---------
                                          r2
                                      ln(----)
                                          r1

And you could also do it this way,

solve( combine(eq1), lambda, allsolutions ) assuming r1>0, r2>r1;
First 201 202 203 204 205 206 207 Last Page 203 of 336