Maple Questions and Posts

These are Posts and Questions associated with the product, Maple

I've never noticed this before, becuase I do not like to with()  packages, but like to add the name of the package at each command and alwsys try to use explicit commands.

Compare this first example, which does not work, since the "." in the codeis the global "dot" command ?dot

restart;
VC:=VectorCalculus:
f:=y*sin(x)+y^2;
VC:-Nabla . VC:-Nabla(f,[x,y])

So the dot above is the one used for normal dot product, which is visible without loading any package as in: <1,2>.<3,4> gives 11

Now when I next loaded the VectorCalculus explicitly, but kept the same code the same, i.e. using the same ".", now it worked

restart;
with(VectorCalculus);
VC:=VectorCalculus:  #do not need this now, but to keep the code the same
f:=y*sin(x)+y^2;
VC:-Nabla . VC:-Nabla(f,[x,y])

It worked because Maple now used VectorCalculus:-`.`  ,Even though I did not tell it to do this, it searched the package since it is loaded) and now decided to use VectorCalculus:-`.` instead of the global `.` dot defined before loading this package.

But how did Maple know which dot to use? 

Did it say to itself, the dot in the middile must be VectorCalculus:-`.` and not the global `.` due to the type of the operands around the dot, it automatically found the correct match? 

So imagine if one has loaded more packages, and some might have its own `.` operator that takes the same operands, does Maple search them all to find the correct dot to use based on type of operands to bind it to? and how in this case it knows which to use, if there is more than one match among all loaded packages? I can see this causing confusion, becuase one is never sure in this case which operator was used. I do not know if Maple issues a warning in this case or not.

I do not use input 2D math in document mode. But was trying it now to see if I can enter this to check my hand solution

In worksheet, this is what I do

restart;
VC:=VectorCalculus:
f:=y*sin(x)+y^2;
VC:-DotProduct(VC:-Del,VC:-Gradient(f,[x,y]))

But I do not know how to enter   if possible, in document mode 2D math. THis is what I tried. Created document mode. Picked the DEL operator from the left side common symbols window. But I do not know how to do the rest.

Clearly I am doing something silly. This is why I prefer plain Maple code, becuase I can see what I am typing :)

But was wondering, how to do the above in docuemnt mode + 2D math? To make it look close to how it shows in the book. Does one need special palette for this?

 

 

Hello

In Section 14.5 - External Calling ..., page 489, the authors gave an example on how to use the command line in Unix to call maple with arguments. I followed the example but added a mpl-file to see if the arguments were sent to it.  

Example (Linux):

/opt/maple2020/bin/maple -c n:=4 -c 'path:="/home/eduardo/examples";' example.mpl > output.txt &

Maple sends out the following error message: "Error, incorrect syntax in parse: '/' unexpected (near 7th character of parsed string)".

The msg is clear where the error is but I could not figure out what to do. The single quotes were supposed to take care of that, weren't they?  

Many thanks.

Ed

Edit: I have added the double-quotes.   The problem still persists.  

I wanted to overwrite an existing variable of type table by the one returned from a call to a proc().

But it does not work, unless eval() is called on the returned result from the proc()

But if the variable that recieves the return value from the proc() was not already a table type, then it works without using eval. Why is that? 

Here is an example

restart;
foo:=proc(A::table)
  A["c"]:=3; #add new field
  return A;
end proc;

A:=table():
A["a"]:=1:
A["b"]:=2:
B:=foo(A):
whattype(B);
print(B)

           table(["a" = 1, "c" = 3, "b" = 2])

In the above, it worked. is table now, and assigned the updated table from the proc.  But 

A:=table():
A["a"]:=1:
A["b"]:=2:
A:=foo(A): #without eval, it does not work.
whattype(A);
print(A)

             symbol
               A

I expected A to be overwritten, just like B was. To fix this, I have to change A:=foo(A): by A:=eval(foo(A)):

But why eval was not needed in the first example, and was needed for the second example?

btw, the same thing happens with Record(), not just table()

just like to understand the reasoning behind this. I expected both cases to work the same way. But it works different if the variable happend to be unassigned (like B above).

Hello all,

I was hoping to get some general tips for tackling numeric integrals. As someone with little experience in the subject, I find myself overwhelemed by the many different integration methods. 

Experts, what are the first steps you take when trying to find a numeric solution to an integral? How might you zero-in on a particular integration method? What about tweaking error parametrs, etc.? Is there a general framework for approaching these problems, or is it all guesswork?

Thanks!

Hi everyone:

How can I convert the following phrase (eq) into the phrase in the photo?

