Maple Questions and Posts

These are Posts and Questions associated with the product, Maple

I am using code form How-To-Find-The-Exact-Line-Number-And which is very useful in showing line number where exception happend in my .mla code.

The only issue is that all such messages are buffered by Maple, and only see them after the program is finished running, which can take hrs.

While the program is running, I only see the this

print(sprintf("error happened in %a: %s",
                lastexception[1],
                StringTools:-FormatMessage(lastexception[2..-1])));

But the output of the following code, do not show at same time:

if lasterrorlocus<>'lasterrorlocus' then
            print(lasterrorlocus);
            showsource();
end if; 

The above only shows when the whole code is finished running and returns. Not while it is running.

I'd like both to show up at same time. For some reason, it seems the the above either evaluated at the very end of the progam running, or showsource() is buffering it. I looked at help for command
showsource(), but see no settings to tell it not to buffer.

I tried to use fflush and FileTools:-Flush but not sure which file to use. Tried 'default' and 'STREAM' and both do not work.

It will be much more useful and easier to see the location of source code error, in same order with the other message printed, instead of all them at the very end.

To show this, below is an example. It is the same exact code by acer in the above question, I just changed my module to generate error, and put delay after that to simulate long running program.

The output shows that the list of source do not show right away, and only shows when the delay is completed. But the print message giving the exception name does show right away. First, here is screen shot showing what happens now

I'd like the put to show like this instead

Here is worksheet

Download A.mw

And here is A.mpl file, which should be put inside the same folder as indicated in A.mw, for example, C:\\tmp

#see https://www.mapleprimes.com/questions/233724-How-To-Find-The-Exact-Line-Number-And

A := module()  
    local B:=module()
        export foo:=proc(n)
            1/n;
        end proc;
    end module;

    export main:=proc()
        try
           B:-foo(0);
        catch:
          if lasterrorlocus<>'lasterrorlocus' then
            print(lasterrorlocus);
            showsource();
            #fflush('default');
            #fflush('terminal');           
            #fflush(STREAM);
            #FileTools:-Flush('default');
          end if; 
          print(sprintf("error happened in %a: %s",
                lastexception[1],
                StringTools:-FormatMessage(lastexception[2..-1])));
        end try;

        print("will now pause a little");
        Threads:-Sleep(5);
        print("OK, lets sleep more");
        Threads:-Sleep(5);
        print("Done");

    end proc;
end module:

Hi,

I am looking to design a learning sequence on the applications of integral calculus (arc length, area under the curve, solid of revolution). The animation of the solid is not optimal because I want to display the revolution over [1,2] while maintaining a global view of the curve over [-3,3]. Thank you for your insights.

 

S7_Arc_Intégrale_Animation.mw

Here is an example of timelimit hanging when adding assuming positive to the call to odetest.

Anyone could find why this happens?

timelimit still does not work well in Maple to this day.

Anyone with beta Maple 2025 could be able to check if this still hangs there or is it fixed?  

timelimit() is the most critical function for me in Maple. Since if it does not work, the whole program hangs and nothing can be done when this happens other than killing the program and not process the input that causes Maple to hang.

interface(version);

`Standard Worksheet Interface, Maple 2024.2, Windows 10, October 29 2024 Build ID 1872373`

Physics:-Version()

`The "Physics Updates" version in the MapleCloud is 1844 and is the same as the version installed in this computer, created 2025, January 25, 22:5 hours Pacific Time.`

libname;

"C:\Users\Owner\maple\toolbox\2024\Physics Updates\lib", "C:\Program Files\Maple 2024\lib"

restart;

ode:=sqrt(x)*(2*x*diff(u(x), x) + 3*u(x))/2 = sqrt(x)*(12^(2/3)*(-9*u(x)*a + sqrt(3)*sqrt(27*u(x)^2*a^2 - 4))^(2/3) + 12)*12^(2/3)/(72*(-9*u(x)*a + sqrt(3)*sqrt(27*u(x)^2*a^2 - 4))^(1/3));

(1/2)*x^(1/2)*(2*x*(diff(u(x), x))+3*u(x)) = (1/72)*x^(1/2)*(12^(2/3)*(-9*u(x)*a+3^(1/2)*(27*u(x)^2*a^2-4)^(1/2))^(2/3)+12)*12^(2/3)/(-9*u(x)*a+3^(1/2)*(27*u(x)^2*a^2-4)^(1/2))^(1/3)

