Maple Questions and Posts

These are Posts and Questions associated with the product, Maple

This seems like a serious limitation of Maple module, unless I am missing something.

I am trying to refactor one of my module, putting some code in separate .mpl file, say B.mpl,  and then do, from the main module

   $include  "B.mpl"; 

 But Maple complain now that, since B.mpl has export in it, that I can't do that. 

But the code inside B.mpl works fine if I copy it back and paste it inside the module, in the same location where the $include  "B.mpl";  is

Here is an example. (Since I can't use $include  "B.mpl";  in worksheet, Maple does not like it, I replaced it in this example by read "B.mpl";

(btw, both the syntax  module A()   and A:=module() seem to be equivalent), the problem shows up with either form)

I also tried with ";" and witout ";" at the end of the $include , it still gives same error.

 

restart;

currentdir("....."); #set directory to where the folder is


module A()

read "B.mpl";

 export foo:=proc()
  0;
 end proc;
end module;

Where the file B.mpl is

export boo:=proc()
return 0;
end proc; 

How is one supposed to refactor long file to separate files if can't leave export on those proc's?  

If I put everything in one .mpl file, it works

module A()

#read "B.mpl";  

export boo:=proc()  #this proc was in B.mpl
return 0;
end proc; 

 export foo:=proc()
  0;
 end proc;
end module;

I did more testing, and found that this seems to be an issue in Maple 2020.2. Because I just tried the same thing in Maple 2019 and it worked there ! i.e. no error.

Any one knows what is going on? 

Maple 2020.2, Physics 884.   Windows 10.

Here is screen shot. Same code. Works OK in Maple 2019.2 but gives error in 2020.2

 

 

 

Hi,

How do I integrate with Units[Standard]?

For example:


 

restart

with(Units[Standard]):

I__RMS__T := int((18*Unit('A')+9*t*Unit('s')*Unit('A')/(.9*Unit('s')))^2, t = 0.1e-1*Unit('s') .. 10*Unit('s'))

Error, (in Units:-Standard:-+) the units `1` and `s` have incompatible dimensions

 

I__RMS__T := int((18*Unit('A')+9*t*Unit('A')/(.9*Unit('s')))^2, t = 0.1e-1*Unit('s') .. 10*Unit('s'))

Error, (in Units:-Standard:-+) the units `A` and `A/s` have incompatible dimensions

 

 

 

It doesn't seem like I can around this. Is there a way to ignore the units error and just calculate the value?
 

Download test.mw

What type of mathematics can perform the type of transformation seen in the uploaded worksheet?

Could it be done with the Maple plottools transform command?

Could it be a projective transformation using homogeneous coordinates?

Could it be a complex conformal transformation?

Transformation.mw

Hi, I would like to parallelize the double for loop. I am computing pairwise SPolynomials like so

for i from 1 to n-1 do

for j from i+1 to ndo

spol:=Spol(poly[i],poly[j], tdeg(op(vars))):

...

od:

od: 

I would like to parallelize this code, here is what I have done:

at_node:=proc(p1,p2,vars, polynomials)

spol:=SPolynomial(p1,p2,tdeg(op(vars))):

if NormalForm(spol, polynomials, tdeg(op(vars)))=0

return [1,0]:

fi:

end proc:

Grid[Setup]("local", num_nodes=4):

Grid[Set](at_node): # below is the main loop that fails

for idx from 1 to n-1 do

out:=Grid[Seq](at_node(polynomials[idx], polynomials[j], vars, polynomials) j=idx+1, n):

od:

The loop above fails due to the error when calling normal form. It seems that the at_node function accepts an incorrect input for p1, a list of polynomials instead of a single polynomial. Is there a way to parallelize double for-loop with Grid like that? I am not sure where my error is.

 

 

 

 

 

 

Hi!

I have the following code to calculate the optimal quadrature rule with preassigned nodes (within a list), while the number of nodes that are to be added is n. The calculated quadrature rule is then used to approximate an integral.

 

