acer

17575 Reputation

29 Badges

14 years, 184 days

On google groups. (comp.soft-sys.math.maple and sci.math.symbolic)

On stackoverflow.

On math.stackexchange.com.

MaplePrimes Activity


These are answers submitted by acer

Did I do this right? (Even if ok, I expect someone will do it more cleverly.)

restart;

eq := a(n) = 2*(a(n)+Sum(a(i),i=1..n-1))^2/(2*(a(n)+Sum(a(i),i=1..n-1))-1):

func := solve(eq, a(n)):
lprint(func);

-2*Sum(a(i),i = 1 .. n-1)^2/(1+2*Sum(a(i),i = 1 .. n-1))

G := subs(__dummy=subs([Sum=add, a=G],func),
  proc(n::posint)
    option remember, system;
    local i;
    if n=1 then return 1; end if;
    __dummy;
  end proc):

showstat(G);


G := proc(n::posint)
local i;
   1   if n = 1 then
   2       return 1
       end if;
   3   -2*add(G(i),i = 1 .. n-1)^2/(1+2*add(G(i),i = 1 .. n-1))
end proc

G(100);

-2/39203

 

Download recur.mw

[edited] Using rsolve, (for S(n), an idea which Carl conceived and posted before I did).

restart;

sol:=rsolve({(S(n)-S(n-1))*(2*S(n)-1)=2*S(n)^2,S(1)=1},S(n));

1/(-1+2*n)

A:=unapply(eval(sol-eval(sol,n=n-1)),n);

proc (n) options operator, arrow; 1/(-1+2*n)-1/(-3+2*n) end proc

A(100);

-2/39203

 

Download recur2.mw

The call_external is a Maple mechanism which calls a function in an external dynamic library of compiled functions. For example such dynamic libraries have filename extension .dll on MS-Windows and .so on Linux.

Like much of the Maple kernel itself such functions are compiled (and stored in external dynamic libraries) for execution speed, or because they come from 3rd party sources as code in a language other than Maple.

