acer

32358 Reputation

29 Badges

19 years, 331 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

These plots render much less grainily in the actual Maple GUI.

[edited: I've added in the version without the black borders, and with the borders shaded to match one of the adjacent fill colors, and made a correction to the bookkeeping there.]

restart

Digits := 16

Filter:=proc(input_signal) #Band-pass filter

NULL

L0 := ImportMatrix(cat(kernelopts(homedir), "/mapleprimes/Spectro_Test.txt"), source = delimited, delimiter = "\t", datatype = float[8])

Matrix(%id = 18446884564431775254)

delt := 1000*(L0[25, 1]-L0[24, 1])

0.10000000000000e-2

tref := 1000*L0[1, 1]

#Correct timescale

timescale := Vector[column](`<,>`(seq(tref+(i-1)*delt, i = 1 .. numelems(L0[() .. (), 1]))), datatype = float[8])

signal := L0[() .. (), 2]

Parameters for STFT

t1 := 152; t2 := 160

N1 := round((t1-timescale[1])/delt)+1

N2 := round((t2-timescale[1])/delt)+1

Signal := Filter(signal[N1 .. N2])

window_type := Hann

nfft := 2^10

SignalProcessing:-Spectrogram(Signal, samplerate = round(1000/delt), fftsize = nfft, window = window_type)

temp := plottools:-getdata(%)

res1 := map(proc (x) options operator, arrow; 10^((1/20)*x) end proc, temp[3])

Matrix(%id = 18446884564291772894)

temp0 := ArrayTools:-Dimensions(res1)

[1 .. 14, 1 .. 513]


This works, but its use of subs, in a listdensityplot, seems awkward. The plots:-surfdata command offers an easier way to specify the ranges. (See below).

subs(temp0[1] = t1 .. t2, temp0[2] = temp[2][2], plots:-listdensityplot(res1, view = [t1 .. t2, 5 .. 60], style = patchnogrid, smooth = true, labels = ["Time (ms)", "Frequency (kHz)"], labeldirections = [Horizontal, Vertical], axes = box, axesfont = ["Arial", 14], labelfont = ["Times New Roman", "Bold", 16], colorscheme = ["#00007F", "Blue", "#007FFF", "Aqua", "#7FFF7F", "Yellow", "coral", "Red"], title = "Spectrogram", titlefont = ["Calibri", "Bold", 16], size = [600, 600]))

clist := ["#00007F", "Blue", "#007FFF", "Aqua", "#7FFF7F", "Yellow", "coral", "Red"];

["#00007F", "Blue", "#007FFF", "Aqua", "#7FFF7F", "Yellow", "coral", "Red"]


Concerning the Second Part of the Question: how to do the above more straightforwardly:

Instead of trying to fix up that listdensityplot's ranges, we can use the simpler functionality to specify the ranges that the plots:-surfdata provides.

ans_surf:=plots:-surfdata(res1, dimension=2, 152 .. 160, 0 .. 500, view = [t1 .. t2, 5 .. 60],
                          style = patchnogrid, colorscheme = clist,
                          labels = ["Time (ms)", "Frequency (kHz)"],
                          labeldirections = [Horizontal, Vertical], axes = box,
                          axesfont = ["Arial", 14], labelfont = ["Times New Roman", "Bold", 16],
                          title = "Spectrogram", titlefont = ["Calibri", "Bold", 16], size=[500,500]):

ans_surf;


Concerning the First Part, how to shade a listcontplot by a list of more than two colors: this solution implements multiple regions with solid colorings. (Obtaining multiple distinct shaded gradients would be another interesting goal, possibly done by constructing multiple surfdata results using piecewise undefined data?!)

Make a listcontplot with coloring from Black to pure Red. Thus the COLOUR substructures will have RGB values with the red component between 0.0 and 1.0.

PP := plots:-listcontplot(res1, coloring = ["Black", "Red"], filledregions = true, thickness=0,
                          levels = nops(clist)-1):

#clistlist := map(c->[ColorTools:-Color(c)[]], ListTools:-Reverse(clist)):
Clist := map(c->[ColorTools:-Color(c)[]], clist):

Replace the COLOUR substructures with colors from out list, taking the position based on the relative position of the existing red component between 0.0 and 1.0.

recoloredPP := subsindets(PP, specfunc(POLYGONS),
                          p->subsindets(p, specfunc(COLOUR),
                                        c->COLOUR(RGB,Clist[1+round((nops(Clist)-1)*(op(2,c)))][]))):

Instead of fiddling with forced tickmarks, transform the listcontplot from being 1..14,1..513 to 152..160,0..500 .
 
adj := plottools:-transform((x,y)->[152+(x-1)/(14-1)*(160-152),0+(y-1)/(513-1)*(500-0)]):

newPP:=plots:-display( adj(recoloredPP),
                       view = ["default", 5 .. 60],
                       labels = ["Time (ms)", "Frequency (kHz)"], labeldirections = [Horizontal, Vertical],
                       labelfont = ["Times New Roman", "Bold", 16],
                       axes = box, axesfont = ["Arial", 14],
                       title = "Spectrogram#2", titlefont = ["Calibri", "Bold", 16], size = [500, 500]):
newPP;

#plots:-display(Array([ans_surf, newPP]));


We can also test the transformer adj, by overlaying an unfilled listcontplot with the sufdata plot. If the transformer is correctly done then the contours would lie on the locations where the smoothed/interpolated colors's underlying values change. This is just a sanity check.

unfilledPP:= plots:-listcontplot(res1, coloring = ["Black", "Red"], thickness=0, levels = nops(clist)-1):

plots:-display( ans_surf, adj(unfilledPP) );


What if we don't like the black lines in the listcontplot result? We can remove them:

newPPnocurves:=subsindets(newPP,specfunc(CURVES),()->NULL):
newPPnocurves:


The edges of the filled regions appear ragged when the CURVES substructures have been removed. We can add shaded versions of those CURVES, so that the edges of the filled regions once again appear smooth (but not all the same colour).

Note that we have a choice between overlaying any ragged POLYGONS edge with either the lower or the upper adjacent color.

We can construct those CURVES (contours) using the same technique as before, but this time leaving out the filledregions option.


PPcurves := plots:-listcontplot(res1, coloring = ["Black", "Red"], levels = nops(clist)-1, thickness=0):
recoloredPPcurves := subsindets(PPcurves, specfunc(CURVES),
                          p->subsindets(p, specfunc(COLOUR),
                                        c->COLOUR(RGB,Clist[`if`(op(2,c)=0.0,1,1+round((nops(Clist))*(op(2,c))))][]))):
newPPcurves:=plots:-display( adj(recoloredPPcurves),
                             view = ["default", 5 .. 60] ):

newPPcurves;


Now we'll combine the multicoloured filled contour plot with the multicoloured unfilled contour plot.

newPPboth := plots:-display(newPPnocurves, newPPcurves):

newPPboth;


We could compare the multicoloured listcontplots, both with and without the added multicolored contour CURVES.

plots:-display(Array([newPP, newPPnocurves, newPPboth]));

 

 

 

 

 


We could compare with the original plots:-surfdata plot (keeping in mind that there were only 14 x-data points for each y-data point, which is coarse data).

plots:-display(Array([ans_surf, newPPboth]));

 

 

 

 

 

 

Download Maple_s_test_3.mw

Your result is from the (deprecated) linalg[eigenvectors] command. It uses a format in which the multiplicity of the eigenvalues is part of the result. Notice that it shows a multiplicity of 2 for the eigenvalue equal to 1000. All the other exact eigenvalues have multiplicity of 1. So eigenvectors returns 7 lists, but they denote 8 eigenpairs.

restart

with(LinearAlgebra)

T := Matrix([[611, 196, -192, 407, -8, -52, -49, 29], [196, 899, 113, -192, -71, -43, -8, -44], [-192, 113, 899, 196, 61, 49, 8, 52], [407, -192, 196, 611, 8, 44, 59, -23], [-8, -71, 61, 8, 411, -599, 208, 208], [-52, -43, 49, 44, -599, 411, 208, 208], [-49, -8, 8, 59, 208, 208, 99, -911], [29, -44, 52, -23, 208, 208, -911, 99]])

Matrix(%id = 18446884131466194566)

old := [linalg[eigenvectors](T)]

[[510+100*26^(1/2), 1, {array( 1 .. 8, [( 1 ) = (-5+26^(1/2)), ( 2 ) = (5/2-(1/2)*26^(1/2)), ( 3 ) = (-5/2+(1/2)*26^(1/2)), ( 4 ) = (5-26^(1/2)), ( 5 ) = (1/2), ( 6 ) = (-1/2), ( 7 ) = (-1), ( 8 ) = (1)  ] )}], [510-100*26^(1/2), 1, {array( 1 .. 8, [( 1 ) = (-5-26^(1/2)), ( 2 ) = (5/2+(1/2)*26^(1/2)), ( 3 ) = (-5/2-(1/2)*26^(1/2)), ( 4 ) = (5+26^(1/2)), ( 5 ) = (1/2), ( 6 ) = (-1/2), ( 7 ) = (-1), ( 8 ) = (1)  ] )}], [1020, 1, {array( 1 .. 8, [( 1 ) = (-1/2), ( 2 ) = (1), ( 3 ) = (1), ( 4 ) = (-1/2), ( 5 ) = (-1), ( 6 ) = (1), ( 7 ) = (-1/2), ( 8 ) = (1/2)  ] )}], [0, 1, {array( 1 .. 8, [( 1 ) = (1/7), ( 2 ) = (2/7), ( 3 ) = (-2/7), ( 4 ) = (-1/7), ( 5 ) = (2), ( 6 ) = (2), ( 7 ) = (1), ( 8 ) = (1)  ] )}], [10*10405^(1/2), 1, {array( 1 .. 8, [( 1 ) = (102+10405^(1/2)), ( 2 ) = ((1/2)*10405^(1/2)+51), ( 3 ) = ((1/2)*10405^(1/2)+51), ( 4 ) = (102+10405^(1/2)), ( 5 ) = (-1/2), ( 6 ) = (-1/2), ( 7 ) = (1), ( 8 ) = (1)  ] )}], [-10*10405^(1/2), 1, {array( 1 .. 8, [( 1 ) = (102-10405^(1/2)), ( 2 ) = (-(1/2)*10405^(1/2)+51), ( 3 ) = (-(1/2)*10405^(1/2)+51), ( 4 ) = (102-10405^(1/2)), ( 5 ) = (-1/2), ( 6 ) = (-1/2), ( 7 ) = (1), ( 8 ) = (1)  ] )}], [1000, 2, {array( 1 .. 8, [( 1 ) = (-3), ( 2 ) = (-8), ( 3 ) = (6), ( 4 ) = (4), ( 5 ) = (0), ( 6 ) = (2), ( 7 ) = (0), ( 8 ) = (1)  ] ), array( 1 .. 8, [( 1 ) = (-4), ( 2 ) = (-6), ( 3 ) = (8), ( 4 ) = (3), ( 5 ) = (2), ( 6 ) = (0), ( 7 ) = (1), ( 8 ) = (0)  ] )}]]

nops(old)

7

map[2](op, 2, old); add(op(2, p), p = old)

8


The "2" in the new output indicates that eigenvalue 1000 occurs with multiplicity 2. (You may also note that it is associated with 2 linearly independent eigenvectors.)

select(proc (p) options operator, arrow; 1 < op(2, p) end proc, old)

[[1000, 2, {array( 1 .. 8, [( 1 ) = (-3), ( 2 ) = (-8), ( 3 ) = (6), ( 4 ) = (4), ( 5 ) = (0), ( 6 ) = (2), ( 7 ) = (0), ( 8 ) = (1)  ] ), array( 1 .. 8, [( 1 ) = (-4), ( 2 ) = (-6), ( 3 ) = (8), ( 4 ) = (3), ( 5 ) = (2), ( 6 ) = (0), ( 7 ) = (1), ( 8 ) = (0)  ] )}]]

newevals, newevecs := Eigenvectors(T)


Unfortunately the newer Eigenvectors command is not returning the eigenvectors in as simplified form.

So I'll map a simplifying command over them.

newevals, map(`@`(`@`(simplify, expand), rationalize), newevecs)

Vector[column](%id = 18446884131466193606), Matrix(%id = 18446884131350005030)

numelems(newevals)

8


If you really like the list format that linalg[eigenvectors] generated, then you can obtain it from LinearAlgebra:-Eigenvectors using its output=list option.

altnew := Eigenvectors(T, output = list)


I'll apply the simplification of the eigenvectors to this format as well.

subsindets(altnew, Vector, proc (v) options operator, arrow; map(`@`(`@`(simplify, expand), rationalize), v) end proc)

[[1020, 1, {Vector[column](%id = 18446884131349960934)}], [1000, 2, {Vector[column](%id = 18446884131349961174), Vector[column](%id = 18446884131349961414)}], [10*10405^(1/2), 1, {Vector[column](%id = 18446884131349961654)}], [-10*10405^(1/2), 1, {Vector[column](%id = 18446884131349961894)}], [0, 1, {Vector[column](%id = 18446884131349962134)}], [510+100*26^(1/2), 1, {Vector[column](%id = 18446884131349962374)}], [510-100*26^(1/2), 1, {Vector[column](%id = 18446884131349962614)}]]

``

``


Download Method-two_1.mw

[edited] Since the rosser Matrix is sometimes used as a classic stress test of floating-point eigen-solvers here is another attachment with floating-point results added. I show (at Digits:=15 to compare linalg results with default double-precision LinearAlgebra results and Matlab) results for linalg, and LinearAlgebra both with and without the input being qualified by shape=symmetric.

Method-two_2.mw

Is that an errant multiplication symbol (centre dot) between Read and the opening round bracket? I mean in the 2D Input line near the bottom of your own code (after the restart). It looks like the Read didn't happen because it was accidentally entered as multipication.  (The blue output supports this view.)

The (**) is the start and finish of a multiline comment. You can start a comment with (* and finish it with *). 

I've seen some people set the prompt string from ">" to "(**)" so that they can cut and paste whole chunks from the Command-Line Interface into either the Standard GUI or the CLI. That allows them to run the code without having to delete the prompts. It looks like the CodeBuilder's help page might have all its red Execution Group statements done that way.

restart;

P:=proc(p) add((1/k^(1/10))*sin(1/k), k=1..10^p); end proc:

seq( evalhf(P(i)), i = 1 .. 5 ); # note that convergence is slow

2.49191306935046653, 4.08921936410845444, 5.38401710176055026, 6.41458705039817367, 7.23336277159380270

restart;

S:=Sum((1/k^(1/10))*sin(1/k), k=1..infinity);

Sum(sin(1/k)/k^(1/10), k = 1 .. infinity)

st:=time[real]():

evalf(S); # Maple has its own tools to figure this out quickly

time[real]()-st;

10.39563885

0.31e-1

# Your instructor wants you to understand a trick,
# that this slowly converging sum can be split into two
# parts: one with quicker convergence and one which can be
# quickly handled symbolically (exactly).
#
# So then you only need to take a moderate number of terms
# for the first part, and do a fast float approximation of the
# second part.

Q:=Sum(1/k^(1/10)*(sin(1/k)-1/k),k=1..n)+Sum(1/k^(11/10),k=1..n);

combine(Q); # note that this is the original goal

Sum((sin(1/k)-1/k)/k^(1/10), k = 1 .. n)+Sum(1/k^(11/10), k = 1 .. n)

Sum(sin(1/k)/k^(1/10), k = 1 .. n)

# This computes the first part of Q, to a finite number of terms.

G:=proc(p) add(1/k^(1/10)*(sin(1/k)-1/k),k=1..10^p); end proc:

seq( evalhf(G(i)), i = 1 .. 6 ); # note the convergence

-.188242112012818291, -.188804659049917056, -.188809574592180229, -.188809614011275523, -.188809614324675301, -.188809614326387792

evalhf(G(6)) + value(Sum(1/k^(11/10),k=1..infinity));

evalf(%);
 

-.188809614326387792+Zeta(11/10)

10.39563885

 


Download sum_trick.mw

[edited] I should mention that the "trick" is not general purpose, and happens to work because of properties of this particular example. So one lesson is that thinking about a problem can sometimes lead to clever reformulation into an equivalent problem that is more easily handled.

This is a bug in the is command. It's surprising to me, because often is does well, yet for this example it produces a wrong result while several other commands get there.

Curiously, it seems to depend on the Pi, in particular.

restart;

 

ee:=exp(I*n*Pi)+exp(-I*n*Pi)=2*cos(Pi*n);

exp(I*n*Pi)+exp(-I*n*Pi) = 2*cos(n*Pi)

new:=(rhs-lhs)(ee)=0;

2*cos(n*Pi)-exp(I*n*Pi)-exp(-I*n*Pi) = 0

is(new); # hrrmm

false

simplify(new);

0 = 0

evalc(new);

0 = 0

convert(new,exp);

0 = 0

convert(new,trig);

0 = 0

alt:=subs(Pi=foo, ee);

exp(I*n*foo)+exp(-I*n*foo) = 2*cos(n*foo)

is( alt );

true

kernelopts(version);

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

 


Download is_weakness.mw

 

I usually call solve wrapped in square brackets. That makes the result a list of solutions. And then I can always use the indexing the same way, even if there is just one solution.

sol := [solve( ... )];

sol[1]; # first solution, whether there are more than one, or not

sol[i]; # ith solution

sol[1][j]; # jth element of first solution

sol[i][j];  # jth element of ith solution

One thing you can try is to force the alternate method=RC of RootFinding:-Isolate . Or you could try some other options to that command. Note that the problem of finding all roots of a system of polynomials with rational coefficients can be hard.

In Maple you can view the interpreted Library source using commands like showstat command. For example,

showstat(RootFinding::Isolate);
showstat(fgbrs::rs_isolate_sys);
showstat(fgbrs::rs_isolate_gb); 
showstat(fgbrs::rs_rur_sys);

The RS method of RootFinding:-Isolate makes calls to compiled libraries of the FGb and RS applications. It looks like it might be possible to utilize the 3rd party RS compiler libraries without a Maple interface layer, but I have no experience in doing so.

The RC method of RootFinding:-Isolate makes use of the RegularChains package (of which major portions are also in compiled libraries). See also the 3rd party homepage of the RegularChains project. I am not sure how easy it might be (if even possible) to utilize the compiled library portions without the Maple Library interface layer.

I don't think that you'd have joy trying to use these projects stand-alone outside Maple, unless you really enjoy programming riddles.

It might be that either of those 3rd party packages (including Maple full or partial interfaces) has a later version than what is shipped with your Maple version (even if current 2017.3). Even if true I don't know what compatibility issues might arise. It might not even be the case.

 

 

The global name can be accessed as :-x which distinguishes it from a local or parameter by the same name.

Below I throw single right quotes (a,k.a. uneval quotes) around it, because it's a good habit to protect such references against the case that the global name has been assigned a value (which is why mint complains). But for your example you can use :-x instead of ':-x' if you really want to.

test:=proc(function,{x::range:=0..1})
  plot(function,':-x'=x);
end proc:

test( sin(x) );

test( sin(x), x=2..4 );

IMO it's not great programming practice to restrict a procedure to work only for expressions that depend upon one particular name. Better would be to pass in the dependent name, or have the procedure figure it out, or pass in both name and range as an optional positional parameter.

Here are two possibilities (for Maple 2015 through 2017). One scheme incorporates the open brackets that Maple used in version 18 and earlier. The other scheme keeps the new, unfenced pretty-printing but applies a color.

Let me know if things like copy&paste work. The context-menu "Units formatting" may not allow changing the "system", but does seem OK with specific unit replacement (eg. N to replace m*kg/s^2).

Note that this only affects output. The behaviour of 2D Input (including use of the Units palette) appears the same.

Since Mapleprimes currently uses an old worksheet renderer (Maplenet?) the display below shows the older open brackets around the two schemes' outputs as well as for the default output of the initial statements executed before I redefine the print extension. (eg. for scheme 1 there are nested brackets.) I'm inlining the attachment here in this Answer anyway. In the Maple Standard GUI those extra open brackets don't appear in the output.

restart;

kernelopts(version);

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

45*K*Unit(m*kg/s^2)+3*Unit(cm*kg/sec^2);

45*K*Units:-Unit(m*kg/s^2)+3*Units:-Unit(cm*kg/s^2)

Unit(m*kg/s^2);

Units:-Unit(m*kg/s^2)

# Scheme 1, using the open brackets of previous releases.
`print/Unit` := proc()
    local Unit;
    if IsWorksheetInterface('Standard')
     or _EnvInRecursiveUnitsModulePrint = true then
       if member(convert(kernelopts(':-version'),string)[1..10],
                 ["Maple 2015","Maple 2016","Maple 2017"]) then
          Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mo("&lobrk;"),
                               Typesetting:-Typeset(Typesetting:-EV(args)),
                               Typesetting:-mo("&robrk;"),
                               Typesetting:-msemantics = "Unit"),
                               ':-open' = "&lobrk;", ':-close' = "&robrk;",
                               Typesetting:-msemantics = "Unit");
       else
          Unit(args);
       end if;
    else
       Unit([args]);
    end if;
