Maple 2022 Questions and Posts

These are Posts and Questions associated with the product, Maple 2022

Do you think the following messages  by mint should have been the same? this is just some made up example with no purpose other than to show the messages.

foo:=proc(x)
local z,a:=1,la;
   patmatch(x,a*x,'la');   
   map(z->assign(z),la);
end proc;

boo:=proc(y,x)
local Z,RHS;   
   RHS:=y(x);
   subs(y(x)=Z,RHS);
end proc;

Looking at the above, foo() has z used but never assigned a value, right?  And in boo(), Z is used but never assigned a value.

but mint gives slighlty different message

"C:\Program Files\Maple 2022\bin.X86_64_WINDOWS\mint.exe" -i 2  A.mpl

Procedure foo( x ) on lines 2 to 6
  These local variables were never used:  z

Procedure boo( y, x ) on lines 8 to 12
  These local variables were used but never assigned a value:  Z

Should not these two messages have been the same?

When running mint on a single .mpl file, I often get this warning

These names were used as global names but were not declared:  main_module

When having this code in the mpl file

o:=Object(main_module:-person_type);

The problem is that main_module is a module that lives in separate mpl file.

It is a differerent module in its own ,mpl file which inside it contains the person_type definition. (another module of type object)

I know I can ignore this. And have been. But my question is: how does one "declare" main_module inside this mpl file to avoid getting this warning message? Since main_module is its own module in separate file. I do not understand what does it mean to  "declare" it.

Here is the full code

A:=module()
   export boo:=proc()
      local o;
      o:=Object(main_module:-person_type);
      o:-foo();
   end proc;
end module;

And here is the command I used

"C:\Program Files\Maple 2022\bin.X86_64_WINDOWS\mint.exe" -i 2 A.mpl

Gives

Nested Procedure boo() on lines 2 to 6
  These names were used as global names but were not declared:  main_module

Later on, when I build my .mla library, all these modules are put inside the library. So it is not an issue when running the code, but I'd like to see if it is possible to add something to A.mpl to tell Maple that main_module is separate module and not to worry about it.

 

I have started to use CodeGeneration[C] instead of codegen[C] (depreciated). In the attached example not all variables and parameters of a C function are declared as double, although the default value is double.

If this is by design:

How can I force double without going back to codegen[C] or manual declaration of each item?

C_code_generation_with_CodeGeneration.mw

again, I wish Maple help can be better. A simple example of how to use listplot on matrix is all what is needed.

I have a matrix, 3 rows and 5 columns. I need to use listplot to generate 3 listplots on same graph. I can do this one row at a time. But when calling listplot(m) where m is the matrix, it gives error

Error, (in plots:-pointplot) incorrect number of coordinates in points data

Clicking on the above link, as usual sends me to page that says There is no help page available for this error

Help says

The listplot command also accepts a list or Matrix containing points data. great. But how?? I click on the link next to the above line, it sends me to page about pointplot. There is says that pointplot also accepts a matrix of size n by 2. Does this mean listplot matrix must also be two columns? It does not say this on the listplot help page.

For a workaround, I now generate plot of each row on its own, then use display to put them all on same graph. But the problem with this is that all have same color. I was hoping that if Maple did it all at once, it will automatically pick different color for each line as is the case with Mathematica (example below)

Is there a better way to do this? For reference, I'd like to generate similar plot like this

You see, the colors are automatically selected. With manual plotting of each row myself, I have to select the color myself and to make sure they are different and so on. It will be better if the system did all of this.

Please see attached worksheet

restart;

m:=Matrix([[1,2,5,6,9],[3,4,5,13,14],[1,3,4,10,11]])

Matrix(3, 5, {(1, 1) = 1, (1, 2) = 2, (1, 3) = 5, (1, 4) = 6, (1, 5) = 9, (2, 1) = 3, (2, 2) = 4, (2, 3) = 5, (2, 4) = 13, (2, 5) = 14, (3, 1) = 1, (3, 2) = 3, (3, 3) = 4, (3, 4) = 10, (3, 5) = 11})

plots:-listplot(m); #why this fail?

Error, (in plots:-pointplot) incorrect number of coordinates in points data

plots:-listplot(m[1,..])

#for a workaround, I can do this. But now all lines have same color which is not good.
map(n->plots:-listplot(m[n,..]),[$1..3]):
plots:-display(%)

 

Download how_to_list_plot_matrix.mw

What is the correct way to use listplot with matrix?

int(sin(x)/x*exp(-2*I*pi*f*x), x = -infinity .. infinity) gives the incorrect answer pi. The correct answer is pi for abs(f)