sol:=u(x) = sqrt(-2*12^(1/3)*(2*a - 1 + sqrt(4*a^2 - 4*a - 3)))*12^(1/3)*(-2*a + 3 + sqrt(4*a^2 - 4*a - 3))/36;

u(x) = (1/36)*(-2*12^(1/3)*(2*a-1+(4*a^2-4*a-3)^(1/2)))^(1/2)*12^(1/3)*(-2*a+3+(4*a^2-4*a-3)^(1/2))

timelimit(30, ( odetest(sol,ode) assuming positive ) ); #hangs. Waited for hrs.

timelimit(30, odetest(sol,ode) ); #does not hang, returns right away.

(1/12)*x^(1/2)*(-2*a+1-(4*a^2-4*a-3)^(1/2))^(1/2)*(4*a^2-4*a-3)^(1/2)*6^(1/2)-(1/6)*x^(1/2)*(-2*a+1-(4*a^2-4*a-3)^(1/2))^(1/2)*a*6^(1/2)+(1/4)*x^(1/2)*(-2*a+1-(4*a^2-4*a-3)^(1/2))^(1/2)*6^(1/2)-(1/6)*x^(1/2)*3^(1/2)*(-2*a*(4*a^2-4*a-3)^(1/2)*(-4*a+2-2*(4*a^2-4*a-3)^(1/2))^(1/2)+4*a^2*(-4*a+2-2*(4*a^2-4*a-3)^(1/2))^(1/2)-6*a*(-4*a+2-2*(4*a^2-4*a-3)^(1/2))^(1/2)+8*(-2*a^3+3*a^2-1)^(1/2))^(1/3)-(2/3)*x^(1/2)*3^(1/2)/(-2*a*(4*a^2-4*a-3)^(1/2)*(-4*a+2-2*(4*a^2-4*a-3)^(1/2))^(1/2)+4*a^2*(-4*a+2-2*(4*a^2-4*a-3)^(1/2))^(1/2)-6*a*(-4*a+2-2*(4*a^2-4*a-3)^(1/2))^(1/2)+8*(-2*a^3+3*a^2-1)^(1/2))^(1/3)

 


 

Download hang_on_odetest_feb_21_2025.mw

 

 

 

 

 

i try find some part of solution of this kind of pde but i can't get results my openion is maybe this pde is wronge when i defined 

pde.mw

Let eps be a real number greater than zero. Calculate the limit lim(x-->oo)[x^(1-eps)*Integral(from x to x+1) sin(t^2)dt] .

my solution is a little bit long which when i click on pdetest command i wait at least more than a hour but still is runing and i don't get any result and not give me error , which i don't know my result is true or not so How i can find that my pde by this solution it will be zero or not ?

restart

with(PDEtools)

with(LinearAlgebra)

NULL

with(SolveTools)

undeclare(prime)

`There is no more prime differentiation variable; all derivatives will be displayed as indexed functions`

(1)

declare(u(x, y, t))

u(x, y, t)*`will now be displayed as`*u

(2)

declare(f(x, y, t))

f(x, y, t)*`will now be displayed as`*f

(3)

pde := diff(u(x, y, t), t)-(diff(diff(u(x, y, t), `$`(x, 4))+5*u(x, y, t)*(diff(u(x, y, t), `$`(x, 2)))+(5/3)*u(x, y, t)^3+5*(diff(u(x, y, t), x, y)), x))-5*u(x, y, t)*(diff(u(x, y, t), y))+5*(int(diff(u(x, y, t), `$`(y, 2)), x))-5*(diff(u(x, y, t), x))*(int(diff(u(x, y, t), y), x))

diff(u(x, y, t), t)-(diff(diff(diff(diff(diff(u(x, y, t), x), x), x), x), x))-5*(diff(u(x, y, t), x))*(diff(diff(u(x, y, t), x), x))-5*u(x, y, t)*(diff(diff(diff(u(x, y, t), x), x), x))-5*u(x, y, t)^2*(diff(u(x, y, t), x))-5*(diff(diff(diff(u(x, y, t), x), x), y))-5*u(x, y, t)*(diff(u(x, y, t), y))+5*(int(diff(diff(u(x, y, t), y), y), x))-5*(diff(u(x, y, t), x))*(int(diff(u(x, y, t), y), x))

(4)