end proc:

Unit(m*kg/s^2);

Units:-Unit(m*kg/s^2)

simplify(%);

Units:-Unit(N)

45*K*Unit(m*kg/s^2)+3*Unit(cm*kg/sec^2);

45*K*Units:-Unit(m*kg/s^2)+3*Units:-Unit(cm*kg/s^2)

simplify(%);

(45*K+3/100)*Units:-Unit(N)

# scheme 2, using a color.
`print/Unit` := proc()
    local Unit, res;
    if IsWorksheetInterface('Standard')
     or _EnvInRecursiveUnitsModulePrint = true then
       if member(convert(kernelopts(':-version'),string)[1..10],
                 ["Maple 2015","Maple 2016","Maple 2017"]) then
          subsindets(Typesetting:-Typeset(Typesetting:-EV(:-Unit(args))),
                     specfunc(anything,{Typesetting:-mfrac,
                                        Typesetting:-mi,
                                        Typesetting:-mo}),
                     u->op(0,u)(op(u),mathcolor = "Green"));
       else
          Unit(args);
       end if;
    else
       Unit([args]);
    end if;
end proc:

45*K*Unit(m*kg/s^2)+3*Unit(cm*kg/sec^2);

45*K*Units:-Unit(m*kg/s^2)+3*Units:-Unit(cm*kg/s^2)