I am not able to even trap this Maple exception.

Any suggestions what to do? It is not a problem if it can't solve it, but I need to at least be able to  trap the exception in order to go to the next one, else the whole program now stops when it hits this.

I used try..catch but this exception just ignores this and escapes to top level. This is not the first time I've seen Maple exception escape the try/catch. I do not understand why some do that and some not. I

Is this another bug?

interface(version);

`Standard Worksheet Interface, Maple 2022.1, Windows 10, May 26 2022 Build ID 1619613`

restart;

eq:=1 = -X*(-1/4*(-40*(X + x0)^(5/3) - 20/3*(X + x0)^(2/3)*Y - 20/3*(X + x0)^(2/3)*y0 - 32*A*(X + x0)^(1/3))/((X + x0)^(5/3)*(Y + y0)) + 5/12*(-15*(X + x0)^(8/3) - 4*(X + x0)^(5/3)*Y - 4*(X + x0)^(5/3)*y0 - 24*A*(X + x0)^(4/3) + 12*A^2)/((X + x0)^(8/3)*(Y + y0)))/(Y*(1/(Y + y0) + 1/4*(-15*(X + x0)^(8/3) - 4*(X + x0)^(5/3)*Y - 4*(X + x0)^(5/3)*y0 - 24*A*(X + x0)^(4/3) + 12*A^2)/((X + x0)^(5/3)*(Y + y0)^2)));

1 = -X*(-(1/4)*(-40*(X+x0)^(5/3)-(20/3)*(X+x0)^(2/3)*Y-(20/3)*(X+x0)^(2/3)*y0-32*A*(X+x0)^(1/3))/((X+x0)^(5/3)*(Y+y0))+(5/12)*(-15*(X+x0)^(8/3)-4*(X+x0)^(5/3)*Y-4*(X+x0)^(5/3)*y0-24*A*(X+x0)^(4/3)+12*A^2)/((X+x0)^(8/3)*(Y+y0)))/(Y*(1/(Y+y0)+(1/4)*(-15*(X+x0)^(8/3)-4*(X+x0)^(5/3)*Y-4*(X+x0)^(5/3)*y0-24*A*(X+x0)^(4/3)+12*A^2)/((X+x0)^(5/3)*(Y+y0)^2)))

try
   sol:=solve(identity(eq,X),[x0,y0]);
catch:
   print("trapped the error");
end try;

Error, (in anonymous procedure called from type/realcons) too many levels of recursion

 

Download how_to_trap.mw

Hello,

I don't understand. With 2 degrees of liberty and a factor of 5% (1-95%), the table Khi-2 indicates 5,99.

It is impossible for me to obtain this value with Mapple. 2 following tests :

Y := ChiSquareRandomVariable(2);
                            Y := _R0

PDF(Y, 0.05);
CDF(Y, 0.05);
                          0.4876549560

                       0.0246900878919645

PDF(Y, 0.95);
CDF(Y, 0.95);
                          0.3109425282

                       0.378114901350325

The same problème with the instruction RandomVariable(ChiSquare(v)).

Thank you to help me.

Kinds regards

It will be great if  DEtools:-convertAlg  which is designed to find coefficients of a linear ode, not to expand the coefficients it finds.

This caused my patterns to fail, as after putting the coefficients in a certain form, and then calling DEtools:-convertAlg later on somewhere else in the program, the patterns no longer worked due to this unexpected expansion.

It will be better if DEtools:-convertAlg returns the coefficients it find as is and not expand them. I could not find an option to use for this. Here is an example.

restart;
ode:=b*(x+x^2)*diff(y(x),x$2)+x*(2*a - 1)*diff(y(x),x)+c*y(x)=0;

After the call the coefficients become

L:=DEtools:-convertAlg(ode,y(x))

You might ask that one can easily "fix" this afterwords. Sure. I can use collect on x. But the point is that in general, it might not be clear what to collect on or what the changes that were made are.

In principle, it is better to keep the coefficients in same form as they were in the ode so that the ode do not change form.

Maple 2022.1 on windows.

What's going on in the following? Why can't I restore the default behavior of diff after using Physics:-diff or even just using with(Physics)? Is it because of Physics:-ModuleLoad()?

restart:

diff(conjugate(f(x)), x);

(diff(f(x), x))*(-conjugate(f(x))/f(x)+2*abs(1, f(x))/signum(f(x)))

Physics:-diff(conjugate(f(x)), x);

diff(conjugate(f(x)), x)

forget(.., conjugate(f(x)));

diff(conjugate(f(x)), x);

diff(conjugate(f(x)), x)

restart:

with(Physics):