pde_nonlinear, pde_linear := selectremove(proc (term) options operator, arrow; has((eval(term, u(x, y, t) = a*u(x, y, t)))/a, a) end proc, pde)

-5*(diff(u(x, y, t), x))*(diff(diff(u(x, y, t), x), x))-5*u(x, y, t)*(diff(diff(diff(u(x, y, t), x), x), x))-5*u(x, y, t)^2*(diff(u(x, y, t), x))-5*u(x, y, t)*(diff(u(x, y, t), y))-5*(diff(u(x, y, t), x))*(int(diff(u(x, y, t), y), x)), diff(u(x, y, t), t)-(diff(diff(diff(diff(diff(u(x, y, t), x), x), x), x), x))-5*(diff(diff(diff(u(x, y, t), x), x), y))+5*(int(diff(diff(u(x, y, t), y), y), x))

(5)

thetai := t*w[i]+y*p[i]+x

t*w[i]+y*p[i]+x

(6)

eqw := w[i] = -5*p[i]^2

w[i] = -5*p[i]^2

(7)

Bij := proc (i, j) options operator, arrow; (-6*p[i]-6*p[j])/(p[i]-p[j])^2 end proc

proc (i, j) options operator, arrow; (-6*p[i]-6*p[j])/(p[i]-p[j])^2 end proc

(8)

NULL

theta1 := normal(eval(eval(thetai, eqw), i = 1)); theta2 := normal(eval(eval(thetai, eqw), i = 2))

-5*t*p[1]^2+y*p[1]+x

 

-5*t*p[2]^2+y*p[2]+x

(9)

eqf := f(x, y, t) = (-5*t*p[1]^2+y*p[1]+x)*(-5*t*p[2]^2+y*p[2]+x)-(6*(p[1]+p[2]))/(p[1]-p[2])^2

f(x, y, t) = (-5*t*p[1]^2+y*p[1]+x)*(-5*t*p[2]^2+y*p[2]+x)-6*(p[1]+p[2])/(p[1]-p[2])^2

(10)

eq17 := u(x, y, t) = 6*(diff(diff(f(x, y, t), x), x))/f(x, y, t)-6*(diff(f(x, y, t), x))^2/f(x, y, t)^2

u(x, y, t) = 6*(diff(diff(f(x, y, t), x), x))/f(x, y, t)-6*(diff(f(x, y, t), x))^2/f(x, y, t)^2

(11)

eqt := eval(eq17, eqf)

u(x, y, t) = 12/((-5*t*p[1]^2+y*p[1]+x)*(-5*t*p[2]^2+y*p[2]+x)-6*(p[1]+p[2])/(p[1]-p[2])^2)-6*(-5*t*p[1]^2-5*t*p[2]^2+y*p[1]+y*p[2]+2*x)^2/((-5*t*p[1]^2+y*p[1]+x)*(-5*t*p[2]^2+y*p[2]+x)-6*(p[1]+p[2])/(p[1]-p[2])^2)^2

(12)

``

pdetest(eqt, pde)

NULL

Download test.mw

Hi,

I'm looking to animate the Riemann sum only on the interval [0,2], while keeping a global view of the curve (G). I tried the background option, but without success. Any ideas? Thanks!

S7_Riemann_Animation_Aire.mw

Hi. How to plot the 2d output like this? I don't know how to declare "a" and "b" random constant?
The pair of equations x = a and y = b graphically represents lines which  are, a. parallel , b. intersecting at (b, a), c. coincident, d.  intersecting at (a, b)

a := (rand(3 .. 4))(); b := (rand(0 .. 3))(); plot(x = a); plot(y = b)

3

 

2

 

Error, (in plot) unexpected option: x = 3

 

Error, (in plot) unexpected option: y = 2

 
 

``

Download x=a_y=b_plot.mw

In a procedure what is the way to only allow specific values in a variable?

ie/

change:=proc(a::integer, b={10,20,30})#only values 10, 20 and 30 allowed for variable b
  a*b;
end proc:

Trying to find a formula such that when n is negative the value is +1 and when n is positive the value is 0, without using an if statement. 

The square grid is given in the Euclidean plane. All grid points therefore have integer coordinates. Investigate whether there are three points in this grid plane that form an equilateral triangle.

Consider the following:

MyTableElement1 := proc(L::list(nonnegint))
  ## L will have only two elements
  local M, x, y;
  M:=L;
  x:=convert(M[1],string);
  y:=convert(M[2],string);

  return cat("\\begin{tabular}{c} ",x," \\\\ ",y," \\end{tabular}")

