## 9 Badges

5 years, 251 days

## Extract array from plot structure...

Hi @kumar29 ,

When you make an implicit plot in Maple, the plot structure contains an array of the points, which can be extracted and exported. For example:

```p := plots:-implicitplot( x^2 + y^2 - 1, x=-1..1, y=-1..1 );
A := op( [1,1], p );
ExcelTools:-Export( A, "data.xlsx" );```

## 'indets()' command...

Hi @Annonymouse ,

I suggest the indets() command, which returns a set of indeterminates. You can then divide these into those that are variables and those that are parameters. Please try the following:

```A := [ k[a1]*C[T]*(R-x[1]-x[2])-k[d1]*x[1], k[a2]*C[T]*(R-x[1]-x[2])-k[d2]*x[2] ];

# All indeterminates.
U := indets( A, 'name' );

# Variables.
V := select( u -> type( u, 'indexed' ) and member( op( 0, u ), ['x','y'] ), U );
v := numelems( V );

# Parameters.
P := U minus V;
p := numelems( P );```

## Try insequence=true option for display()...

If you specify the 'insequence'=true option for display(), you can create the animation. Here's my variation:

```restart;

# endpoints for extension
a, b := -Pi, Pi;

# original function
f := t -> t / Pi;

# periodic extension
g := proc(t)
option cache:
piecewise( t > b, g(t+a-b), t < a, g(t+b-a), f(t) ):
end proc:

# constant term of Fourier series
alpha := 1/(b-a) * int( f(t), t=a..b );

# Fourier cosine coefficients
A := unapply( simplify( 2/(b-a) * int( f(t) * cos(2*Pi/(b-a)*n*t), t=a..b ) ), n ) assuming n :: posint;

# Fourier sine coefficients
B := unapply( simplify( 2/(b-a) * int( f(t) * sin(2*Pi/(b-a)*n*t), t=a..b ) ), n ) assuming n :: posint;

# Inert Fourier series
F := unapply( alpha/2 + Sum( A(n) * cos(2*Pi/(b-a)*n*t) + B(n) * sin(2*Pi/(b-a)*n*t), n=1..infinity ), t );

# Truncated series
G := proc( t, m )
alpha/2 + add( A(n) * cos(2*Pi/(b-a)*n*t) + B(n) * sin(2*Pi/(b-a)*n*t), n=1..m ):
end proc:

# animation
M := 20:
plots:-display( seq( plot( [ 'g'(t), 'G'(t,m) ], 'tickmarks'=[piticks,[-1,1]], 'color'=[blue,red], 'thickness'=3, 'discont'=true ), m=1..M ), 'insequence'=true );```

## Change grading code...

Hi @Dim

If you are using the default grading code

`evalb((\$ANSWER)-(\$RESPONSE)=0);`

for a Maple-graded question, it won't mark equations as being equal, since it is comparing the difference with zero. However, this should work:

`evalb((\$ANSWER)=(\$RESPONSE));`

To make the grading code more robust, you can also allow for equivalent equations:

```EquivEQ := proc( A :: 'Or'(equation,algebraic), B :: 'Or'(equation,algebraic), { params :: set := {} } )
local phi, X, Y, k, sol:
phi := u -> `if`( type( u, 'equation' ), lhs(u) - rhs(u), u ):
X := simplify( phi(A) ):
Y := simplify( phi(B) ):
sol := solve( { X = k * Y, k <> 0 }, k ):
return is( numelems( sol ) = 1 and indets( sol ) = { k } union params ):
end proc:

EquivEQ( \$ANSWER, \$RESPONSE );```

For an example in Maple:

```f := s*Y(s)-2-3*Y(s) = 2/(s-1);
g := simplify( f );
evalb( f = g ); # false
is( f = g ); # false
EquivEQ( f, g ); # true```

## Optimization Approach...

This works for me for the parameter value I chose, but there is probably a more robust way:

vanderpol.mw

```restart;

UseHardwareFloats := false:
Digits := 35:

# Van der Pol oscillator.
mu := 4.0;
de := diff( x(t), t ) - y(t), diff( y(t), t ) - mu * ( 1 - x(t)^2 ) * y(t) + x(t);

# Parametric initial conditions.
ic := x(0) = a, y(0) = b;

# Parametric solution of IVP.
sol1 := dsolve( { de, ic }, { x(t), y(t) }, 'numeric', 'abserr'=1e-25, 'parameters'=[a,b] ):

# Objective function, requiring periodicity.
phi := proc( a__0, b__0, tau__0 )
sol1( 'parameters' = [ 'a'=a__0, 'b'=b__0 ] ):
eval( ( x(t) - a__0 )^2 + ( y(t) - b__0 )^2, sol1( tau__0 ) ):
end proc:

# Bounds on parameters.
a__r, b__r, tau__r := -3..3, -7..7, 1..25:

# Plot to estimate initial values for parameters.
DEtools:-DEplot( { de }, { x(t), y(t) }, t=tau__r, x=a__r, y=b__r, 'dirfield'=500 );

# Estimate for parameters.
P := [ a=1.5, b=-0.25, tau=10.0 ];

# Determine parameters [a,b,tau] based on constraint phi(a,b,tau)=0.
sol2 := Optimization:-NLPSolve( 'phi(a,b,tau)', 'initialpoint'=P ):

# Assign parameter values.
assign( sol2[2] ):

# Fix solution for the parameter values.
sol3 := dsolve( { de, ic }, { x(t), y(t) }, 'numeric', 'abserr'=1e-25 ):

# Choose smallest tau (period).
while true do
d := fnormal( eval( ( x(t) - a )^2 + ( y(t) - b )^2, sol3( tau/2 ) ), 1e-10 ):
if d = 0 then
tau := tau/2:
else
break:
end if:
end do:

# Print values.
'a' = a, 'b' = b, 'tau' = tau;

# Plots.
p := DEtools:-DEplot( { de }, { x(t), y(t) }, t=0..5*tau, x=a__r, y=b__r, 'dirfield'=5000 ):
q := plots:-odeplot( sol3, [ x(t), y(t) ], t=0..tau, 'numpoints'=1000, 'color'=blue, 'thickness'=3 ):
plots:-display( [ p, q ] );```

