MaplePrimes Questions

I depend alot on bracket matching to help me during writing code.

Maple suddenly losses bracket matching at some lines. I think it related to using strings with "\\" in them.

I make sure I have bracket matching on

 

I use worksheet mode (corrected), Maple 2020 under windows 10.

I made small video. Notice how the brackets do not match on the second line there.

Do you see how the brackets do not match on that second line there? This movie below shows what happens when I remove "\\string" from the line. Now bracket match starts to work again.

This is a serious problem for me. Any suggestions what to try to fix it and what can cause it?. Once bracket matching is lost, it is lost all the way to the rest of the code below the location where it started to lose first time.

restart;
if length(data_last(k,8))>300 then
   fprintf(file_id,"%s\n","\\footnotesize");
fi;

I think I have to find different editor to use and write the code to .mpl file since I have lots of such code and I need to have bracket matching working.

I am interested in trying to find the Kretschmann Scalar of certain metric, where the line element in given bellow as well as conditions on the indices. 

I am wondering if there is any possible way to compute the Riemann tensor components just using indices with the physics package or the tensor package. I have used them both before but for metrics which are explicitly defined. 

 

Thank you. 

 

 

Hello,

 

 

 

restart; with(Physics); Setup(mathematicalnotation = true); Setup(dimension = 3, metric = Euclidean, spacetimeindices = lowercaselatin); g_[]; Define(X[i], P[k]); Setup(quantumop = {P, X}, algebrarules = {%Commutator(P[i], P[j]) = 0, %Commutator(X[i], X[j]) = 0, %Commutator(X[j], P[k]) = Physics:-`*`(I, g_[j, k])}); L2 := Simplify(Physics:-`^`(Physics:-`*`(Physics:-`*`(LeviCivita[i, j, k], X[j]), P[k]), 2)); L2X := Simplify(Commutator(L2, X[k])); L2L2X__1 := Simplify(Commutator(L2, L2X)); L2L2X__2 := Simplify(Expand(AntiCommutator(Physics:-`*`(2, L2), X[k]))); Simplify(L2L2X__1-L2L2X__2)

[mathematicalnotation = true]

 

`The dimension and signature of the tensor space are set to `[3, `- - +`]

 

`The Euclidean metric in cartesian coordinates`

 

`Changing the signature of the tensor spacetime to: `*`+ + +`

 

[dimension = 3, metric = {(1, 1) = 1, (2, 2) = 1, (3, 3) = 1}, spacetimeindices = lowercaselatin]

 

Physics:-g_[a, b] = Matrix(%id = 18446746397905475934)

 

`Defined objects with tensor properties`

 

{Physics:-Dgamma[a], P[k], Physics:-Psigma[a], X[i], Physics:-d_[a], Physics:-g_[a, b], Physics:-LeviCivita[a, b, c]}

 

`* Partial match of  '`*quantumop*`' against keyword '`*quantumoperators*`' `

 

_______________________________________________________

 

[algebrarules = {%Commutator(P[i], P[j]) = 0, %Commutator(X[i], X[j]) = 0, %Commutator(X[j], P[k]) = I*Physics:-g_[j, k]}, quantumoperators = {P, X}]

 

(2*I)*Physics:-`*`(X[j], P[j])+Physics:-`*`(Physics:-`^`(X[j], 2), Physics:-`^`(P[k], 2))-Physics:-`*`(X[j], X[k], P[j], P[k])

 

2*X[k]-(2*I)*Physics:-`*`(Physics:-`^`(X[b], 2), P[k])+(2*I)*Physics:-`*`(X[c], X[k], P[c])

 

(12*I)*Physics:-`*`(X[c], X[k], P[c])-(4*I)*Physics:-`*`(Physics:-`^`(X[b], 2), P[k])+4*X[k]+4*Physics:-`*`(Physics:-`^`(X[b], 2), X[k], Physics:-`^`(P[h], 2))-4*Physics:-`*`(X[a], Physics:-`^`(X[b], 2), P[a], P[k])+4*Physics:-`*`(Physics:-`^`(X[b], 2), X[f], P[f], P[k])-4*Physics:-`*`(X[f], X[i], X[k], P[f], P[i])

 

4*X[k]+(12*I)*Physics:-`*`(X[c], X[k], P[c])+4*Physics:-`*`(Physics:-`^`(X[b], 2), X[k], Physics:-`^`(P[d], 2))-(4*I)*Physics:-`*`(Physics:-`^`(X[b], 2), P[k])-4*Physics:-`*`(X[e], X[f], X[k], P[e], P[f])

 

0

(1)

NULL

 

 

 

 

Download Commutator_Algebra_with_L2.mw

 

 

 