:-diff(:-conjugate(f(x)), x);

diff(conjugate(f(x)), x)

 

Download PhysicsDiff.mw

I don't know why the prettyprinted output of my worksheet is shown the way that it is above. I didn't do anything differently than I usually do to upload a worksheet. Anyway, the output is simple enough that I think that my Question is still clear.

I have an expression and I want to select the part of the expression which has diff(y(x),x) in the expression.

Using select(has,expr,diff(y(x),x) works, except when the expression happend to be exactly diff(y(x),x) in this case select returns diff()

I understand why this happens. But I can not avoid this problem by say first checking if the expression has more than one operand, because nops(diff(y(x),x) is 2 and not one. Also 1+diff(y(x),x) has two operands. And I can not check if the expression is of type `+` or `*` before, because other types can have more than one operand also.

So now what I do is the folliwng: first check if the expression has diff(y(x),x). If so, convert the expression to D and now check if nops is more than one, and if so, only now call select.

This is becuase nops(D(y)(x)) is one, while nops(diff(y(x),x) is two.

Is there a better way to do this, in order to avoid calling select and getting diff() ? I suppose I could also just check if the expression is exactly diff(y(x),x) before even calling select or has and avoid all this?

Worksheet attached


 

interface(version)

`Standard Worksheet Interface, Maple 2022.1, Windows 10, May 26 2022 Build ID 1619613`

#the wrong way
expr:=diff(y(x),x):
if has(expr,diff(y(x),x)) then
   part_with_diff:=select(has,expr,diff(y(x),x));
fi;

diff()

#add extra check,  example 1
expr:=diff(y(x),x):
if has(expr,diff(y(x),x)) then
    if nops(convert(expr,D))>1 then
       part_with_diff:=select(has,expr,diff(y(x),x));
    else
       print("expression is itself diff(y(x),x))");
    fi;
fi;

"expression is itself diff(y(x),x))"

#add extra check, example 2
expr:=1+3*diff(y(x),x):
if has(expr,diff(y(x),x)) then
    if nops(convert(expr,D))>1 then
       part_with_diff:=select(has,expr,diff(y(x),x));
       print("part_with_diff=",part_with_diff);
    else
       print("expression is diff(y(x),x))");
    fi;
fi;

"part_with_diff=", 3*(diff(y(x), x))


 

Download best_way_to_check.mw

maple_calculations.mw

Why does my sequence return 0 at n=9 and n=10, when it should be 4?

Beneath the sequence i have also calculated the limit of f, as x approaches infinity, and it returns 4.

Below the initial screenshot, i have displayed a screenshot of the same plot but with a much bigger x-axis. It seems something weird happens at very large numbers of x. Is it a glitch, and if so how do i fix it?

here is the maple document containing the calculations below: maple_calculations.mw

I'd like to plot row[i] of M_jk (left axis) vs. row[i] of M_ki (right axis). i is the x axis, and varies discretely from 1 to 10 (number of runs). See attached screenshot below for details. My result is off in terms of values... How to fix my plot command?

 

Dear friends,

I found a file in the Maplesoft Application Center to evaluate the minimum of a function in two variables.

I tried to extend the code to find a minimum for a function in 4 variables.

But the code does not work. Any Help, I will be appreciated.

Amr

Gradient_Search_Program_Code-22-9-2022.mw

restartNULL

NULL``

Can I disable maple's use of the ' function? (aka prime/derivative function)

 

For example, if

 

f := x^2+1

x^2+1

(1)

it's derivative is obtained as

 

Diff(f(x), x) = diff(f(x), x)

Diff(x^2+1, x) = 2*x

(2)

.

We used the prime operator on the f to obtain f' on the right-hand-side.

 

The problem is, I use prime notation as a naming convention like in defining an integral equation such as:

"psi(t)=∫G(t,t')*psi(t') ⅆt' ."

NULL

This is common practice in many texts.

 

Is there a way that I can disable the operator function of ' so I can use it as a naming scheme? I have tried using the Alias( ) command which works on one evaluation but if an equation is passed to another function the Alias( ) command is extinguished by the previous evaluation and it takes the derivative again which is undesired.

how_do_i_disable_prime_operation.mw

Given

expr:=c[2]*sin(sqrt(3)*x/2) + c[3]*cos(sqrt(3)*x/2);
expr:=convert(expr,tan);

How to change the second result above (with the tan) back the the original form it was in?

I tried all different convert and simplification commands, and non managed to get back the original form.

convert(expr,sincos);
simplify(expr,size);
#etc...

Maple 2022.1 on windows 10

1 2 3 4 5 6 7 Last Page 1 of 10