## 2998 Reputation

17 years, 28 days

Doug

`---------------------------------------------------------------------Douglas B. Meade  <><Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.eduPhone:  (803) 777-6183         URL:    http://www.math.sc.edu`

## Two Maplets? or two windows (in 1 Maplet...

I don't believe you can have 2 Maplets running at the same time and share information between them. You can have 2 windows within a single Maplet.

If you'll tell us more about what you want to do, and provide your current attempt, we might have a better chance to give a useful response.

Doug

```---------------------------------------------------------------------
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu
```

## Here's one implementation that is pretty...

Here's one implementation that is pretty easy, and is easy to understand:

a := n -> `if`(is(n,odd),1/n,-1/n^2);

> a(1);
1

> a(2);
-1/4

This implementation even works with assumed variables.

> assume( k::posint );
> a(2*k);
- 1 / ( 4 k^2 )

> a(2*k+1);
1 / (2 k + 1)

I hope this is useful.

Doug

```---------------------------------------------------------------------
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu
```

## Type the "name" of the letter and Maple ...

Type the "name" of the letter and Maple will display it as the appropriate Greek letter. Capitalize the first character to get the uppercase Greek letter:

 > alpha, Beta, gamma, Delta, upsilon, omega, Omega;
 (1)
 >

Doug

```---------------------------------------------------------------------
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu
```

## evaluation rules for -> (proc) and unapp...

THis is all well understood and documented. The arguments of an arrow-defined procedure are not evaluated at the time the procedure is defined.

From ?arrow:

> f := x -> x^2-1;
is equivalent to
> f := proc(x) option operator, arrow; x^2-1 end proc;

From ?operators,functional:

A functional operator of the form:
vars -> result
is semantically equivalent to:
proc(vars) option operator, arrow; result end

So, when you type -> you are really entering a proc and evaluation is subject to the evaluation rules for a proc. From the Evaluation Rules section of ?proc:

Within a procedure, during the execution of its statementSequence, local variables have single level evaluation.
This means that using a variable in an expression will yield the current value of that variable, rather than first
evaluating that value. This is in contrast to how variables are evaluated outside of a procedure, but is similar to
how variables work in other programming languages.

What you are seeing is exactly what the developers expect you to see. You just need to accept unapply as a useful tool for defining functions in a situation like you described with seq.

Doug

```---------------------------------------------------------------------
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu
```

## some ideas, and more questions...

This isn't reallyl an answer, but an attempt to better understand what you are doing.

B and D are pretty clear: the denominators are between 2 and 8 (including the endpoints).

R is between -(B-1) and (B-1); similar for S

The real numerators are A and B. I do not completely understand the syntax of these "if" statements. It looks to me as though you are trying to assign the value of in most cases, and 1 in other cases. But, how is the test being done. I assume you want something equivalent to "if \$R<>0 then \$R else 1 end if".

One way to avoid the problems with zero is to construct A (and C) by selecting a number between 1 and B-1 and then using another random number to decide the sign of the number:

\$A = rint(1,\$B-1) * (-1)^rint(1,2)

I remember fighting some of the same issues about floating point evaluation when converting from strings. One thing that might be of use is the "identify" command. That should allow you to get 2/3 from 0.6666 (but not from 0.666). There are other ways to fine tune the identify command - see the online help for full details. (I should also mention that parse("2/3") returns 2/3.)

I hope some of this is of help to you,

Doug

```---------------------------------------------------------------------
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu
```

## an idea...

Isn't there a way to say, in effect,

_COEFF := @c;   # (or Get(c) or however one extracts the value from an input field in TA)
_EXP := @e;
if _COEFF<>"" then _C := parse(_COEFF) else _C := 1 end if;
if _EXP<>"" then _E := parse(_E) else _E := 1 end if;
_ANS := _COEFF*x^_EXP;

In this pseudo-code snippet I've also assumed that if the exponent is left blank then you want to assume the exponent is 1. I've not worked directly with TA for a while, so do not recall all of the syntax and tools for working with user input.

This should not be too hard to implement by someone with direct knowledge of TA.

Doug

```---------------------------------------------------------------------
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu
```

## some observations - and questions...

Your problem has some singularities that need to be addressed before y ou are likely to get too much from Maple.

I note that if you look at the ODE at b=3/8, with f(3/8)=0, that the 2nd derivative disappears, and it's possible to solve for f'(3/8): f'(3/8) = 4.

What is the origin of the DE and boundary values? Why do you believe it has a solution?

Also, I see that you appear to have attempted to reduce the number of digits used by Maple in it's computations, but the actual parameter is Digits (not digits - capitlization matters!). Further, I don't see any benefit to doing this here. If anything, I would expect you might want to INCREASE Digits. Remember this the number of digits stored for all numerical computations, not the accuracy of the final answer.

Doug

```---------------------------------------------------------------------
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu
```

## Filled regions with implicitplot...

I hope this approach is a little more intuitive than Preben's.

Maple's implicitplot command (in the plots package) supports the plotting of filled regions, but the boundary of the region has to be defined as a level curve of a single equation. In this case, where we want the region bounded by y=ln(x+2), y=-1, and y=2, the boundary of the region is the set of all points where at least one of these expressions is satisfied. Another way of saying this is that the boundary of the region is the set of all solutions to

(y+1) (y-2) (y-ln(x+2)) = 0

This suggests:

 > restart;
 >
 > f := ln(x+2):
 > x1 := solve( f=-1, x ):
 > x2 := solve( f=2, x ):
 > plots:-implicitplot( (y+1)*(y-2)*(y-f)=0, x=x1..x2, y=-1..2, filledregions=true, coloring=[red,blue] );

