acer

32333 Reputation

29 Badges

19 years, 326 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

If you change that to Shutdown("0") then the return value wil be the string "0" upon Cancel (and, as you've implemented the other button, a list containing the selected filename string otherwise).

Assign the return value directly to say f1, and leave indexing into it until after you've tested whether it is "0".

You can just check evalb(f1="0") and then return/break/next/stop/end/etc as you wish. If it isn't then you can index into it like f1[1], etc, to get at the filename.

You can use subsindets and type anyfunc or type specfunc to find and act directly upon (ie. freeze) all those subexpressions which you don't want to be combined.

For example, excluding any function of alpha or beta,

thaw(combine(subsindets( expr, anyfunc(identical(alpha,beta)), freeze)));

Or, restricting it to just a few particular functions such as any combination of sin or cos of alpha or beta,

thaw(combine(subsindets( expr, specfunc(identical(alpha,beta),{sin,cos}), freeze)));

For handling an explicit (and small, say) list of items to exclude the choice is a matter of personal preference, I'd say. I find that I usually reach for subsindets so that I have less editing to do if I want to switch from a fixed list to more encompassing type. For example, to work on expression expr,

L:=[cos(beta),sin(alpha)]:
thaw(combine(subs(((x->x)=freeze)~(L),expr)));
thaw(combine(eval(expr,((x->x)=freeze)~(L))));
thaw(combine(eval(expr,(x->x=freeze(x))~(L))));
thaw(combine(subsindets(expr,identical(op(L)),freeze)));

I pointed out a new bug in the parsing of 2D Input, new to Maple 2017, on Sept 7th, 2017 in another thread on Mapleprimes.

There is a new problem in that infix arithmetic operations are being parsed to prefix function calls. For your example done in 2D Input Maple compute the float reciprocal of the denominator first, and then multiplies the numerator by that preliminary result.

Of course, compared to using proper float division, that new behavior can violate the expected behavior of attaining no more then 0.6 ulps error for the atomic floating-point arithmetic operation.

I recall that the rules for when this happened for 2D Input infix arithmetic operations, or not, were all over the map.

I submitted at least two bug reports related to it, at that time. (The bug report submitted approximately Sept 7th did not make it to a fix for the 2017.3 point release of Oct 3rd.)

I'll note that your Question's input appears to be in 1D Notation input. But you also indicated that it made a difference whether you were in a Document of Worksheet. It may be that the disctinction occurs, say, between a Document Block and a plain Execution Group. It would help if you uploaded your document as an attachment rather than just inlining images input in your Comments.

If you are passing a list of expressions to plot then you can also pass a list for the legend option. Eg,

exprs:=[sin(x), cos(x), sqrt(x)*sin(x)];

plot(exprs, x=0..6, legend=exprs);
Here are a few different ways:

restart;

sys:={x^2 + y^2 + z^2 = 4, x + y + z = 0, x*sin(y*z) = -1}:


After inspecting the implicit plot (Kitonum's idea) we could call
fsolve using restricted ranges for y.

fsolve(sys, {x,y,z}, {y=0.8..1});

{x = -1.630958259, y = .8860579420, z = .7449003167}

fsolve(sys, {x,y,z}, {y=0..0.8});

{x = -1.630958259, y = .7449003167, z = .8860579420}

restart;

sys:={x^2 + y^2 + z^2 = 4, x + y + z = 0, x*sin(y*z) = -1}:


It turns out that fsolve (with its avoid option) can find two roots for
the restriction that comes from eliminating x.

T:=eliminate(sys,{x});

[{x = -y-z}, {-sin(y*z)*y-sin(y*z)*z+1, 2*y^2+2*y*z+2*z^2-4}]

S1:=fsolve(T[2], {y,z});
ans1:=S1 union eval(T[1],S1);

{y = .7449003167, z = .8860579420}

{x = -1.630958259, y = .7449003167, z = .8860579420}

S2:=fsolve(T[2], {y,z}, avoid={S1});
ans2:=S2 union eval(T[1],S2);

{y = .8860579420, z = .7449003167}

{x = -1.630958259, y = .8860579420, z = .7449003167}

kernelopts(version);

`Maple 2017.3, X86 64 LINUX, Sep 27 2017, Build ID 1265877`

 

Download sys_fsolve.mw

[edit] Having obtained a solution, there will be another with values for y and z interchanged (due to symmetry).

sys:={x^2 + y^2 + z^2 = 4, x + y + z = 0, x*sin(y*z) = -1}:

evalb( eval(sys, [y=z,z=y]) = sys );

                    true

So swapping values for y and z is another way to get a second solution.

One way (without re-doing your whole approach) is to use the select command to take only the real roots, before calling max.

In the attachment I've done that for all the solve calls (though some may not have needed it, returning purely real roots, according to the particular equations passed).

mathias_1_M18.mw

You don't need the assumption, for these to work. It is true for any n.

restart;

expr:=exp(-n*ln(2*Pi));

exp(-n*ln(2*Pi))

simplify(expr,exp) assuming n::nonnegint;

(2*Pi)^(-n)

restart;

assume(n >= 0, n::integer);

simplify(exp(-n*ln(2*Pi)), exp);

(2*Pi)^(-n)

 


Download simplify_exp.mw

This kind of call to simplify is called simplify with side-relations.

simplify( log[1/3](x)-log[sqrt(3)](x^2)+log[x](9), {log[3](x)=a} ) assuming x>0;

                      2
                  -5 a  + 2
                  ---------
                      a

That works in Maple 2015, 2016, and Maple 2017. In earlier versions it also needs a wrapping call to (at least) normal.

You need to figure out what you mean by raising to power 1/p, since the quantity that you're raising to that power may be negative.

You have at least these three choices of interpretation:
1) Using the principle pth root, you'll get nonzero imaginary results when the radicand is negative.
2) Using the surd concept (eg. after conversion of 1/p=1/0.15 to 1/p=20/3)
3) Using the absolute value of the integral.

We cannot tell you which interpretation you are looking for.

For 1) and 2) you'll need to specify a looser accuracy option on the numerical integration.

int_pthroot.mw

The Statistics:-Biplot command uses the plots:-arrow command, not the plottools:-arrow command.

So instead of options wb, wh, hh you could use options width, head_width, head_length, etc.

 

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

 

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