MaplePrimes Questions

I am trying to decide which is better to use, a table or Record, to pass lots of information back and forth between functions inside say a personal Maple package.

So instead of passing each argument on its own, as normally one does when calling a function, instead all the input is put into one table, or into one record, and this is passed instead. So the function always takes as input one argument.

When the function returns result, it also does the same. It updates any fields it needs in the table or in the record, o rmay be add new field, which the caller would have to know about, (since same person has programmed both) and returns that.

I find this easier to handle, than passing each argument on its own.  And on return, rather than return many results in list or sequence and making sure they are in correct order, the function simply update the fields in the table or the record. No problems with wrong order here as caller will read these fields by name later on.

So I made same toy example, one using table and one using record. 2 numbers are passed to a function. The function returns the result of multiplication by adding new field into the table/record.  Here is version using table.

restart;
foo:=proc(input::table)
   local x,y,result,updated;

   x      := input["x"];
   y      := input["y"];
   result := x*y;

   #finished computation. Return result. Copy all content
   #of passed table first, then add new field to write result to

   updated := eval(input);
   updated["result"] := result;
   return updated;      

end proc:

Called using

input:=table(["x"=4,"y"=6]);
r:=eval(foo(input)):
print(r["result"]);

prints 24

 

Here is version using Record

foo2:=proc(input::record)
   local x,y,result,updated;

   x      := input:-x;
   y      := input:-y;
   result := x*y;

   #finished computation. Return result
   #could not update input Record in place, even after deep copy
   #since "result" is not an existing field. So have to make a new Record
   #this is a problem, since this function need to know all fields now in Record

   updated := Record("x"=x,"y"=y,"result"=result);
   return updated;      

end proc:

called as

input:=Record( "x" = 4, "y"=6);
r:=eval(foo2(input)):
print(r:-result);

prints 24

 

Some observations: I found the table more flexible. Because the function called can add a new field to the table, even if this field do not exist. If called function wants to add a new result back to the caller, it can do this.  With Record, all fields have to be decided on when the record is created. So the function has to create new record from all the old fields and add the new field to do this.

This might not be a big problem actually, as one can decide at top of package what all the possible fields that needs to be in the Record, and creates such Record, giving default values for al field. So now Record will have all possible fields in it.  Using this the above can now be written as

restart;
foo3:=proc(input::record)
   local x,y,result;

   x      := input:-x;
   y      := input:-y;
   result := x*y;

   #finished computation. Return result  
   input:-result := result; 
   return input;      

end proc:

And called as

input:=Record( 'x' = 4, 'y'=6, 'result'=NULL);
r:=eval(foo3(input)):
print(r:-result);

24

But it seems both methods suffer from the fact that type checking on the types of the arguments now inside is lost. (But I seem to remember one can do type checking on fields for a Record somehow). So if this is possible, this will be one advantage of Record over table.  But again, it is possible in both methods to check type of field by using whattype() or type() manually if needed.

But other than these two issues, and assuming one wants to pick between table and record, the question is, why choose Record over table?  If the main purpose is to just to pass information back and forth? Is there some hidden advatage to using Record I am overlooking that tables do not provide (again, for the purpose of passing arguments and results between functions and no more).

For me, I see table doing what I want from a record, but a little bit easier to work with as well (field names can be strings for example).  So with table one does  A["x"]=.....  While with Record one does A:-x=...

For me, I see a Maple table just like Python dictionary, so easy to underatand and work with.

Any thoughts from the experts on this subject? 

I am trying to count of the number of primes p such that when p is concatenated with 1 (ie p1, or 10*p+1),  if p1 is composite then we record the result 1, else  2. This gives the minimum k for which the concatenation pk is composite, and k is always either 1 or 2. It would be interesting to compare the number of primes with 1 and those with 2 up to a given max. I have already written a code which calculates the 1 or 2 for each prime but have not managed to adapt it keep count.
 

I would like to have a code to keep a count  of the 1s and 2s, thus being able to say that up to 10^k we see {a, b} where a is the number of primes with "1" and b is the number with "2".

Ideally I would like to be able to output plots of these data for any k =1,2,3,... up to a pre declared maximum k value, so as to make comparative graphs. I do not know how to organise the counting process, or if it is possible to get Maple to do the plots as well. Can anyone please assist me with this? I have Maple 2017.

Best regards,

David.

 

Hi guys I showing the problem in the following document, and the file is attached

restart; Setup(mathematicalnotation = true); with(Physics); Setup(op = {A, B, S, omega, v, x, x_, `ω_`})

_______________________________________________________; "_noterminate"

(1)

 

 