eq:= -w*z^2/(2*E*MI*alpha^2)+w*H*sinh(alpha*H)*cosh(alpha*z)/(alpha^3*E*MI*cosh(alpha*H))-w*H*sinh(alpha*H)/(alpha^3*E*MI*cosh(alpha*H))+w*cosh(alpha*z)/(alpha^4*E*MI*cosh(alpha*H))-w/(alpha^4*E*MI*cosh(alpha*H))+w*H*z/(E*MI*alpha^2)-w*H*sinh(alpha*z)/(E*MI*alpha^3):

the phrase in the photo:

tnx...

I want to write a proc, say f, that takes an single argument Z, as in
f := proc(Z::?) ...
where the only acceptable Z values are pairs [x,y], where x and y are selected from the set {a,b,c,d}. The entries a,b,c,d of that set are prescribed symbolic constants. 

Thus, the following are legal calls to f:
f([a,a]), f([a,b]), f([d,c])
but these are illegal:
f([a]), f([a,b,c]), f([a,x])

I don't know what to put for the "::?" in the proc's definition in order to enforce those constraints.  Any ideas?

Extra: In fact, I would prefer to ban the f([a,a]) option as well (no repeated symbols) but that's of secondary importance since it is easy to inspect and handle that within the proc's body.

Hello. I am a student who has been given access to Maple through my school. Normally, the program works just fine and without any problems. But today I tried to do a linear regression which did not work as it used to do. Though, the exponential (ExpReg) and the potential (PowReg) regression still works normally.

Here is a picture of what the error looks like:

As shown on the picture, I use a special extension called the 'Gym-pakke' which we use in my high school. As far as I know, this extension is created for Danish high schools?

Another thing that I had like to emphasize, is that the linear regression still works whenever I copy-paste the command from a previous document - a document from before the issue began. But I am tired of having to copy-paste every time I have to do a linear regression.

Please help me solve this problem, thanks! :)

Hi there!

I am trying to save the coefficients of a polynomial in a list to work with them in a rather complicated procedure. It is about representing a polynomial via a set of orthogonal polynomials phi_n which change depending on the input. For example, phi_s*phi_0=1*phi_s, so the coefficient of phi_s is 1 and the rest is 0. I save this as a[s][0][s]:=1. In this procedure, however, the coefficient of phi_{s+1} or phi_{s+10} might come up, and I have not declared them as 0, so the procedure stops whenever something like a[s][0][s+2] or a[s][0][s+10] appears. I could work with polynomials I guess, saving x^s for the result of

phi_s*phi_0 and working with coeff (x^s,n), which would indeed return 0 if n is not s instead of aborting the entire procedure, however, to me, it's not quite beautiful coding to encrypt the needed coefficients in another polynomial instead of just extracting them into a list. Is there a way to tell Maple that anything unspecified, a[s][j][x], shall just be 0?
 
Thank you in advance, Daniel
 
 

I did two attempts with different ideas
 

 

restart;

Task (a) A list of numbers in Maple :

L:=[1,2,3,4,5];

[1, 2, 3, 4, 5]

(1)

 

In general summing up numbers sum(a, i = k .. n) = sum(a_i, i = 1 .. 5) and sum(a_i, i = 1 .. 5) = a1+a2+a3+a4+a5

underscript? ..i like to write a with underscore n : how to that

#S:={seq(L[i],i=1..5)};

#L:= [seq(L[i],i=1..5)];

For summing up numbers in a list of L i can use a ...

Sumlist := proc (L,N):  

Sumlist:=proc(L,N)

   a:=1;

   for i from 1 to N do

      a:=seq(L[i],i=1..5);

   end do;

end proc:

 

Warning, (in Sumlist) `a` is implicitly declared local

 

Warning, (in Sumlist) `i` is implicitly declared local

 

L:=[1,2,3,4,5];

[1, 2, 3, 4, 5]

(2)

N:=3;

3

(3)

Sumlist(L,N);

1, 2, 3, 4, 5

(4)

 

And now to sum the number sequenze  from the procedure?

 

restart;

Sumlist:=proc(L,N)

   a:=1;

   for i from 1 to N do

      a:=seq(L[i],i=1..5);
      #sum(a, i=1..5); # for this probably a second do loop nested ?

   end do;

end proc:

 

Warning, (in Sumlist) `a` is implicitly declared local

 

Warning, (in Sumlist) `i` is implicitly declared local

 

L:=[1,2,3,4,5];

[1, 2, 3, 4, 5]

(5)

N:=3;

3

(6)

Sumlist(L,N);

