## 5127 Reputation

16 years, 80 days

"A map that tried to pin down a sheep trail was just credible,

but it was an optimistic map that tried to fix a the path made by the wind,

or a path made across the grass by the shadow of flying birds."

- _A Walk through H_, Peter Greenaway

## combine...

Here is one way. I'm pasting as plain text, which is why the units show below as function calls to Units:-Unit() instead of the nice 2D Math output way involving the fenced [[]] brackets.

```> restart:
> with(ScientificConstants):

> L:=[seq(1/10^(-i)*Unit(nanometer),i=11..13)];

[100000000000 Units:-Unit('nm'), 1000000000000 Units:-Unit('nm'),

10000000000000 Units:-Unit('nm')]

> c := evalf(GetValue(Constant('c'))*GetUnit(Constant('c')));

8            /'m'\
2.99792458 10  Units:-Unit|---|
\'s'/

> newL := map2(`/`,c,L);

[                          /'m'\
[0.002997924580 Units:-Unit|---|
[                          \'s'/
[-------------------------------,
[       Units:-Unit('nm')

/'m'\
0.0002997924580 Units:-Unit|---|
\'s'/
--------------------------------,
Units:-Unit('nm')

/'m'\]
0.00002997924580 Units:-Unit|---|]
\'s'/]
---------------------------------]
Units:-Unit('nm')        ]

> newL := c /~ L;

[                          /'m'\
[0.002997924580 Units:-Unit|---|
[                          \'s'/
[-------------------------------,
[       Units:-Unit('nm')

/'m'\
0.0002997924580 Units:-Unit|---|
\'s'/
--------------------------------,
Units:-Unit('nm')

/'m'\]
0.00002997924580 Units:-Unit|---|]
\'s'/]
---------------------------------]
Units:-Unit('nm')        ]

> map(combine,newL,units);

[              6            / 1 \
[2.997924580 10  Units:-Unit|---|,
[                           \'s'/

5            / 1 \                         / 1 \]
2.997924580 10  Units:-Unit|---|, 29979.24580 Units:-Unit|---|]
\'s'/                         \'s'/]

```

Another way could be to rely on the automatic combining of units when the Units:-Standard package is loaded. (I use `map` slightly differently here. Due to the manner of the programming of Units:-Standard:-`/` as a unary procedure, it is a little awkward to `map` it.)

```> restart:
> with(ScientificConstants):
> with(Units:-Standard):

> L:=[seq(1/10^(-i)*Unit(nanometer),i=11..13)];

[100000000000 Units:-Unit('nm'), 1000000000000 Units:-Unit('nm'),

10000000000000 Units:-Unit('nm')]

> c := evalf(GetValue(Constant('c'))*GetUnit(Constant('c')));

8            /'m'\
2.99792458 10  Units:-Unit|---|
\'s'/

> newL := map(t->c/t,L);

[              6            / 1 \
[2.997924580 10  Units:-Unit|---|,
[                           \'s'/

5            / 1 \                         / 1 \]
2.997924580 10  Units:-Unit|---|, 29979.24580 Units:-Unit|---|]
\'s'/                         \'s'/]
```

## library archive...

Whenever your code assigns a new value to the variable, it could be made to savelib that variable to a Library archive. As long as that Library archive is in libname following restart then the saved value will get used (until you reassign a new value to the name).

But you won't be able to restart from within a procedure (or even with a loop, properly).

In the Standard GUI you could use a DataTable Component to store one or more values. You could even hide it. So if the rtable associated with such a Component is named X, then any value of X[1] would survive restart even without the worksheet being saved (as well as relaunch provided the worksheet were saved). The downside is that rtable entry X[1] is not a symbolic name, in case your code wanted to use it that way.

## suggestions...

For each loop iteration, once each call to Simulate is finished, could you call iostatus, and then programmatically extract the strings of which .msys files are still opened for WRITE, and fclose them? Maybe things would go wrong, and subsequent Simulate runs in that same Maple session would fail miserably, but who knows it might work.

An alternative might be to write a batch file that runs commandline interface cmaple.exe against a text .mpl script, in a loop. Each invocation of cmaple file could could read z and parameter values from a text data file (or even receive those as input from the batch script). The overhead of relaunching cmaple each time might be less than (or comparable to) the simulation time (if lucky).

## part 1...