ok now here is the question: I first initialize some matrices (noncommutative objects) with Setup(op = {A, B, S, omega, v, x, x_, `ω_`}) then I have an expression which is:

 

(Iota[c][i]*Dagger(diff(x[i](t), t)).Dagger(A[i]).A[i].(diff(x[i](t), t)))/L[i](t)^2

Iota[c][i]*Physics:-`*`(Physics:-Dagger(diff(x[i](t), t)), Physics:-Dagger(A[i]), A[i], diff(x[i](t), t))/L[i](t)^2

(2)

 

Now I want to substitute the expression Dagger(A[i])*A[i]with -A[i]^2,so I write
eval(Iota[c][i]*Physics[`*`](Physics[Dagger](diff(x[i](t), t)), Physics[Dagger](A[i]), A[i], diff(x[i](t), t))/L[i](t)^2, Dagger(A[i])*A[i] = -A[i]^2)

Iota[c][i]*Physics:-`*`(Physics:-Dagger(diff(x[i](t), t)), Physics:-Dagger(A[i]), A[i], diff(x[i](t), t))/L[i](t)^2

(3)

now guess what it doesn't substitute the expression. Help me please !!. for now I have some clues:
1-its because I initialize the Matrices as noncommutative objects.
2-altering the substitution expression to this one will fix the issue (but what the hell!! let's say I beside of x I have y so now I most write a similar expression for y and so on)

  Dagger(diff(x[i](t), t))*Dagger(A[i])*A[i]*(diff(x[i](t), t)) = -Dagger(diff(x[i](t), t))*A[i]^2*(diff(x[i](t), t))

Physics:-`*`(Physics:-Dagger(diff(x[i](t), t)), Physics:-Dagger(A[i]), A[i], diff(x[i](t), t)) = -Physics:-`*`(Physics:-Dagger(diff(x[i](t), t)), Physics:-`^`(A[i], 2), diff(x[i](t), t))

(4)

eval(Iota[c][i]*Physics[`*`](Physics[Dagger](diff(x[i](t), t)), Physics[Dagger](A[i]), A[i], diff(x[i](t), t))/L[i](t)^2, Physics[`*`](Physics[Dagger](diff(x[i](t), t)), Physics[Dagger](A[i]), A[i], diff(x[i](t), t)) = -Physics[`*`](Physics[Dagger](diff(x[i](t), t)), Physics[`^`](A[i], 2), diff(x[i](t), t)))

-Iota[c][i]*Physics:-`*`(Physics:-Dagger(diff(x[i](t), t)), Physics:-`^`(A[i], 2), diff(x[i](t), t))/L[i](t)^2

(5)

 

``


 

Download MapleProblem.mw

 

To do this there should be a plotoption grid[ ], but probably obselote ?
Task (7) ask to plot the curve in rectangle [-,2,2]x[-4,5] : what rectangle?

Try using the Plotbuilder ( )command too( this generates also code )  and  interactive plotbuilder
Plotting this portion of curve in rectangle is not working yet.

ex_set_2_task_7.mw

How can I generate a code to plot the optimals; h, chi and psi?

 

Hi,

I need taylor expasion of

A(w):=M/sqrt(M^2+2*w)-mup*sqrt(((mu*M^2+3*sigmap-2*w)-sqrt((mu*M^2+3*sigmap-2*w)^2-12*mu*sigmap*M^2))/(6*sigmap))

I used taylor(A,w,4), but I had a problem!

If I know that A(w) is a real function, how can I remove ‘csgn’ from the  ‘taylor(A,w,4)’ command:

Thanks.

12.mws

There are discrepancies between Maple's solution of Fourier transforms and the results printed in USA NIST Handbook of Mathematical Functions, page 30

fourier(exp(-a*abs(x))/sqrt(abs(x)),x,s) assuming a>0;
            /   /   (1/2)   (1/2)                (1/2)  
        1   |   |2 2      Pi      signum(s - _U1)       
       ---- |int|-------------------------------------,
       2 Pi |   |       /   2    \                      
            |   |       |_U1     |          (1/2)       
            |   |     a |---- + 1| (s - _U1)            
            |   |       |  2     |                      
            \   \       \ a      /                      

                                    \\
                                    ||
         _U1 = -infinity .. infinity||
                                    ||
                                    ||
                                    ||
                                    ||
                                    //


For this transform of
                 "exp(-a*abs(x))/sqrt(abs(x))"

 the result in the NIST table is
          "sqrt(a + sqrt(a^2 + s^2))/sqrt(a^2 + s^2)"

 .
fourier(sinh(a*t)/sinh(Pi*t),x,s) assuming a>-Pi, a<Pi;
                    2 sinh(a t) Pi Dirac(s)
                    -----------------------
                          sinh(Pi t)       

For this transform of sinh(a*x)/sinh(Pi*x)   the result in the NIST table is
                         "1/sqrt(2*Pi)"  "sin(a)/(cosh(s) + cos(a))"

 
fourier(cosh(a*t)/cosh(Pi*t),x,s) assuming a>-Pi, a<Pi;
                    2 cosh(a t) Pi Dirac(s)
                    -----------------------
                          cosh(Pi t)       

For this transform of cosh(a*x)/cosh(Pi*x) the result in the NIST table is  
                          "sqrt(2/Pi) cos(a/2)*cosh(s/2)/(cosh(s) + cos(a))"

These disparities are significant, apart from the fact that Maple failed to solve the first example above.

 

Hi, 

Is it possible to define a linear idempotent operator in Maple?
I found no clue in the define help page.
To fix the ideas, an example could be the transposition operator on the ring of matrices

Thanks in advance

Hi,

I'm only getting one Answer instead of two (see below).

Thanks in Advance


 

Example 4: Solving Equations Involving Radicals

 

"ex4a(x):=sqrt(2 x+7)-x-2"

proc (x) options operator, arrow, function_assign; sqrt(2*x+7)-x-2 end proc

(1.1)

"->"

 

NULL

NULL

NULL

sqrt(2*x+7)-x-2

(2*x+7)^(1/2)-x-2

(1.2)

"(->)"

[[x = 1]]

(1.3)

NULL

2*x+7 = x^2+4*x+4

2*x+7 = x^2+4*x+4

(1.4)

"(->)"

[[x = -3], [x = 1]]

(1.5)

x^2+2*x-3 = 0NULL

x^2+2*x-3 = 0

(1.6)

(x+3)*(x-1) = 0

(x+3)*(x-1) = 0

(1.7)

"(->)"

[[x = -3], [x = 1]]``

(1.8)

``


 

Download Radicals.mw

Hello. Please help me. I set the function as "spline". The resulting function is shown in the figure. Is there any way to find the extremum points of this function? I will need to investigate many such functions, so searching separately for local minima and maxima will be a difficult long job for my research. Thank you for your answers.

Doing a routine simplification but got an error...Dont know where the mistake comes from.

 

simplification_error.mw

Is it possible to make notes above and next to a matrix like in the image above? How?

I'm sorry if this is really obvious but I'm new to Maple.

Thank you in advance :)