The red points are where the LHS is positive and blue points are where it's negative. This is fine for x>0, but the colors need to be reversed for x<0. That's easy to realize by adding another term to the equation that defines the boundary of the region:

 > plots:-implicitplot( (y+1)*(y-2)*(y-f)*x=0, x=x1..x2, y=-1..2, filledregions=true, coloring=[red,white], gridrefine=2 );
 >

Notice how adding gridrefine=2 improves the resolution of the boundary. (Using gridrefine=3 is even better, but slower.)

Doug

```---------------------------------------------------------------------
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu
```

## RandomMatrix and matrix surgery...

I am not aware of a built-in Maple command corresponding to circshift, but this effect is easy enough to realize. Here's my implementation, for N=3 but this is easily

`Spin := N -> (-1)^~(LinearAlgebra:-RandomMatrix( N, N, generator=rand(N) ));`

spin := Spin(3);

`neighbours :=   < spin[..,-1] | spin[..,1..-2] > # rotate bottom row to top+ < spin[..,2..-1] | spin[..,1] >  # rotate top row to bottom+ < spin[-1,..] , spin[1..-2,..] > # rotate last column to first+ < spin[2..-1,..] , spin[1,..] >; # rotate first column to last`

The repeating this 1000 times is not difficult. (right?)

I hope this is helpful, and not too difficult to understand.

Doug

```---------------------------------------------------------------------
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu
```

## Edit My Settings...

In your profile, click on "Edit My Settings". From there you can see, and change, your avatar - and other information.

Doug

```---------------------------------------------------------------------
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu
```

## build matrix of solution values...

Here's my approach to this problem.

Once the matrix of values is created, you can access the data for that variable in a natural way. To identify the order of the variables in the matrix, see the Vars vector. With A as the first entry in Vars, you would get the vector of A values with RESULTS[1]; (I did not take the time to include a row in RESULTS for T. If you want this, you can add it yourself.)

There are some problems with some of the negative values of T. I got results down to T=-0.08 (I started with T=0.3). I've not tried to figure out why.

I will add that using l (ell) as a variable can be very risky. I thought it was "I" (which would be a real problem in Maple) until I copied your code into a worksheet and the 1D input showed it clearly as an "l".

Here's my full worksheet.

LoopSolve.mw

Doug

```---------------------------------------------------------------------
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu
```

## series...

Another approach is to use series to control the number of terms - and then use convert,polynom to make the result a polynomial.

`P:=1+epsilon+epsilon^2+epsilon^3;        3         2  epsilon + epsilon + epsilon + 1convert( series( P, epsilon, 2 ), polynom ); 1 + epsilon`

Doug

```---------------------------------------------------------------------
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu
```

## According to the Maple (2015) help docum...

According to the Maple (2015) help document for table:

Entries can be removed from a table by assigning a table entry to its own name using evaln.
Thus, T[1] := evaln(T[1]) removes the entry 4 [the previously assigned value of T[1]] from T.

This can be helpful for individual elements, but Acer's command for recreating a table with selected entries is better when you want to remove lots of entries.

Doug

```---------------------------------------------------------------------
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu
```

## simplified version...

First, the message was only a warning. It should not have stopped anything. The real issue was the "return Z" that others have already addressed.

I wanted to point out that you should be a little careful about the assignments that you made. Technically, you were assigning values to functions RHOR, C1, C2, C3, and C4 only at the specific inputs passed to this procedure. (To define an actual function, use -> or unapply.)

You also had many unnecessary sets of parentheses. I believe the following is a more readable and understandable version of your code:

`Z_DAK_FSOLVE := proc( PR , TR )local RHOR, C1, C2, C3, C4, EQU;## This routine solves the Dranchuk - Abou Kassem equation for the Z gas compressibility factor using Maple's fsolve routine.# RHOR := 0.27*PR / (Z*TR) : C1     := 0.3265 - 1.07 /TR - 0.5339/TR^3 + 0.01569/TR^4 - 0.05165/TR^5 : C2     := 0.5475 - 0.7361/TR + 0.1844/TR^2 : C3     := 0.1056*(-0.7361/TR + 0.1844/TR^2): C4     := 0.6134*(1.+0.721*RHOR^2)*(RHOR^2/TR^3)*exp(-0.721*RHOR^2) : EQU   := Z - ( 1. + C1*RHOR + C2*RHOR^2 - C3*RHOR^5 + C4 ): fsolve( EQU , Z) :## return Z:#end proc :`
`Z_DAK_FSOLVE(.6668876, 1.639826);     0.9522684730`

Doug

```---------------------------------------------------------------------
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu
```

## force evaluation...

Your problem arises because of Maple's evaluation rules. In your compound statement, the derivatives (D) are not fully evaluated before you make the substitution for eta(t).

temp1 := collect(expand(subs(eta(t) = epsilon*z(t), (series(subs(y(t) = y_per(t), y(t-tau_n) = y_per(t-tau_n), q = 3/4, tau_n = tau_exp, eqmy), epsilon = 0, 4)))), epsilon)

try

temp1 := collect(expand(subs(eta(t) = epsilon*z(t), eval(series(subs(y(t) = y_per(t), y(t-tau_n) = y_per(t-tau_n), q = 3/4, tau_n = tau_exp, eqmy), epsilon = 0, 4)))), epsilon)

Note that you already had an unnecessary pair of parentheses at exactly the point where the eval needs to be added. I wonder if you didn't have it (or something else) there at some point and mistakenly removed it.

I think you might need to do another series expansion to handle the fractional powers in your expressions, but I think you can handle that.

Here's the revised worksheet:

```---------------------------------------------------------------------