end;

MyTableElement1([2,3]);

will output

"\begin{tabular}{c} 2 \\ 3 \end{tabular}"

as desired. However, if one inserts an \hline into the table,

MyTableElement2 := proc(L::list(nonnegint))
  ## L will have only two elements
  local M, x, y;
  M:=L;
  x:=convert(M[1],string);
  y:=convert(M[2],string);

  return cat("\\begin{tabular}{c} ",x," \\\\ \\hline ",y," \\end{tabular}")

end;

will output

"\begin{tabular}{c} 2 \\ \hline 3 \end{tabular}"

again as desired. However, if I copy and paste this int a document, I get

"\begin{tabular}{c} 2 \\ hline 3 \end{tabular}".

Note that \hline is now just hline. Putting "\\\\" in front of the hline outputs

"\begin{tabular}{c} 2 \\ \\hline 3 \end{tabular}",

but this does not compile properly. How can I get a proper \hline command to appear in the table? Thank uou for your consideration.

After a long chat with ChatGPT I finally received a fully working code for a proc for a generalized Woodbury Identity for the inversion of the sum of two or more positive definite matrices.
I was inspired by a family member who is a trained professional programmer, who told me that in his professional work he uses ChatGTP for an initial draft of his program.  
I did find out that ChatGTP makes errors: from simple ones like writing 'Simplify' instead of 'simplify' to serious conceptual errors, for example in recursive loops. However, ChatGTP seems to 'understand' the error after given specific feedback. Although, this does not mean that the next proposal does not contain the same logical error. But after a long chat I received a nice proc that seems to work. 
My second surprise was that Gemini suggested a formula for the generalized Woodbury lemma that was unknown to me, and I was unable to find on Scholar Google or https://math.stackexchange.com. Based on a special case of that formula, I was able to write the second proc myself. 
In conclusion, to start working it can be helpful to collaborate with AI friend, a little patience may help, AI may not be astute as someone on Mapleprimes wrote, but neither am I. I am now retired, and it is fun to play with Maple and AI. 
By the way, the search term Woodbury did not give a single hit on Mapleprimes.With_a_little_help_from_my_friends.mw
kind regards,Harry 

 

 Can I solve the Tolman-Oppenheimer-Volkoff equation with Maple ?  I'm having trouble with Einstein's equation with the energy tensor as the second member


Let's suppose I define a procedure P which uses a Maple built-in procedure BP.
BP is a procedure which uses optional parameters, let's say a and b.

I would like to call P with the same optional parameter names than BP, that is to write something like this

P := proc(....., {a::a_type:=a:-default, b::b-type:=b_default)
       ....
       BP(...., 'a'=a, 'b'=b)
     end proc.

The execution of P(..., a=1) leads to the error unexpected option: 1=1
 

A workaround is to define P this way

P := proc(....., {P_a::a_type:=a_default, P_b::b-type:=b_default)
       ....
       BP(...., a = P_a, b = P_b)
     end proc.

# example

P(..., P_a=1, P_b="yes")

This works but it would be easier for the users to use the same option names in the definition of P than in the definition of BP.

Question: Is that possible?

Here is an illustrative example where I would prefer to write

ecdf(S, color="red", thickness=3)

instead of

ecdf(S, ecdf_color="red", ecdf_thickness=3)


 

restart

ecdf := proc(S, {ecdf_color::string:="blue", ecdf_thickness::posint:=1})
  local N   := numelems(S):
  local M   := sort(S):
  local opt := [color=ecdf_color, thickness=ecdf_thickness]:
  plots:-display(
    plot([ seq(op([[M[i], (i-1)/N], [M[i], i/N], [M[i+1], i/N]]), i=1..N-1) ], opt[])
    , plot([ [M[N], (N-1)/N], [M[N], 1] ], opt[])
    , plot([ [M[N], 1], [(max+(max-min)*0.2)(S), 1] ], opt[], linestyle=3)
    , plot([ [M[1], 0], [(min-(max-min)*0.2)(S), 0] ], opt[], linestyle=3)
  )
end proc:

S := Statistics:-Sample(Uniform(0, 1), 10):
ecdf(S)

 

ecdf(S, ecdf_color="red", ecdf_thickness=3)

 

 


 

Download ecdf.mw


Thanks in advance

 

5 6 7 8 9 10 11 Last Page 7 of 2191