## Try '(-1)^f()' where 'f:=rand(1..2)'...

Does this work for you?

```randomize():
f := rand( 1..2 ):
RM := Matrix( 10, 10, (i,j) -> (-1)^f() );```

## Try ':-param'...

Hi @rahinui ,

The :- oparator will work. It will tell Maple to use the global, unassigned version:

```foo1 := proc( {param:={}}, \$)
foo2(':-param'=param):
end proc:```

Alternatively:

```foo1 := proc( {param:={}}, \$)
foo2(_options['param']):
end proc:```

## 'evalindets()'...

Hi @MALU ,

I didn't have any luck with applyrule(), but I did with evalindets():

```
r := u -> op(0,u)[1](op(1..2,u)) * op(0,u)[2](op(3..4,u));
evalindets( f(t,x,y,z), function, r );
evalindets( g(a,b,c,d), function, r );```

## Do you have the 'GodMode' Control Panel?...

Hi @ngon,

Do you happen to have the so-called “God Mode” for Control Panel running on your desktop? The folder is named

`GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}`

but it looks like the Control Panel icon with no name. Does removing this folder help? Alternatively, you might try updating the version of the JRE used by Maple 2017:

https://faq.maplesoft.com/hc/en-us/articles/360019488772

## 'language=en' option...

Assuming you're using 64-bit Maple 2017 (not 17) on 64-bit Windows, I think you need to add the line

`-Duser.language=en `

to your

`C:\Program Files\Maple 2017\bin.X86_64_WINDOWS\maplelauncher.l4j.ini`

file. You may need to save the original file to your Desktop, make and save the change, and then drag-and-drop it back to the original folder.

For Maple 17, though, you will need to add

`language=en`

to the

`C:\Program Files\Maple 17\bin.X86_64_WINDOWS\launch.ini`

file.

## You could also try 'map[3]()'...

Hi @Earl,

A variation of @Joe Riel's suggestion would be to use map[3]():

`map[3]( P, [ A1, A2, A3, A4 ], [ B1, B2, B3, B4 ], 0 );`

Here, the two lists are treated as direct arguments for P, and P is distributed over the (unused) argument of 0, with the result not being a list.

## How about 'indets()'?...

@digerdiga

A big more generally, you can use indets() to select the terms with alpha, and then apply freeze() and thaw():

```f := sin(alpha) * expand( cos(x+y) ) * cos(alpha);
A := select( has, indets( f, function ), alpha );
thaw( combine( eval( f, A =~ freeze~(A) ) ) );```

## Try 'applyop()'...

Hi @digerdiga,

I suggest using applyop() to apply combine() to only part of the expression:

```f := -sin(alpha)*(sin(theta1)*cos(theta)-cos(theta1)*sin(theta));
applyop( combine, 3, f );```

## Try 'map()' and then convert to list...

Hi Rainer,

Using map(), you can replace each element of the matrix with the corresponding inequality. Then, you can convert the matrix to a list:

```A := Matrix( 2, 2, symbol=a );
B := convert( map( u -> u >= 0, A ), list );```

Is this what you're after?

## Re-arrange options, load 'DEtools'...

Hi @carriewong,

It looks like you just need to re-arrange some options, and load DEtools for the phaseportrait() command:

```pendsys := { diff(x(t),t) = 1 - x(t) - b * x(t) + x(t)^2 * y(t), diff(y(t),t) = b * x(t) - x(t)^2 * y(t) };
vars := { x(t), y(t) };
tr, xr, yr := t=0..50, x=0..5, y=0..5;
br := b=0.5..3;
ic := [ [x(0)=0,y(0)=0], [x(0)=2,y(0)=3] ];
opts := linecolor=[black,green], numpoints=75, dirgrid=[30,30];
plots:-animate( DEtools:-phaseportrait, [ pendsys, vars, tr, ic, xr, yr, opts ], br );
```
 1 2 3 Page 2 of 3
﻿