MaplePrimes Questions

Hello again,

 

I have two functions f and h, that I want to show by pointplot as a diagramm (with a range from -10 to +10).

I know how to do it with "normal" functions, but what if for example the function f has 2 variables but h only has one?

f:= (sin(sqrt(x^2+y^2)))/(sqrt(x^2+y^2));

h:= f(x, 1.8);

These are the two functions.

 

So far I've made a list for each function for x  = -10 to x = 10

ListF:= [seq(f, x = -10..10, 1)];

ListH:= [seq(h, x = -10..10, 1)];

 

But I don't know how to go from there. Can I already use pointplot to connect the two lists? Or do I have to connect these two lists as one (which is what I originally planned) But I don't know how to do that, without always copying the results of one and then the other and putting both in a new list.

e.g Both lists show the values for the function for x = -10..10. If the first value of ListF is 5 and the first value of ListH is 1, then connecting both in a new list ListFH: = [[5,1]...], followed by the 9 other values.)

(5 and 1 aren't the actual results, I just used them for simplification.)

(Even if this isn't the right beginning for the solution of my original problem, I still want to know if it's even possible to take all values of one list of a function 'a' and all values of a second list of function 'b' and put them in a new list 'c' with c: = [a,b] without manually putting them together. So that the first value of list a is paired with the first of list b, the second of list a with the second of list b, etc... I hope you know what I mean)

In regards to my original problem I thought I could do something like this:

pointplot( [ [ListF], [ListH] ]);

 

I'm grateful for every answer :)

 

 

 

 

 

 

 

When making a function and using the return type, I found Maple is not catching the case when the function returns wrong type.

Actually there are two issues in this example I like to ask about. First, here is the example

restart;
kernelopts(assertlevel):=2;
TypeTools:-AddType(type_A, record(x::integer)):

foo:=proc( A::type_A ) ::type_A;  #this is what return type should be
     print( type(A,'type_A')); #this prints TRUE
     A:-x :=1.5; #opps, wrong type, changes type of record now!
     print( type(A,'type_A')); #This now prints FALSE
     return A;
end proc:

A:=Record('x' = 1);
B:=foo(A):
eval(B)

The call to foo() goes through as expected since type is correct.

First issue: Inside the function doing A:-x :=1.5;  changed the type of record now, since is supposed to be integer and now become real. Is there a way to have Maple detect this at run time?

Second issue: The function was defined to return type_A  but due to this overwriting the field of the record by wrong value, it is no longer type_A  (the print now says false). But why Maple did not detect this? Since the function is defined to only return type_A ?

Is it possible to change the code above to catch these type mistakes I made?

given A := [[1, 0,9], [5, 0, 6], [4, 0, 0]]; and to remove 0 from each entry, I used map2(remove,has,A,0) which gives 

                   [[1, 9], [5, 6], [4]]

Is it possible to do the same thing using ~ notation for mapping?  (Element-wise Operator). Where now each element is each entry in A? I can't figure what the syntax would be if possible.  remove(has,??,0)~A

For exmaple in Mathematica one would use what is called slot number #. So the above mapping would look like in Maple as doing remove(has,#,0)~A  where now acts as place holder to be filled by each entry taken one at a time from list A as the mapping runs.  But do not know if this is possible in Maple.   

map2 does the job, but can be tricky to use when the function to map takes number of different arguments.

One work around is to make seperate function, and use that for mapping, as follows

f:= x->remove(has,x,0);
f~(A)

which gives  [[1, 9], [5, 6], [4]] correctly. 

So I find the above easier to understand and more clear than map2, and I am not unhappy with it, and so I see no reason to use map2 vs. ~ in this case.

But wanted to see if it was possible to use ~ without making separate function, but do it in-line if you well (using what is called pure function, or unamed function in functional programming).

 

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 :)

First 545 546 547 548 549 550 551 Last Page 547 of 2426