restart;
with(LinearAlgebra):     
with(ListTools):
with(PolynomialTools):
Erweiterung:= proc(Unten, Oben, f,g,Liste,n)::real;
  #Unten:= Untere Intervallgrenze; Oben:= Obere Intervallgrenze; f:= zu integrierende Funktion;
  #G:= Gewicht; Liste:= Liste der alten Knoten, n:= Anzahl hinzuzufügender Knoten;
  local Basenwechsel,p,i,c,d,e,Hn,Koeffizienten,a,s,j,M,V,S,K,nNeu,Em,Hnm,KnotenHnm,KoeffizientenHnm,h0,b,gxi,Gewichte,Delta,Ergebnis,Endergebnis,Koeffizient,Rest;
  uses LinearAlgebra, ListTools;
  Basenwechsel1:=proc(Dividend, m)::list; #stellt ein gegebenes Polynom über eine Linearkombination der orthogonalen Polynomen dar.
   local Basenwechsel;
 
  Koeffizient:=quo(Dividend, p[m],x);

  Rest:=rem(Dividend, p[m],x);
 
  if m=0 then
    Basenwechsel:=[Koeffizient*evalf(int(g*p[m]^2,x=Unten..Oben))];
  else

    Basenwechsel:=[Koeffizient*evalf(int(g*p[m]^2,x=Unten..Oben)),op(procname(Rest,m-1))];
   
  end if;
 
  end proc;
  Basenwechsel2:=proc(Dividend, m)::list; #stellt ein gegebenes Polynom über eine Linearkombination der orthogonalen Polynomen dar.
   local Basenwechsel;
 
  Koeffizient:=quo(Dividend, p[m],x);

  Rest:=rem(Dividend, p[m],x);
 
  if m=0 then
    Basenwechsel:=[Koeffizient];
  else

    Basenwechsel:=[Koeffizient,op(procname(Rest,m-1))];
   
  end if;
 
  end proc;
p[-1]:=0;
p[0]:=1;
for i from 1 to (numelems(Liste)+n)*2 do
  p[i]:=(x^i-add(evalf(int(x^i*p[j]*g,x=Unten..Oben))*p[j]/evalf(int(p[j]^2*g,x=Unten..Oben)),j=0..i-1)); #Berechnung einer Folge orthogonaler Polynome bezüglich der gegebenen Gewichtsfunktion und des gegebenes Intervalles
  pprint(p[i]);
c[i-1]:=coeff(p[i],x,i)/coeff(p[i-1],x,i-1); #Berechnung der dreigliedrigen Rekursion der errechneten orthogonalen Polynome
d[i-1]:=(coeff(p[i],x,(i-1))-c[i-1]*coeff(p[i-1],x,(i-2)))/coeff(p[i-1],x,(i-1));
if i <> 1 then
  e[i-1]:=coeff(p[i]-(c[i-1]*x+d[i-1])*p[i-1],x,i-2)/coeff(p[i-2],x,i-2);
else
  e[i-1]:=0;
end if;
end do;
pprint(Liste[1],numelems(Liste));
Hn:=mul(x-Liste[i],i=1..numelems(Liste));
pprint(Hn);
 Koeffizienten:=FromCoefficientList(Basenwechsel1(Hn,numelems(Liste)+1),x,termorder=reverse); #Die Koeffizienten der orthogonalen Polynome werden hier als Koeffizienten der Monome gespeichert.
pprint(Koeffizienten,HIER);

pprint(c,d,e);
a[0][0]:=1; #Beginn der Berechnung der orthogonalen Produkterweiterungen, die Koeffizienten der orthogonalen Polynome werden wieder über die Monome gespeichert (2*x^2+2 bedeutet bspw. [2,0,2,0,0...] für die Koeffizienten)
a[1][0]:=x;
a[1][1]:=-e[1]*c[0]/c[1]+(d[0]-d[1]*c[0]/c[1])*x+c[0]/c[1]*x^2;
for s from 2 to numelems(Liste)+n do
  a[s][0]:=x^s;
  a[s][1]:=-e[s]*c[0]/c[s]*x^(s-1)+(d[0]-d[s]*c[0]/c[s])*x^s+c[0]/c[s]*x^(s+1);
    pprint (coeff(a[s][1],x,s),as1s);