I have the following issue.

The way it is set at the moment, works kinda in that the final result is 0, which I tried to check.

However, the expression L2L2X[1] is not fully Simplified, since the term

-(4*X[a])*X[b]^2*P[a]*P[k] + (4*X[b]^2)*X[f]*P[f]*P[k]

is actually zero. I suppose that he doesn't manage because of the different indices "a" and "f" here. How can this be fixed?

 

When I comment out "Define" and use "Coordinates(X,P)" instead, it doesn't work. Seems to give the wrong result (Difference is not zero).

 

Hey,

I'm trying to differentiate a function but whenever I do so, it adds new variables for some reason. I think I might be able to copy the new function and just delete the extra but it is not a good solution.

 

So I'm hoping someone could help me to figure out how to remove all this extra that Maple adds to my equation. Thanks in advance.

 

If I have v = 2400000 m/s as a a result. 

 

How do I convert this with units to 2.4*10 m/s in maple. 

Any idea on howto do this?

 

Best Regards. 

Using mode with axis we can choose linear or log.  But what if we want some other custom scaled axis?

Seems if we want a y^3 y-axis, we'll have to cube root the data then use plottools to form our own scale.  Unless there's some other way I don't know. 

f:= 2*x^5-x^3*y+2*x^2*y^2-x*y^3+2*y^5;

This is symetrical in x and y.  subs(x=1,f) and  subs(y=1,f) are identical in form.

for idx to 10 do
    lim:=1/idx:
    plots[implicitplot](f,x=-lim..lim,y=-lim..lim,numpoints=1000000);
end do;

This shows a curve to (0,0) in quadrant 2, rabit ears in quadrant 1, and a curve from (0,0) in quadrant 4.

Plotting this with python matplotlib shows values in quadrant 3.  I assume that matplotlib plots only the real zeros of the polynomial.  Looks like it, the plotted values match the real zeros in maple.

use RealDomain in
    for idx from -1/100 to 1/100 by 1/1000 do
        lprint(idx,evalf(solve(subs(x=idx,f)=0)));
    end do;
end use;

This shows no values in quadrant 3.

How do I show/prove no zeros in quadrant 3?

I noticed some problems with pdsolve in 2020. Using Maple 2020 on windows 10 with latest Physics 626.

This PDE now hangs when the timeout is increased. This does not happen in Maple 2019.2.1/
 

restart; 
pde := diff(w(x,y),x)+(a*sin(lambda*x + mu)^k * (y-b*x^n -c)^2 + y - b*x^n + b*n*x^(n-1) - c)*diff(w(x,y),y) = 0; 
cpu_time := timelimit(60*5,CodeTools[Usage](assign('sol',pdsolve(pde,w(x,y))),output='realtime'));

In Maple 2019.2 it gives

    Error, (in trig/reduce/reduce) time expired

Which is good. Since I can now go on to the next PDE.

The hang goes away in Maple 2020 when small timeout is used.  For example I just tried 30 seconds timeout instead of 300 or more seconds and it did expire ok.

This tells me that it depends where it was in the kernel at the time. But as a user, I have no way to control this and so I use the same timeout for all the problems.

Do others using Maple 2020 see the same issue? I know that the timeout does not happen at exactly the same amout given, but for this one, I waited for almost 40 minutes and it still did not time out.

Is this a new bug and is there a better way to handle this other than using timelimit()?

Thank you

Hi 

I'm trying to plot Bar in maple 

yr=[0.1,0.2,0.3];

sle=[8,12,200]

Statistics:-ColumnGraph(yr,sle)

But not work

I'm trying to accent variables with both hats and checks (^ , v). I was able to get this to work using `#mover(mi("π"),mi("^"))`; but `#mover(mi("π"),mi("✓"))`; doesn't look very good. Is there a better alternative? 

This behavior by Maple is completely wrong if you ask me.

But given this is how Maple works, the question I have is how to explictly close a file opened by call to readline()?

I have a proc(), where inside it, it wants to read say first 3 lines by calling readline("input.txt") on a file. Then the proc() returns back to caller.

The first call reads the first 3 lines from the file OK.

I expected all resources to be removed after the call returns, including any files opened to be automatically closed. So next time proc() is called, I expected the first 3 lines to be read again.

It turns out the next time  proc() is called, now lines 4,5,6 are read. This is becuase the file remained open between calls!  Only way to close the file is to call restart() on the whole session. But I do not want to do this. 

Looking at help, I see no method to explicity close the file other than reading all the lines.

How does one explicitly close a file opened by readline() without reading the whole file?

Here is example

restart;

foo := proc()
local n,current_line;

   for n from 1 to 3 do
       current_line:= readline("input.txt");
       print("line read is ",current_line);
   od;