Regarding your first question, are you talking about 2D plots, such as x vs y=f(x)? If so then I am not aware of any recent functionality changes which make inverting the y-axis direction any easier.

One question that has been asked here a few times [1, 2, and 3] before is how to reverse the direction of just the positive section of the y-axis. That is: zero at top, and some finite value at the intercection with the x-axis. This might be the same as what you are asking now.

One answer (which can be seen via those links) is to use the `reflect` command while overriding the tickmarks.

Another possibility is to fake the 2D plot using a 3D plot, and then using the `orientation` option. For example, these can look somewhat similar:

```plots:-display(plot(-x^2,x=0..4),
axes=box,ytickmarks=[seq(-i=i,i=0..16,2)]);
```

```plots:-display(plottools:-reflect(plot(x^2,x=0..4), [[0,0],[1,0]]),
axes=box,ytickmarks=[seq(-i=i,i=0..16,2)]);
```

```plot3d(x^2,x=0..4,y=0..0,orientation=[-180,-90,90],
labels=[x,``,y],axes=box,view=[0..4,0..0,0..16]);
```

## part 2...

```Explore( plot(a*sin(x),x=0..2*Pi) );

Explore( plot(a*sin(x),x=0..2*Pi, view=[0..2*Pi, -10..10]) );
```

The second example forces the view and keeps it fixed, while the first example allows the view to "float" and change while matching the computed range. You may want the second approach.

I don't know of any way to change the defaults for new tables inserted from the menubar.

But these might each be a workaround, to save you manual effort, if you have many repeats to insert. They require some Maple savvy to set up, though.

- Insert them as usual, but then after saving the worksheet you could use the Worksheet and/or XMLTools packages to read in the .mw file as XML, change all the tables' properties in one swoop, and then save as a new .mw file.

- Create a (help-based) Task that just contains the kind of table you want. An 1x2 empty table, say. Use that Task to repeatedly insert. You should be able to keep the Task open, while working in your Document/Worksheet.

## try..catch...

Do you want something like this?

```SPV := proc (values::list, b::integer)
local a, N, const, value, res;
N := nops(values);
const := convert([seq(x || i, i = 1 .. N)], `+`) <= b;
value := convert([seq(x || i*values[i], i = 1 .. N)], `+`);
for a to 100 do
res:='res'; # wasn't sure whether you wanted final result. if not, get rid of res.
try
res := Optimization:-LPSolve(value, {value = a, const}, assume = {nonnegint},
depthlimit = 200, maximize);
catch "no feasible integer point found":
return a+1;
catch "no feasible point found for LP subproblem":
return a+1;
catch: # all other errors
error; # rethrow the error
end try;
end do;
NULL;
end proc:

SPV([1, 2, 5, 7], 13);

89

SPV([1, 4, 12, 21], 5);

73

SPV([1, 2, 7, 12, 50], 5);

42

SPV([1, 2, 5, 20], 7);

79
```

## rotate (Maple 13)...

```restart:

P := 1 + x + 1*x^2-1*y + 1*y^2 + 1*x*y:

Q:=plot3d(P, x = -5 .. 5, y = -5 .. 5):

T:=[seq(plottools:-rotate(Q,0,0,A),A=0..evalf(2*Pi),evalf(Pi/20))]:

plots:-display(T,insequence=true,axes=box,labels=[x,y,z]);
```

## eval(s,1)[1] not eval(s[1],1)...

```restart:

s:={'a', 'b'};

{a, b}

a:=4;

4

s;

{4, b}

eval(s,1)[1]; # not eval(s[1],1)

a

unassign(eval(s,1)[1]);

s;

{a, b}

a;

a
```

## to FTOC, or not to FTOC...

...that is the question.

Using the fundamental theorem of calculus is not the only way to do definite integration.

```restart:

g:=Int(x^(-13/10), x):

f:=value(g);

10
- ---------
(3/10)
3 x

sol1:=eval(f,x=1000)-eval(f,x=1/1000);

1      (7/10)   10     (3/10)
- --- 1000       + -- 1000
300              3

infolevel[int]:=2:

sol2:=int(x^(-13/10), x=1/1000..1000);

Definite Integration:   Integrating expression on x=1/1000..1000
Definite Integration:   Method meijergspecial succeeded.
Definite Integration:   Finished sucessfully.

1    (9/10)    /3    \ /       /1   \      /3    \   (1/5)\
-- 10       sin|-- Pi| |100 sec|- Pi| - csc|-- Pi| 10     |
30             \10   / \       \5   /      \10   /        /

evalf(sol1), evalf(sol2);

26.05796602, 26.05796603

10   (9/10)   1   (1/10)
-- 10       - - 10
3             3

simplify(sol1);

10   (9/10)   1   (1/10)
-- 10       - - 10
3             3

int(x^(-13/10), x=1/1000..1000, method=FTOC);

Definite Integration:   Integrating expression on x=1/1000..1000
Definite Integration:   Method FTOC succeeded.
Definite Integration:   Finished sucessfully.

10   (9/10)   1   (1/10)
-- 10       - - 10
3             3

```