simplify(%);

(45*K+3/100)*Units:-Unit(N)

Unit(m*kg/s^2);

Units:-Unit(m*kg/s^2)

simplify(%);

Units:-Unit(N)

 

 

Download unit_print.mw

Please upload your worksheet using the green up-arrow in the Mapleprimes editor, instead of pasting in a screen-shot.

It's difficult to read your screen-shot image. But one thing that does stand out is that you're incorrectly using square brackets for grouping subexpressions. You need to use round brackets for that. (Square brackets are for creating lists.)

The assignments do succeed. They just don't print anything. If you want you can print something after the fact...

 

restart:

Games:= [[B1,A1], [A1,B2], [B1,A2], [A2,B2]]:

TBS:=seq(Tab[op(indets(Games))[i]]
         =Record(numwins=0,numlost=0,wins=table([]),losses=table([])),
         i=1..nops(indets(Games))):

seq(assign(TBS[j]),j=1..nops(indets(Games))); # no output.

seq(print(evaln(Tab[i])=Tab[i]), i=indets(Games,name));

Tab[A1] = Record(numwins = 0, numlost = 0, wins = (table( [ ] )), losses = false)

Tab[A2] = Record(numwins = 0, numlost = 0, wins = (table( [ ] )), losses = false)

Tab[B1] = Record(numwins = 0, numlost = 0, wins = (table( [ ] )), losses = false)