end do;
for s from 2 to numelems(Liste)+n do
  for j from 2 to s do
    
      pprint(c[j-1]*sum(coeff(a[s][j-1],x,k-1)/c[k-1]*x^k,k=abs(s-j)+2..s+j));  pprint(sum((d[j-1]-c[j-1]*d[k]/c[k])*coeff(a[s][j-1],x,k)*x^k,k=abs(s-j)+1..s+j-1));  pprint(c[j-1]*sum(e[k+1]*coeff(a[s][j-1],x,k+1)/c[k+1]*x^k,k=abs(s-j)..s+j-2));pprint(e[j-1]*sum(coeff(a[s][j-2],x,k)*x^k,k=s-j+2..s+j-2));

     a[s][j]:=c[j-1]*sum(coeff(a[s][j-1],x,k-1)/c[k-1]*x^k,k=abs(s-j)+2..s+j)+sum((d[j-1]-c[j-1]*d[k]/c[k])*coeff(a[s][j-1],x,k)*x^k,k=abs(s-j)+1..s+j-1)-c[j-1]*sum(e[k+1]*coeff(a[s][j-1],x,k+1)/c[k+1]*x^k,k=abs(s-j)..s+j-2)+e[j-1]*sum(coeff(a[s][j-2],x,k)*x^k,k=abs(s-j)+2..s+j-2);

      
   
    
  end do;
end do;
for s from 0 to numelems(Liste)+n do
  for j from 0 to s do
    pprint(a[s][j], Polynom[s][j]);
  end do;
end do;
M:=Matrix(n,n); #Beginn der Erstellung eines linearen Gleichungssystems, dessen Lösung die Koeffizienten der orthogonalen Polynome sind, deren Summe Em die hinzuzufügenden Knoten als Nullstellen hat.
V:=Vector(n);
 
  for s from 0 to n-1 do
    for j from 0 to s do
      M(s+1,j+1):=sum(coeff(a[s][j],x,k)*coeff(Koeffizienten,x,k),k=0..n);
      if s<>j then
        M(j+1,s+1):=M(s+1,j+1);
      end if;
      pprint(M,1);
    end do;
    pprint(testb1);pprint(coeff(a[n][s],x,2));pprint(coeff(Koeffizienten,x,2));
    pprint(testb2); pprint(Koeffizienten);
    M(s+1,n+1):=sum(coeff(a[n][s],x,k)*coeff(Koeffizienten,x,k),k=0..n);
    
    pprint(M,V);
  end do;
pprint(M,V);
S:=LinearSolve(M,V);
K:=evalindets(S,name,()->2);
pprint(K,LinSolve);

Em:=add(p[i]*K[i+1],i=0..n); #Erstellen von Em, dessen Nullstellen die hinzuzufügenden Knoten sind
Hnm:=Hn*Em; #Erstellen von Hnm, welches alle Knoten als Nullstelle besitzt
KnotenHnm:=fsolve(Hnm,complex); #Knotenberechnung

 


   
pprint(Hn,alt,Em,neu,Hnm);
pprint(Testergebnis,nNeu);
pprint(fsolve(Hnm),fsolve(nNeu));
KoeffizientenHnm:=Reverse(Basenwechsel2(Hnm,n+numelems(Liste)));  #Das Polynom Hnm wird über die orthogonalen Polynome dargestellt.
pprint(KoeffizientenHnm);
h0:=int(g,x=Unten..Oben); #Beginn der Berechnung der Gewichte
 pprint(h0,HO);
b[n+numelems(Liste)+2]:=0;
b[n+numelems(Liste)+1]:=0;
  for i from 1 to nops([KnotenHnm]) do
    for j from n+numelems(Liste) by -1 to 1 do
      pprint(test21,KnotenHnm,Hnm);
      b[j]:=KoeffizientenHnm[j+1]+(d[j]+KnotenHnm[i]*c[j])*b[j+1]+e[j+1]*b[j+2];
      pprint(b[j]);
    end do;
    pprint(test23);
    gxi:=quo(Hnm,x-KnotenHnm[i],x);
   pprint(gxi);
    Gewichte[i]:=c[0]*b[1]*h0/eval(gxi,x=KnotenHnm[i]);
    pprint(b);
   
    Delta[i]:=c[0]*b[1];
  end do;