end proc;

And now the above is called as follows

currentdir("C:\\test"); #change as needed
foo()
                   "line read is ", "line 1"
                   "line read is ", "line 2"
                   "line read is ", "line 3"

Next call

foo()
                   "line read is ", "line 4"
                   "line read is ", "line 5"
                   "line read is ", "line 6"

Where input.txt is 

line 1
line 2
line 3
line 4
line 5
line 6

I know how to do all this using fopen() and fscanf() and explicit fclose(). I also know I can use FileTools package.

But wanted to check first if readline() will do what I wanted more easily if I can figure how to close the file explicitly.

Hello

I would like to fillup the area between multiple function in my plot.

The plot consist out of multiple functions. Each function connects to one another.

In total there are 10 functions that define the border. The grey horizontal lines (PL4 and PL7) and all red lines PL8 - PL15.

I tried to find codes, but i cant get them to work.

 

 

Thanks a lot for any help!

 

I was working through an old text book, trying to understand a different problem.  I came across this problem in an exercise set and thought it was simple.  Until I tried it.

The difficlty I had was in using subs to substitute all values.  I had to use subs 2 or 3 times to get all substitutions.  How can I avoid this?

## Prove if F is the fibonacci sequence,
restart;
with(combinat, fibonacci):
F := n -> fibonacci(n);  ## F(n+1) = F(n)+F(n-1); F(1) = 1;
## the problem
P := n-> F(n+1)*F(n+2) - F(n)*F(n+3);
##
check_low := proc(n)
    local idx;
    for idx to n do
        print(P(idx),(-1)^idx);
    end do;
end proc;
check_low(1);
check_low(2);
check_low(3);
check_low(4);

## Assume true for n=k
A := P(k) = (-1)^k;

notation := { F(k)   = a,
              F(k+1) = b,
              F(k+2) = c,
              F(k+3) = d,
              F(k+4) = e };

## some fibonacci definitions
fibs := [ e = c + d,  d = b + c, c = a + b ];

eq1 := subs(notation,A);
eq1 := subs(fibs,eq1);
eq1 := subs(fibs,eq1);  ## have to repeat to get only a and b in the expression

eq2 := subs(notation,P(k+1));
eq2 := subs(fibs, eq2);
eq2 := subs(fibs, eq2);
eq2 := subs(fibs, eq2);  ## have to repeat to get only a and b in the expression
## Reduce eq2 to (-1)^(k+1)
simplify(eq2 = -lhs(eq1));
verify(eq2, -lhs(eq1), equal);
evalb(eq2); simplify(%);  ## Ah, this is why I need equal in verify.
evalb(-lhs(eq1)); simplify(%);

testeq(eq2, -lhs(eq1));

 

Hi, 

Suppose you have to do some sequence of operations on a random variable (RV), and that you need to repeat this for several RV of the same family (e.g. exponential RV), differing only in the values of their parameters.

Here are two examples do code this.
1/ probably the most natural way to proceed (?)
restart:
with(Statistics):
X := a -> RandomVariable(Exponential(a)):
for n from 1 to 100 do
  S := X(n);
  # here are some operations to do
end do:
anames(alluser);

The last instruction indicates that 103 user variables have been created (X, n, S and 100 random variables).
Note that adding one of the commands S := 'S'; or unassign('S') before the end of the loop just unassigns S but not remove the variables named _ProbabilityDistribution, ..., _ProbabilityDistribution98.


2/ To prevent this inflation of random variables I thought to use the procedure Specialize:
restart:
with(Statistics):
X := RandomVariable(Exponential(a)):
for n from 1 to 100 do
  S := Specialize(X, [a=n]):

  # here are some operations to do
end do:
anames(alluser);

This doesn't change the situation.

So my (multiple) question: 

  • How can I prevent the creation of the objects _ProbabilityDistribution, ..., _ProbabilityDistribution98 given only one of them is used for a given value of the loop counter (once the operations have been done I pass to another random variable) ?
  • How can I unassign a random variable ?
    Maybe it is not possible as suggested by the help page about "_": "Any symbol beginning with an underscore (_) is effectively reserved for use only by library code. It is not available to users." ?

Thanks in advance

Hello everyone,

I have the following problem:

I have an array of data dataarray[i,j,k] whose elements are either 1 or -1. I also have three vectors x[i], y[j] and z[k] (the axis).  I want to represent the data of dataarray so I have two different volumes: A green volume such as dataarray(x,y,z)=1 and a red one with dataarray(x,y,z)=-1. Is that possible? In case that it is, how can I do that?

Thank you very much in advance

1 2 3 4 5 6 7 Last Page 3 of 1853