I want to solve the following problem in Maple:

I used the following Maple code. I am unsure whether this is the correct way of entering the assumptions for the initial and boundary conditions though.


 

eq := diff(u(x, t), t, t)-4*(diff(u(x, t), x, x)) = 0

diff(diff(u(x, t), t), t)-4*(diff(diff(u(x, t), x), x)) = 0

(1)

ic := `assuming`([u(x, 0) = 4*sin(x), (D[2](u))(x, 0) = 0], [x > 0])

u(x, 0) = 4*sin(x), (D[2](u))(x, 0) = 0

(2)

bc := `assuming`([(D[1](u))(0, t) = 0], [t > 0])

(D[1](u))(0, t) = 0

(3)

`assuming`([simplify(pdsolve([eq, ic, bc]))], [`and`(t > 0, x > -t)])

u(x, t) = (-4*Heaviside(x-2*t)+4)*sin(2*t-x)+4*sin(x)*cos(2*t)

(4)

``

``

Download IVP_with_inequalities.mw

Hi, I have a problem that needs excessive use of symbolic matrix-vector manipulation. I'm using maple physics vector package. my first problem is that it seems this package don't support symbolic vector transpose and the related rules is there a way to implement this, for example, I want to write in symbolic form: V_*Transpose(V_) but maple eliminate the Transpose head function and evaluate this as V_^2 which is wrong, or I want maple automatically simplify the transpose rule which state that (ab)'=b'a' which a and b are symbolic matrices if maple doesn't understand this, so is there a way I can implement this.
my second question is how can I state that for example, A*B is not equal to B*A with just assuming A and B are Matrix with Airbtrary dimension and not define A and B indices so that whenever i type: A*B+B*A it doesn't evaluate it as 2*AB

I need to plot a model of the amount of internet users starting from 1995 - 2024 in the US.


 

Example : Quadratic Modeling: Internet Users

 

"I:={[[-0.25 t^(2)+16.9 t-50,,5<=t<=24],[,]]"

``

"I  ="number of users of internet

t = time i.e 5 = 1995 year

 

NULL


 

Download Modeling_graph.mw

 

First 427 428 429 430 431 432 433 Last Page 429 of 2308