print(DieKnoten,KnotenHnm);
print(DieGewichte, Gewichte);
Ergebnis:=add(eval(f,x=KnotenHnm[k])*Gewichte[k],k=1..nops([KnotenHnm]));
Endergebnis:=evalf(Ergebnis)
end proc


The problem is that the code takes very, very long to run if the weight function is not a polynomial.

Erweiterung(-1,1,2*x^2+2,1,[-0.906179845938664],4)

for example, is done immediately (1, the 4th entry, being the weight function), while

Erweiterung(-1,1,2*x^2+2,2/sqrt(1-x^2),[-.8660254037, 0, .8660254037],4)


takes ages to finish. Is there a tool for me to see what exactly is taking Maple so long? Is there an easy fix, such as evalf()'ing key calculations (other than using (2*x^2+2)*2/sqrt(1-x^2) as the integrand and 1 as the weight function, since the quadrature rules I am looking at are supposed to be good with certain weird weight functions)? Thank you in advance!

Hello everyone,

I think that I accidentely deleted a file from inside of a Maple workbook. Is there a way to restore it inside of that workbook?

Regards,

 

Hi,

I have managed to create the following plot.  It won't plot on the site's plotter:

fieldplot([1, y^2 + x], x = -10 .. 10, y = -6 .. 6, fieldstrength = fixed, color = abs(y^2 + x + 1))

I am trying to assign a colour gradient to the different vectors based on vector magnitude.  In the color option, I entered color= expresssion for the magnitude of the vectors

 

This only half worked.  It currently scales the colours such that the largest and smallest vectors are the same colour.  How do I assign a gradient such that the small magnitude vectors are one colour, and they then transition to another colour as their magnitude gets larger?

 

 

Hi,

What's the steps to prevent simplify() from doing ugly stuff like this :

Ofc I expect something like (1 - R) instead of -(-1+R)

Thanks!

Is it possible to generate a XMLElement by using part of the code to be generated with a string, or are the only methods a strict use of AddAttribute and AddChild?

Hope the code below explains what I mean. The first line is a strict copy of a declaration in the help file.

The question is if I could use some part of the definition which is saved in the str variable and combine it into the first declaration?


 

with(XMLTools)

x := XMLElement("a", ["colour" = "red", "style" = "italic"], ["some content", XMLElement("b", ["colour" = "blue"], "more text"), "still more text"])

_XML_Element(_XML_ElementType("a"), [_XML_Attribute(_XML_AttrName("colour"), _XML_AttrValue("red")), _XML_Attribute(_XML_AttrName("style"), _XML_AttrValue("italic"))], [_XML_Text("some content"), _XML_Element(_XML_ElementType("b"), [_XML_Attribute(_XML_AttrName("colour"), _XML_AttrValue("blue"))], [_XML_Text("more text")]), _XML_Text("still more text")])

(1)

str := "["colour"="red","style"="italic"],["some content",XMLElement("b",["colour"="blue"],"more text"),"still more text"]"

"["colour"="red","style"="italic"],["some content",XMLElement("b",["colour"="blue"],"more text"),"still more text"]"

(2)

``


 

Download xml_string.mw

Is there a command that can show me all multipermutations?

If I have a set (1,2,3) I want an output of all the multipermutations of length n.

For example for n=2:
[1,1],[1,2],[1,3],[2,1],[2,2],[2,3],[3,1],[3,2],[3,3].

I suspect I have to use the Iteration command MultiPartition, but I don't understand the examples given on maplesoft:
https://www.maplesoft.com/support/help/Maple/view.aspx?path=Iterator%2FMultiPartition

Dear all,

In some step of my program, Maple cannot understand that the two following vectors are equal:

V1 := Vector[column](8, [1, 2, 2, 1, 3, A, B, 1/(A + B)^2]);

V2 := Vector[column](8, [1, 2, 2, 1, 3, A, B, 1/(A^2 + 2*A*B + B^2)]);

I tried to use the following two commands:

LinearAlgebra:-Equal(V1[6 .. 8], V2[6 .. 8]);

verify(V1, V2, 'Vector(expand)');

but Maple still returns 'false' instead of 'true'

Could somebody help me please ?
Best regards,