In general it is not possible to view the source of such functions, unless they were compiled with debugging information. (That's an OS thing, rather than a Maple thing.)

Few if any of the stock external libraries shipped with Maple were compiled with debugging information -- and if they were then you'd still need an external debugger that could run the whole process, not just Maple's user-facing debugger.

The Maple command showstat is for displaying source of procedures in the Maple language. That has nothing to do with compiled functions in dynamic libraries.

I was looking at the second paragraph of the first bullet point in the Description of the help page for Topic rtable_eval, which reads as,

    Evaluation is needed provided the following two conditions are met.
    Firstly, eval(A[i],1) <> eval(A[i]) for a given element  "A[i]". Secondly,
    full evaluation must have been applied to A prior to calling rtable_eval(A).

So, for you example, the eval(v) could be before (or within) the rtable_eval call. At the top-level the eval call would not be needed I suppose.

proc() local x, v:= <x>; x:= 1; rtable_eval(eval(v)) end proc(); 
                              [1]

In Maple 17.02 I see the addition working that way (without evaluation) as for the multipication. I am not sure why the two now differ in behavior.

So, you want the running value of x in v to be used at each iteration?

restart;

kernelopts(version);

`Maple 2019.1, X86 64 LINUX, May 21 2019, Build ID 1399874`

proc(n::nonnegint)
local x, q, v:= <<x>>, s:= <<0>>, p:= <<1>>;
   for x to n do p:= p.eval(v); s:= s+v od;
   p, s
end proc(6);

Matrix(1, 1, {(1, 1) = 720}), Matrix(1, 1, {(1, 1) = 21})

restart;

proc(n::nonnegint)
local x, q, v:= <<x>>, s:= <<0>>, p:= <<1>>;
   for x to n do p:= p.rtable_eval(eval(v)); s:= s+v od;
   p, s
end proc(6);

Matrix(1, 1, {(1, 1) = 720}), Matrix(1, 1, {(1, 1) = 21})

 

Download matrixevalexample.mw

Here's an outline of the general idea. Adjust to taste.

for i from blah to blech do
    try
        dodgy_thing;
    catch:
        print("error encountered; skipped...");
    end try;
end do;

The name `&Delta;` (which line-prints similar to an HTML entity) gets pretty-printed like a Greek Delta in 2D Output.

You can concatenate that with another symbol of your choice, to get the effect you describe.

restart;

nprintf("&Delta;%a", a);

`&Delta;a`

lprint(%);

`&Delta;a`

cat(':-`&Delta;`', a);

`&Delta;a`

lprint(%);

`&Delta;a`

PutDelta := nm -> nprintf("&Delta;%a", nm):

PutDelta(a);

`&Delta;a`

lprint(%);

`&Delta;a`

 

Download PutDelta.mw

In Maple 2018 and Maple 2019 something similar attains without having to specify method=ftocms for the int command.

Below I use Maple 2017.2,

restart;

kernelopts(version);

   Maple 2017.2, X86 64 LINUX, Jul 19 2017, Build ID 1247392

ig := R^2/(cosh(2*R)+cosh(rho))^2:

res := int(ig, R=-infinity..infinity, method=ftocms) assuming rho::real:

lprint(res);

(1/6)*exp(2*rho)*(-2*exp(2*rho)*Pi^2*rho-2*Pi^2*rho-2*exp(2*rho)*rho^3+2*exp(2*rho)*Pi^2+6*exp(2*rho)*rho^2-2*rho^3-2*Pi^2-6*rho^2)/((exp(2*rho)-1)*(-exp(4*rho)+2*exp(2*rho)-1))

eval(res, rho=1.2);

                         0.07643822467

evalf(Int(eval(ig, rho=1.2), R=-infinity..infinity));

                         0.07643822459

You asked why it goes wrong. It looks like the undesirable infinite result is coming out of the ftoc method (using regular series and limit).

Let's just take a rough look at the indefinite integration result, and compare :-limit vs Multiseries:-limit .

foo := int(ig, R):

limit(foo, R=infinity) assuming rho>0:
op(0,eval(%,1));

                 limit

MultiSeries:-limit(foo, R=infinity) assuming rho>0:
lprint(simplify(%)) assuming rho>0;

-(1/3)*exp(2*rho)*((Pi^2*rho+rho^3-Pi^2-3*rho^2)*exp(2*rho)+Pi^2*rho+rho^3+Pi^2+3*rho^2)/((exp(2*rho)-1)*(-exp(4*rho)+2*exp(2*rho)-1))

alt := MultiSeries:-limit(foo, R=infinity)
       - MultiSeries:-limit(foo, R=-infinity) assuming rho>0:

altres := simplify(alt) assuming rho>0:

lprint(%);

-(1/3)*exp(2*rho)*((Pi^2*rho+rho^3-Pi^2-3*rho^2)*exp(2*rho)+Pi^2*rho+rho^3+Pi^2+3*rho^2)/((exp(2*rho)-1)*(-exp(4*rho)+2*exp(2*rho)-1))

eval(altres, rho=1.2);

                         0.07643822463

[edit] In Maple 2019.1 the result attains for int even with method=ftoc, and :-limit also handles the latter computation.

Why the need to post this in a whole new Question thread? It simply duplicates this earlier topic, and senselessly splits the responses. (And you were provided a few robust and fast ways to compute a floating-point result in Answers in that thread.)

In your definition of operator L you have just speed and not speed(t). But you subsequently redefined speed as an operator. So you have confused expressions and operators.

You may have intended something like,
   L := proc(b) local t; int(speed(t), t = 0 .. b); end proc;

Do you think that symbolic int will be able to handle all your examples or r, for symbolic upper bound b? Why not stick with floating-point approximation as in your previous example?

What are you planning to do when the symbolic integration takes a very long time? Or when the equation involving the symbolic integration result cannot be solved explicitly for name b? Or when -- for nonnumeric upper bound b - the symbolic integration with method=ftoc runs amok while method=elliptic produces a result with special function calls that evaluates more slowly?

What are you really trying to accomplish with this entirely symbolic approach?

In the following attachment I illustrate some of the issues with your approach, and once again demonstrate a fast root-finding approach.

more_sc.mw

For some reason Mapleprimes is not inlining my attachments today.

I am guessing that you are using Maple 2019.

You'll need interface(typesetting) to be set to extended, and Typesetting:-Settings(useprime) to return true.

You can set those as follows,
    interface(typesetting=extended):
    Typesetting:-Settings(useprime=true):

The attachment illustrates your example. It also shows how 2D Output can get the same effect of derivatives using prime notation, and how the dependency can be visibly suppressed in the 2D Output.

typesetprime.mw

Here are some worksheets, with it laid out for you.

limitexample1D.mw

limitexample2D.mw

Here are some ideas, including some various kinds of automatic application.

Note that calling a blanket expand on expressions containing ``() function calls may expand more than you wish. Similarly calling blanket value on expressions containing inert % calls may make more than you wish active.

restart;

kernelopts(version);

`Maple 2018.2, X86 64 LINUX, Nov 16 2018, Build ID 1362973`

ee := (x^3-2*x^2+5*x-7) * x%^(-1);

(x^3-2*x^2+5*x-7)*`%^`(x, -1)

ff := (1/x) %* (x^3-2*x^2+5*x-7);

`%*`(1/x, x^3-2*x^2+5*x-7)

with(InertForm):

Display(ee, inert=false);

(x^3-2*x^2+5*x-7)*`%^`(x, -1)

Display(ff, inert=false);

0, "%1 is not a command in the %2 package", _Hold, Typesetting

value(ee), value(ff);;

(x^3-2*x^2+5*x-7)/x, (x^3-2*x^2+5*x-7)/x

eval(ee, `%^`=`^`), eval(ff, `%*`=`*`);

(x^3-2*x^2+5*x-7)/x, (x^3-2*x^2+5*x-7)/x

Value(ee), Value(ff);

(x^3-2*x^2+5*x-7)/x, (x^3-2*x^2+5*x-7)/x

restart;

gg := (x^3-2*x^2+5*x-7) * x^``((-1));

(x^3-2*x^2+5*x-7)*x^``(-1)

hh := ``(1/x) * (x^3-2*x^2+5*x-7);

``(1/x)*(x^3-2*x^2+5*x-7)

evalindets(gg,specfunc(anything,``),expand);

(x^3-2*x^2+5*x-7)/x

evalindets(hh,specfunc(anything,``),expand);

(x^3-2*x^2+5*x-7)/x

restart;

`print/%*` := proc()
  InertForm:-Display(`%*`(args), ':-inert'=false);
end proc:

`print/%^` := proc()
  InertForm:-Display(`%^`(args), ':-inert'=false);
end proc:

 

kk := (x^3-2*x^2+5*x-7) * x%^(-1);

(x^3-2*x^2+5*x-7)*`%^`(x, -1)

mm := (1/x) %* (x^3-2*x^2+5*x-7);

`%*`(1/x, x^3-2*x^2+5*x-7)

InertForm:-Value(kk), InertForm:-Value(mm);

(x^3-2*x^2+5*x-7)/x, (x^3-2*x^2+5*x-7)/x

eval([kk, mm], [`%^`=`^`, `%*`=`*`]);

[(x^3-2*x^2+5*x-7)/x, (x^3-2*x^2+5*x-7)/x]

value(kk), value(mm);

(x^3-2*x^2+5*x-7)/x, (x^3-2*x^2+5*x-7)/x

expr := A(x)/(x*y*K^(b));

A(x)/(x*y*K^b)

foo := numer(expr) * denom(expr)%^(-1);

A(x)*`%^`(x*y*K^b, -1)

InertForm:-Value(foo), value(foo);

A(x)/(x*y*K^b), A(x)/(x*y*K^b)

restart;

`print/%/` := proc()
  local num, den, S;
  uses Typesetting;
  if nargs<>2 then return `%/`(args); end if;
  S := {`+`,`*`,specfunc(anything,{Int,int})};
  (num,den) := Typeset(EV(args[1])), Typeset(EV(args[2]));
  if args[1]::S and nops(args[1])>1 then
    num := mfenced(num);
  end if;
  if args[2]::S and nops(args[2])>1 then
    den := mfenced(den);
  end if;
  mrow(num,mo("/"),den);
end proc:

bar := (x^3-2*x^2+5*x-7) %/ (x*y*K^(b));

`%/`(x^3-2*x^2+5*x-7, x*y*K^b)

InertForm:-Value(bar), value(bar);

(x^3-2*x^2+5*x-7)/(x*y*K^b), (x^3-2*x^2+5*x-7)/(x*y*K^b)

blah :=  (x^3-2*x^2+5*x-7) %/ (x);

`%/`(x^3-2*x^2+5*x-7, x)

InertForm:-Value(blah), value(blah);

(x^3-2*x^2+5*x-7)/x, (x^3-2*x^2+5*x-7)/x

boo := Int(f(x),x) %/ (a+b);

`%/`(Int(f(x), x), a+b)

eval(boo, `%/`=`/`)

(Int(f(x), x))/(a+b)

 

Download inert_mult.mw

How about scaling the problem by exp (eg, taken at the largest argument of the present calls to sinh for B>0)? Or something similar.

restart;

kernelopts(version);

`Maple 2019.1, X86 64 LINUX, May 21 2019, Build ID 1399874`

detA:= -(-((-16*cosh(beta*`&ell;`*xi[2])*sinh(beta*`&ell;`)+16*sinh(beta*`&ell;`*xi[2])
*cosh(beta*`&ell;`))*sinh(beta*xi[1]*`&ell;`)+(-16*sin(beta*`&ell;`*xi[2])*cos(beta*`&ell;`)
+16*cos(beta*`&ell;`*xi[2])*sin(beta*`&ell;`))*sin(beta*xi[1]*`&ell;`)-(16*(-sin(beta*`&ell;`
*xi[2])*sin(beta*`&ell;`)+cosh(beta*`&ell;`*xi[2])*cosh(beta*`&ell;`)-sinh(beta*`&ell;`*xi[2])
*sinh(beta*`&ell;`)-cos(beta*`&ell;`*xi[2])*cos(beta*`&ell;`)))*(cos(beta*xi[1]*`&ell;`)
-cosh(beta*xi[1]*`&ell;`)))*sin(beta*`&ell;`*xi[2])+16*cos(beta*`&ell;`*xi[2])*
((sin(beta*`&ell;`*xi[2])*sin(beta*`&ell;`)-cosh(beta*`&ell;`*xi[2])*cosh(beta*`&ell;`)
+sinh(beta*`&ell;`*xi[2])*sinh(beta*`&ell;`)+cos(beta*`&ell;`*xi[2])*cos(beta*`&ell;`))
*sin(beta*xi[1]*`&ell;`)+(sin(beta*`&ell;`*xi[2])*cos(beta*`&ell;`)-cos(beta*`&ell;`*xi[2])
*sin(beta*`&ell;`))*(cos(beta*xi[1]*`&ell;`)-cosh(beta*xi[1]*`&ell;`))))*sinh(beta*`&ell;`*xi[2])
+16*cosh(beta*`&ell;`*xi[2])*((sin(beta*`&ell;`*xi[2])*sin(beta*`&ell;`)-cosh(beta*`&ell;`*xi[2])
*cosh(beta*`&ell;`)+sinh(beta*`&ell;`*xi[2])*sinh(beta*`&ell;`)+cos(beta*`&ell;`*xi[2])
*cos(beta*`&ell;`))*sinh(beta*xi[1]*`&ell;`)+(sinh(beta*`&ell;`*xi[2])*cosh(beta*`&ell;`)
-cosh(beta*`&ell;`*xi[2])*sinh(beta*`&ell;`))*(cos(beta*xi[1]*`&ell;`)-cosh(beta*xi[1]*`&ell;`)))
*sin(beta*`&ell;`*xi[2])-(16*(cos(beta*`&ell;`*xi[2])*cosh(beta*`&ell;`*xi[2])-1))
*((sin(beta*`&ell;`*xi[2])*cos(beta*`&ell;`)-cos(beta*`&ell;`*xi[2])*sin(beta*`&ell;`))
*sinh(beta*xi[1]*`&ell;`)+sin(beta*xi[1]*`&ell;`)*(sinh(beta*`&ell;`*xi[2])*cosh(beta*`&ell;`)
-cosh(beta*`&ell;`*xi[2])*sinh(beta*`&ell;`))):

xi1_val:= 0.05: xi2_val:= 0.10: ell_val:= 12:

H := subs([xi[1] = xi1_val, xi[2] = xi2_val, `&ell;` = ell_val], detA):

HH := combine(subsindets(combine(H),specfunc(anything,{sinh,cosh}),u->convert(u,exp)));

-8*sin(12.00*beta)*exp(.60*beta)-8*sin(10.80*beta)*exp(.60*beta)+8*sin(12.00*beta)*exp(-.60*beta)+8*sin(10.80*beta)*exp(-.60*beta)-8*sin(.60*beta)*exp(12.00*beta)+8*sin(.60*beta)*exp(-12.00*beta)+8*sin(1.20*beta)*exp(11.40*beta)-8*sin(1.20*beta)*exp(-11.40*beta)+8*sin(11.40*beta)*exp(1.20*beta)-8*sin(11.40*beta)*exp(-1.20*beta)-8*sin(.60*beta)*exp(10.80*beta)+8*sin(.60*beta)*exp(-10.80*beta)

map(op,indets(HH,specfunc(anything,exp)));
fact := max(%) assuming beta>0;

{-12.00*beta, -11.40*beta, -10.80*beta, -1.20*beta, -.60*beta, .60*beta, 1.20*beta, 10.80*beta, 11.40*beta, 12.00*beta}

12.00*beta

new := collect(combine(HH/exp(fact)),exp,simplify);

8.*sin(.6*beta)*exp(-24.00*beta)-8.*sin(1.2*beta)*exp(-23.40*beta)+8.*sin(.6*beta)*exp(-22.80*beta)-8.*sin(11.4*beta)*exp(-13.20*beta)+(8.*sin(12.*beta)+8.*sin(10.8*beta))*exp(-12.60*beta)+(-8.*sin(12.*beta)-8.*sin(10.8*beta))*exp(-11.40*beta)+8.*sin(11.4*beta)*exp(-10.80*beta)-8.*sin(.6*beta)*exp(-1.20*beta)+8.*sin(1.2*beta)*exp(-.60*beta)-8.*sin(.6*beta)

Student[Calculus1][Roots](new, 1 .. 15, numeric);

[5.235987756, 10.47197551]

 

Download rootsexp2.mw

You haven't said just how the values of those other parameters may vary, so it's not so easy to be general about handling that.

Alternatively, you could raise the working precision (Digits), but that is slower.

[edit] If you notice that all the terms in new are products involving sin of multiples of 0.6*beta then it's not difficult to see that the roots you've mentioned are at 5*Pi/3 and 10*Pi/3, which concurs with what Axel showed. In Maple 2019.1 the solve command can find those too, if given the expanded form of the expression.

solve({expand(H), beta>0, beta<15});
Warning, solutions may have been lost
           {beta = 5.235987758}, {beta = 10.47197551}

solve({expand(convert(H,rational,exact)), beta>0, beta<15});
Warning, solutions may have been lost
                /       5   \    /       10   \ 
               { beta = - Pi }, { beta = -- Pi }
                \       3   /    \       3    / 

What precisely do you mean by your use of the term define here?

How are you planning on using this Matrix or its entries, such that this effect is seen?

Is it enough to place assumptions on the names that are the values of the entries?

restart;

k:=1: M:=1:

assume(seq(seq(u[i,j]>1,i=1..2*k*M),j=1..2^k*M));

U:=Matrix((2^(k))*M,(2^(k))*M,symbol=u);

Matrix(2, 2, {(1, 1) = u[1, 1], (1, 2) = u[1, 2], (2, 1) = u[2, 1], (2, 2) = u[2, 2]})

map(p->is(p>1), U);

Matrix(2, 2, {(1, 1) = true, (1, 2) = true, (2, 1) = true, (2, 2) = true})

type(U, 'Matrix'(satisfies(p->is(p>1))));

true

andmap(p->is(p>1), U);

true

map(p->sqrt((p-1)^2), U);

Matrix(2, 2, {(1, 1) = u[1, 1]-1, (1, 2) = u[1, 2]-1, (2, 1) = u[2, 1]-1, (2, 2) = u[2, 2]-1})

 

Download symb_mat.mw

I manually inserted the page-breaks using the GUI. Then I exported as PDF.

graphs2.mw

graphs1.mw

The graphs1.mw file uses DocumentTools:-Tabulate. You could optionally call that command so that the interior and/or exterior borders of the Tables were suppressed.

And of course you can play with the number of graphs per row, etc. And you could also adjust the font size for the vertex labels (changing the value that I forced).

The 2D Input for your worksheet's last computation is corrupted and missing in the .mw file.

Here is what I was able to recover. It has only the output for that last computation.

Calculation1_ac.mw

First 11 12 13 14 15 16 17 Last Page 13 of 204