Tab[B2] = Record(numwins = 0, numlost = 0, wins = (table( [ ] )), losses = false)

``

Download assignation_1.mw

Could you not use colon-equals assignment within a loop? That too is "programmatic". Is there a reason you prefer the functional style here?

Whether the 2D Input

   d := "hello"

echoes (in the output region) only the result or the whole assignment statement is behavior that varies according to a few things.

It varies according to whether interface(typesetting) is set to `extended` or `standard`.

It can also vary according to whether you are in an Execution Group (in a Worksheet say) or a Document-Block (in a Document).

I think it only makes sense to compare the same cases between versions.

Note the the default typesetting level changed from standard to extended, between Maple 2016 and 2017.

What major and minor versions are you using, precisely? Which typesetting level in each?

See the Grid package.

You could also look at the Threads package (but I suspect that it will not be suitable, if your computations involve code the is not thread-safe).

There is an undocumented export Hyperlink of the DocumentTools:-Layout subpackage.

You cannot get a hyperlink in regular printed output, but you can include it in embedded content.

hyperlink_embed.mw

With an explicit expression (formula) for the individual terms you can do symbolic summation using the sum command. For your example the summation can be computed to a closed-form expression formula, whose exact limit can then be taken, as Kitonum has shown.

But with a procedure that only computes the addition of a particular number of terms the limit command will not see any formula and so exact computation of the limit cannot be done. The procedure is then a black-box, as far as the limit command is concerned.