1, 2, 3, 4, 5

(7)

 

 

 

 

========================================================================

Also possible by? : a1 = 1, a2=a1+1, a3=a2+1, etc

restart;

 

Sumlist:=proc(L,N)

   a:=1;

   for i from 1 to N do

      a:=L[i]+1;

   end do;

end proc:

 

Warning, (in Sumlist) `a` is implicitly declared local

 

Warning, (in Sumlist) `i` is implicitly declared local

 

L:=[1,2,3,4,5];

[1, 2, 3, 4, 5]

(8)

N:=2;

2

(9)

Sumlist(L,N);

3

(10)

L[1];

1

(11)

 

Try some things out, but summing up list ?


 

Download betounes_ex_set_2_task_5.mw

 

restart;
a := 10;
ff := proc()

       ##local a,b;

        b := a + 10:  #### implicit local

         return b:

        end proc:
ff();

output: 20

restart;

a := 10:
ff := proc()

       ##local a,b;

        b := a + 10:   #### implicit local

        a:=b:

        return b:

        end proc:
ff();

output: a+10

expected: 20

Please explain the reason

 

How can I create an even function, g, in Maple? I want Maple to give g(x) - g(-x) as 0.

Good day sirs, I write a system of DAE but giving me this code "(The use of global variables in numerical ODE problems is deprecated, and will be removed in a future release. Use the 'parameters' argument instead (see ?dsolve,numeric,parameters)". The code is attached below.

Thanking you in anticipating for your help.

Help!!!!.mw

This is my attempt to produce a subplot within a larger plot for magnifying data in a small region, and putting that subplot into the white space of the figure.
Based on the questions: How to insert a plot into another plot? and Inset figure in Maple, I wrote a couple of procedures that create sub-plots and allow the user to place the subplot window as he/she chooses. This avoids the graininess issues mentioned by acer in the second link (and experienced by me).

So far, I only have this completed for point plots, but using acer's method of piecewise functions posted in the plotin2b.mw of the second article, with the subplot function being defined only if it satisfies your conditions, would allow the subplot generating procedure to be generalized easily enough. But the data I'm working with all point plots, so that's the example here.

The basic idea  is to use one procedure to create boxes, make tickmarks on the expanded region, and make tickmark labels, combine all of those into one graph. Then create scaled and shifted versions of the data series, then make graphs of those. Lastly, combine them all into one picture.

Hope this helps someone who has to do the same.

Mapleprimes isn't inserting the contents, but here is the download of the file: SubPlotBoxesandVectorDataSeries.mw

 

Hello, I was given the problem "Set N:=100. (i) Form four lists L[1], L[3], L[5], L[7] where L[r] contains all primes 2< p < N such that p mod 8 = r ." and came up with the following code:

N := 100;
List1 := [];
List3 := [];
List5 := [];
List7 := [];
for p from 2 to N do
    if isprime(p) and p mod 8 = 1 then List1 := [op(List1), p]; end if;
    if isprime(p) and p mod 8 = 3 then
        List3 := [op(List3), p];
    end if;
    if isprime(p) and p mod 8 = 5 then
        List5 := [op(List5), p];
    end if;
    if isprime(p) and p mod 8 = 7 then
        List7 := [op(List7), p];
    end if;
end do;
List1;
List3;
List5;
List7;
 

this gave me the answer I wanted, however using the above code I have to answer this second question: 

In the notation of Problem 1, make a procedure with input = arbitrary  positive integer N and output = the list [nops(L[1]), nops(L[3]), nops(L[5]), nops(L[7])]. Do some experiments to see for which (if any) r, L[r] is largest. 

I am unsure of how to create a procedure out of the code I already have. I created this: 
 

restart;
F := proc(n)

local N, p, List1, List3, List5, List7;

List1 := [];

List3 := [];

List5 := [];

List7 := [];

for p from N do

if isprime(p) and p mod 8 = 1 then List1 := [op(List1), p]; end if;

if isprime(p) and p mod 8 = 3 then List3 := [op(List3), p]; end if;

if isprime(p) and p mod 8 = 5 then List5 := [op(List5), p]; end if;

if isprime(p) and p mod 8 = 7 then List7 := [op(List7), p]; end if;

return [nops(List1), nops(List3), nops(List5), nops(List7)];

end do;

end proc;

 

however, when I input F(100) or any other value of N, I am receiving the error message "Error, (in F) initial value in for loop must be numeric or character"

 

Any ideas on how to improve my program to get the output I desire?

thank you 

 

 

 

First 541 542 543 544 545 546 547 Last Page 543 of 2217