I'd like to define a proc, which takes first argument to be either an ode (i.e. type `=`) or set of ode's, or list of ode's.

However, I do not know how to tell Maple that the list or set, if that is the type, to be a list of `=` and no other type.

Here is what I tried to make it more clear

If I do this

restart;

interface(warnlevel=4);
kernelopts('assertlevel'=2): 


foo:=proc(ode::{`=`, set,list},func::`function`,$)
   print("ode=",ode);
   print("func=",func);
end proc:

Then Maple will check that the first argument is ANY one of `=`, set or list. 

But does not check if the list or set contains only equations of type `=`.  So I am able to call the above like this

ode1:=diff(y(x),x)=1:
ode2:=diff(y(x),x)=x:
foo(ode1,y(x));  #this is OK
foo([ode1,a],y(x))  #this is wrong

Which is wrong, since `a` is not of type `=`.

Next I tried this (I also wanted to check that if first argument is list or set, that it is not empty, so added extra check)

restart;
interface(warnlevel=4);
kernelopts('assertlevel'=2):

foo:=proc(ode::{`=`, 
                   And(set,satisfies(x-> (numelems(x)<>0 and type(x,`=`))  )),
                   And(list,satisfies(x-> (numelems(x)<>0 and type(x,`=`))  ))
                   },
                   func::`function`,$                                   
                   )

  print("ode=",ode);
  print("func=",func);
end proc;

But the above gives an error

ode1:=diff(y(x),x)=1:
ode2:=diff(y(x),x)=x:

foo([ode1,a],y(x))  

I also tried

foo:=proc(ode::{`=`, 
                   And(set,satisfies(x-> type(x,`=`)  )),
                   And(list,satisfies(x-> type(x,`=`) ))
                   },
                   func::`function`,$                                   
                   )

   print("ode=",ode);
   print("func=",func);

end proc;

Also gives erorr when called 

foo([ode1,ode2],y(x))

Ofcourse, I can just leave the check as in first case above, and in the proc itself, do the check myself manually by going over each entry in the list or set to make sure each entry is of type `=`. 

But I wanted Maple to do this work for me, if possible.

What is the correct syntax for doing so?

Maple 2020.2

 

[Perhaps this should be a Post rather than a Question.]

As far as I can tell, RootOf is the only Maple command that takes a bound variable on input and returns an unevaluated form with the bound variable renamed (to _Z). Why is that? Either all should do it (definite integrals, limit, sum, etc.) or none should. 

Pros:

Making a substitution for a variable that occurs both free and bound in the same expression is a major source of programming error. Renaming bound variables helps to ameliorate that. 

Cons:

The unexpected appearance of _Z in their results seems to be a great source of confusion to new users. However, if more commands did this, perhaps it would be more expected.

Feel free to start a brainstorming discussion on this, as if it were a Post, even if you don't have a direct Answer for the Question. If that's the way that the thread heads, I'll change it to a Post.

Hi,

I'm experiencing something quite annoying.

When copying Maple input code from an executable block into a document block, just after a line of text was written.

So for example <CTRL+T><write some text><CLICK ENTER FOR \newline><CTRL+M><PASTE MAPLE INPUT 1D CODE><CLICK ENTER>

The block doesn't get executed. I don't see the blue Maple output. Why is that? Is this a bug or I'm I doing something wrong. Normally logic would dictate after pressing enter it would execute the 1D code and simply show the blue output just below the 1D one-liner?

Another question:

I want to write the values of function g(x,t) as scientific notation.  I mean I want to write 1.95*10^(-3)  instead of 0.001953125 etc.


Yes, by clicking right-click and clicking the numeric formatting, I can transform all columns of Array A, but I want to transform just the last column g(x,t) in Array A.

 

restart:
  f:=(x,t)->x*t;
  g:=(x,t)->x^2*t;interface(rtablesize=20):
  A:=Array( [ [`x`,`t`,`f(x,t)`, `g(x,t)`],
              seq
              ( seq
                ( [i, j, f(i,j), g(i,j)],
                  j=0.125..0.875, 0.25
                ),
                i=0.125..0.875, 0.25
              )
            ]
          );  

 

First 463 464 465 466 467 468 469 Last Page 465 of 2217