With such a procedure it is still possible to compute the limit to a non-exact floating-point value, by using a command that numerically computes the addition of various finite numbers of terms and then determines whether those results converge.

restart;

 

p:=proc(n)
  local i,su;
  su:=0;
  for i from 1 to n do
    su := su+(2*i/n)*(2/n);
  end do;
  return su;
end proc:

p(1), p(2), p(3), p(4);

4, 3, 8/3, 5/2

limit(p(n), n=infinity);

Error, (in p) final value in for loop must be numeric or character

 

That error occurs because the p(n) is evaluated prematurely. That is to say, before
the limit command gets to work Maple first evaluated the first argument. We can
see in the next statement that itself is producing the error.

 

p(n);

Error, (in p) final value in for loop must be numeric or character

 

We can guard against such premature evaluation by delaying evaluation (of that
first argument passed to limit) through use of single right-quotes (unevaluation quotes).

 

'p'(n); # returns unevaluated

p(n)

limit('p'(n), n=infinity);

limit(p(n), n = infinity)

evalf(limit('p'(n), n=infinity));

2.000000000

Limit('p'(n), n=infinity);

Limit(p(n), n = infinity)

evalf(Limit('p'(n), n=infinity));

2.000000000

 

Another way to prevent that premature evaluation is to construct the procedure so
that it returns unevaluated if its own argument is not of the appropriate type.

 

p:=proc(n)
  local i,su;
  if not type(n,posint) then
     return 'procname'(args);
  end if;
  su:=0;
  for i from 1 to n do
    su := su+(2*i/n)*(2/n);
  end do;
  return su;
end proc:

p(1), p(2), p(3), p(4);

4, 3, 8/3, 5/2

p(n); # returns unevaluated

p(n)

limit(p(n), n=infinity);

limit(p(n), n = infinity)

evalf(limit(p(n), n=infinity));

2.000000000

 


Download evalf_limit.mw

First 188 189 190 191 192 193 194 Last Page 190 of 336