Maybe see this video, for some insight into how Maple does symbolic integration. (It may discuss indefinite integration more, but might offer insight into the fact that Maple can choose between different methods.)

## using ``()...

```restart:

e:= (g^n) / (g^n -1);

n
g
e := ------
n
g  - 1

# This next use of ``() is to prevent expansion done by the `numer` and `denom` commands.
mult := g^(``(-n));

(-n)
mult := g

# This next use of ``() is to prevent automatic cancellation of g^(``(-n)) term.
new:=``(numer(e)*mult)/``(denom(e)*mult);

/ n  (-n)\
\g  g    /
new := ----------------
// n    \  (-n)\
\\g  - 1/ g    /

# Now use the `expand` command in two ways, to get rid of both uses of ``().
expand(map(expand,numer(new))) / expand(map(expand,denom(new)));
1
------
1
1 - --
n
g
```

If you're curious, you can see the effect of that last operation as in two substeps

```map(expand,numer(new)) / map(expand,denom(new));

(1)
--------
/    1 \
|1 - --|
|     n|
\    g /

expand(%);

1
------
1
1 - --
n
g
```

And, of course, most of this is not necessary and can be done more neatly, except that you have written that you wanted to see the form of `new` above explicitly.

## possibly...

I'm not sure whether I understand your goal. But...

```restart:

RVars:=[[''Rla'',''Rlb'',''Rsa'',''Rsb'',''RN''],
[''GAL'',''GBL'',''GAS'',''GBS'',''GN'']]:

for i from 1 to 5 do
assign( cat(m,(RVars[1,1])), i);
assign( RVars[1,1], i);
mRla;
Rla;
od;

1
1
2
2
3
3
4
4
5
5

RVars;

[[Rla, Rlb, Rsa, Rsb, RN], [GAL, GBL, GAS, GBS, GN]]

eval(RVars);

[[5, Rlb, Rsa, Rsb, RN], [GAL, GBL, GAS, GBS, GN]]
```

Or,

```restart:

RVars:=[[''Rla'',''Rlb'',''Rsa'',''Rsb'',''RN''],
[''GAL'',''GBL'',''GAS'',''GBS'',''GN'']]:

for i from 1 to 5 do
m || (RVars[1,1]) := i;
assign( RVars[1,1], i);
mRla;
Rla;
od;

1
1
1
2
2
2
3
3
3
4
4
4
5
5
5

RVars;

[[Rla, Rlb, Rsa, Rsb, RN], [GAL, GBL, GAS, GBS, GN]]

eval(RVars);

[[5, Rlb, Rsa, Rsb, RN], [GAL, GBL, GAS, GBS, GN]]
```

## gamma...

You get that error because gamma is known to Maple as a particular mathematical constant.

See the online help, for details, which you can also get from Maple with a help query for the term gamma.

It is also a protected name, so that you cannot accidentally assign some other value to it.

```> gamma:=4;
Error, attempting to assign to `gamma` which is protected

> assume(gamma<3);
Error, (in assume) cannot assume on a constant object
```

## Alec M....

Alec Mihailovs answered this question here in 2006.

It is also possible to construct something that acts as a colorbar.

## exact vs floating-point...

Using 64bit Maple 15.01 on Windows 7, I get

```int(simplify(eval(ErTime,
[k[0]=3,k[1]=2/10,k[2]=1/10,x[1](0)=0,x[2](0)=30])),
t = 0 .. infinity);

5
```

It looks like the floating-point values k[1]=0.2 and k[2]=0.1 are causing the problem and producing the infinite result that Markiyan showed.

I have not pinpointed the particular place that thing are going astray with the float values for the parameters.

 First 6 7 8 9 10 11 12 Last Page 8 of 48
﻿