Maple Questions and Posts

These are Posts and Questions associated with the product, Maple

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 

 

 

 


 

restart;

with(PDEtools):

with(plot):

Error, invalid input: with expects its 1st argument, pname, to be of type {`module`, package}, but received plot

 

A1:=Matrix([[phi,(chi),conjugate(phi),conjugate(chi)],
          [chi,(phi),conjugate(chi),conjugate(phi)],
          [lambda*phi,-(lambda)*(chi),
           conjugate(lambda)*conjugate(phi),-conjugate(lambda)*conjugate(chi)],
          [lambda*chi,-(lambda)*(phi),
           conjugate(lambda)*conjugate(chi),-conjugate(lambda)*conjugate(phi)]]);

A1 := Matrix(4, 4, {(1, 1) = phi, (1, 2) = chi, (1, 3) = conjugate(phi), (1, 4) = conjugate(chi), (2, 1) = chi, (2, 2) = phi, (2, 3) = conjugate(chi), (2, 4) = conjugate(phi), (3, 1) = lambda*phi, (3, 2) = -lambda*chi, (3, 3) = conjugate(lambda)*conjugate(phi), (3, 4) = -conjugate(lambda)*conjugate(chi), (4, 1) = lambda*chi, (4, 2) = -lambda*phi, (4, 3) = conjugate(lambda)*conjugate(chi), (4, 4) = -conjugate(lambda)*conjugate(phi)})

(1)

d1 := LinearAlgebra:-Determinant(A1):

d1; length(%);

conjugate(lambda)^2*conjugate(phi)^2*chi^2-conjugate(lambda)^2*conjugate(phi)^2*phi^2-conjugate(lambda)^2*conjugate(chi)^2*chi^2+conjugate(lambda)^2*conjugate(chi)^2*phi^2+2*conjugate(lambda)*conjugate(phi)^2*chi^2*lambda+2*conjugate(lambda)*conjugate(phi)^2*lambda*phi^2-8*conjugate(lambda)*conjugate(phi)*conjugate(chi)*chi*lambda*phi+2*conjugate(lambda)*conjugate(chi)^2*chi^2*lambda+2*conjugate(lambda)*conjugate(chi)^2*lambda*phi^2+conjugate(phi)^2*chi^2*lambda^2-conjugate(phi)^2*lambda^2*phi^2-conjugate(chi)^2*chi^2*lambda^2+conjugate(chi)^2*lambda^2*phi^2

 

705

(2)

den:=simplify(d1,size); length(%);

-(-(conjugate(chi)-conjugate(phi))*(chi+phi)*conjugate(lambda)+lambda*(conjugate(chi)+conjugate(phi))*(chi-phi))*(-(conjugate(chi)+conjugate(phi))*(chi-phi)*conjugate(lambda)+lambda*(conjugate(chi)-conjugate(phi))*(chi+phi))

 

333

(3)

 

con1:=phi=exp(I*lambda*(x-t/(4*lambda^2)-w^2)):con2:=chi=exp(-I*lambda*(x-t/(4*lambda^2)-w^2)):

 

den1:=simplify(dsubs({con1,con2},den));

4*conjugate(lambda)^2*cos((1/4)*(4*w^2*lambda^2-4*x*lambda^2+conjugate((4*lambda^2*w^2-4*lambda^2*x+t)/lambda)*lambda+t)/lambda)^2-4*conjugate(lambda)^2*cos((1/4)*(-4*w^2*lambda^2+4*x*lambda^2+conjugate((4*lambda^2*w^2-4*lambda^2*x+t)/lambda)*lambda-t)/lambda)^2+8*conjugate(lambda)*cos((1/4)*(4*w^2*lambda^2-4*x*lambda^2+conjugate((4*lambda^2*w^2-4*lambda^2*x+t)/lambda)*lambda+t)/lambda)^2*lambda+8*conjugate(lambda)*cos((1/4)*(-4*w^2*lambda^2+4*x*lambda^2+conjugate((4*lambda^2*w^2-4*lambda^2*x+t)/lambda)*lambda-t)/lambda)^2*lambda+4*cos((1/4)*(4*w^2*lambda^2-4*x*lambda^2+conjugate((4*lambda^2*w^2-4*lambda^2*x+t)/lambda)*lambda+t)/lambda)^2*lambda^2-4*cos((1/4)*(-4*w^2*lambda^2+4*x*lambda^2+conjugate((4*lambda^2*w^2-4*lambda^2*x+t)/lambda)*lambda-t)/lambda)^2*lambda^2-16*conjugate(lambda)*lambda

(4)

plot3d(subs(Re(lambda)=1, Im(lambda)=.2, w=1, rhs(den1)),x=-6..6, t=-6..6)

Warning, inserted missing semicolon at end of statement

 

Error, invalid input: rhs received 4*conjugate(lambda)^2*cos((1/4)*(4*w^2*lambda^2-4*x*lambda^2+conjugate((4*lambda^2*w^2-4*lambda^2*x+t)/lambda)*lambda+t)/lambda)^2-4*conjugate(lambda)^2*cos((1/4)*(-4*w^2*lambda^2+4*x*lambda^2+conjugate((4*lambda^2*w^2-4*lambda^2*x+t)/lambda)*lambda-t)/lambda)^2+8*conjugate(lambda)*cos((1/4)*(4*w^2*lambda^2-4*x*lambda^2+conjugate((4*lambda^2*w^2-4*lambda^2*x+t)/lambda)*lambda+t)/lambda)^2*lambda+8*conjugate(lambda)*cos((1/4)*(-4*w^2*lambda^2+4*x*lambda^2+conjugate((4*lambda^2*w^2-4*lambda^2*x+t)/lambda)*lambda-t)/lambda)^2*lambda+4*cos((1/4)*(4*w^2*lambda^2-4*x*lambda^2+conjugate((4*lambda^2*w^2-4*lambda^2*...

 

NULL

``

 

``


 

Download 23May(1).mw

Seems to make no difference with or without RETURN() for the procedure ?

 

vraag_op_forum_gesteld_over_boek_vb_binomium.mw

 

For to know what each graph is standing for in the plot legenda

Could not yet get it  in y , y' , y '' , to 5th derative 

Better is perhaps to have vertical table with the names and function expression together , but that could be difficult betounes_ex_set_task_4def.mw  

First 421 422 423 424 425 426 427 Last Page 423 of 2097