Carl Love

Carl Love

28055 Reputation

25 Badges

12 years, 357 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

The coefficients of all the extraneous terms are relatively small. The relative error is ~ 1e-6 (just eyeballing it) over a small range of sigma2. However, it's true that an extra-degree term will ultimately cause unlimited error.  I'm working on some precise error computations, presented in a worksheet below.

The method used for the original determinant is unifloat. (So note that your guess that it was Gaussian elimination was incorrect.) The method used for Axel's method is fracfree. The details of each method that I summarize below can be viewed by setting infolevel[all]:= 5 before doing the computation.

Using the unifloat method, it first determines that the maximum possible degree of the determinant is 9. This estimate is very reasonable based on the maximum degree in every row and column. Both rowwise and columnwise estimates are 9 (as can be seen by inspection). Then it evaluates the matrix's floating-point determinant at 10 points and computes the interpolating polynomial. This method is nearly guaranteed to give you a dense degee-9 polynomial when done with floating-point arithmetic.

The fracfree method proceeds by relatively straightforward fraction-free Gaussian elimination. "Fraction-free" in this context means that no rational functions are used; it doesn't mean that integer coefficients are used.

Here's a worksheet showing the relative errors of the two methods.

restart:

macro(LA= LinearAlgebra):

infolevel[all]:= 5:

A:= <
     180*sigma2^2, -17980.4676072929*sigma2, 60*sigma2^2,
          -1792.74593023400*sigma2, -597.004097753022*sigma2, -60*sigma2;
     -17980.4676072929*sigma2, 60*sigma2^2, -17980.4676072929*sigma2,
          -597.004097753022*sigma2, -597.581976744666*sigma2, 5993.48920243096;
     60*sigma2^2, -17980.4676072929*sigma2, 180*sigma2^2,
          -597.581976744666*sigma2, -1791.01229325907*sigma2, -60*sigma2;
     -1792.74593023400*sigma2, -597.004097753022*sigma2, -597.581976744666*sigma2,
          -60*sigma2, 5993.48920243096, 597.581976744666;
     -597.004097753022*sigma2, -597.581976744666*sigma2, -1791.01229325907*sigma2,
          5993.48920243096, -60*sigma2, 597.004097753022;
     -60*sigma2, 5993.48920243096, -60*sigma2,
          597.581976744666, 597.004097753022, 60
>;

A := Matrix(6, 6, {(1, 1) = 180*sigma2^2, (1, 2) = -17980.4676072929*sigma2, (1, 3) = 60*sigma2^2, (1, 4) = -1792.74593023400*sigma2, (1, 5) = -597.004097753022*sigma2, (1, 6) = -60*sigma2, (2, 1) = -17980.4676072929*sigma2, (2, 2) = 60*sigma2^2, (2, 3) = -17980.4676072929*sigma2, (2, 4) = -597.004097753022*sigma2, (2, 5) = -597.581976744666*sigma2, (2, 6) = 5993.48920243096, (3, 1) = 60*sigma2^2, (3, 2) = -17980.4676072929*sigma2, (3, 3) = 180*sigma2^2, (3, 4) = -597.581976744666*sigma2, (3, 5) = -1791.01229325907*sigma2, (3, 6) = -60*sigma2, (4, 1) = -1792.74593023400*sigma2, (4, 2) = -597.004097753022*sigma2, (4, 3) = -597.581976744666*sigma2, (4, 4) = -60*sigma2, (4, 5) = 5993.48920243096, (4, 6) = 597.581976744666, (5, 1) = -597.004097753022*sigma2, (5, 2) = -597.581976744666*sigma2, (5, 3) = -1791.01229325907*sigma2, (5, 4) = 5993.48920243096, (5, 5) = -60*sigma2, (5, 6) = 597.004097753022, (6, 1) = -60*sigma2, (6, 2) = 5993.48920243096, (6, 3) = -60*sigma2, (6, 4) = 597.581976744666, (6, 5) = 597.004097753022, (6, 6) = 60})

gc():

P[unifloat]:= CodeTools:-Usage(LA:-Determinant(A)):

IndexList: initializing external call for IndexList

IndexList: external IndexList call successfully initialized
ComputeConnect: initializing external call for ComputeConnect
ComputeConnect: external ComputeConnect call successfully initialized
StronglyConnectedBlocks: Decomposed into blocks of sizes  [6]
Determinant/unifloat: dimension is 6 domain is R[sigma2] evaluation/interpolation requires 9 determinants over R
Determinant/unifloat: R[sigma2]: proceeding with determinant 1
Determinant/float: calling external function
Determinant: NAG hw_f07arf
Determinant/unifloat: R[sigma2]: proceeding with determinant 2
Determinant/float: calling external function
Determinant: NAG hw_f07arf
Determinant/unifloat: R[sigma2]: proceeding with determinant 3
Determinant/float: calling external function
Determinant: NAG hw_f07arf
Determinant/unifloat: R[sigma2]: proceeding with determinant 4
Determinant/float: calling external function
Determinant: NAG hw_f07arf
Determinant/unifloat: R[sigma2]: proceeding with determinant 5
Determinant/float: calling external function
Determinant: NAG hw_f07arf
Determinant/unifloat: R[sigma2]: proceeding with determinant 6
Determinant/float: calling external function
Determinant: NAG hw_f07arf
Determinant/unifloat: R[sigma2]: proceeding with determinant 7
Determinant/float: calling external function
Determinant: NAG hw_f07arf
Determinant/unifloat: R[sigma2]: proceeding with determinant 8
Determinant/float: calling external function
Determinant: NAG hw_f07arf
Determinant/unifloat: R[sigma2]: proceeding with determinant 9
Determinant/float: calling external function
Determinant: NAG hw_f07arf
Determinant/unifloat: R[sigma2]: proceeding with determinant 10
Determinant/float: calling external function
Determinant: NAG hw_f07arf
subtype: TESTING: anything <<< nonreal
subtype: AFTER SIMPLIFICATION: anything <<< nonreal
memory used=1.58MiB, alloc change=0 bytes, cpu time=15.00ms, real time=61.00ms, gc time=0ns

gc():

P[fracfree]:= CodeTools:-Usage(LA:-Determinant(convert(A, rational, exact))):

StronglyConnectedBlocks: Decomposed into blocks of sizes  [6]

Determinant/fracfree: gaussian elimination
Determinant/fracfree: elimination at row 1
Determinant/fracfree: pivot selected -60*sigma2
Determinant/fracfree: elimination at row 2
Determinant/fracfree: pivot selected (3/2500000000)*sigma2^2
Determinant/fracfree: elimination at row 3
Determinant/fracfree: pivot selected (2697070141093941/31250000)*sigma2^4
Determinant/fracfree: elimination at row 4
Determinant/fracfree: pivot selected (2689118895350997/312500000000000000000)*sigma2^5+(640658284733379319059892072243256671367577/156250000000000000000000000000000)*sigma2^4
Determinant/fracfree: elimination at row 5
Determinant/fracfree: pivot selected -(4854726253969069605731308228221/15625000000000000000)*sigma2^6-(57732251822958065318061323918368069370263980820815882906453/312500000000000000000000000000000000000000000)*sigma2^5-(85818076159321533072130690706468745958854769498084423957090495217670196273/3125000000000000000000000000000000000000000000000000000000)*sigma2^4
memory used=351.55KiB, alloc change=0 bytes, cpu time=0ns, real time=37.00ms, gc time=0ns

infolevel[all]:= 0:

P[fracfree]:= evalf(P[fracfree]):

R:= LA:-RandomVector(99, generator= -2.0..2.0):

d[e]:= map(r-> LA:-Determinant(eval(A, sigma2= r)), R):

d[u]:= map(r-> eval(P[unifloat], sigma2= r), R):

d[ff]:= map(r-> eval(P[fracfree], sigma2= r), R):

So, over the 99 evaluation points, the maximum relative error of the unifloat method is

LA:-Norm((d[e] -~ d[u]) /~ d[e], infinity);

HFloat(1.083377744650285e-6)

(That's amazingly close to my "eyeballing" estimate of 1e-6.)

And the maximum relative error of the fracfree method is

LA:-Norm((d[e] -~ d[ff]) /~ d[e], infinity);

HFloat(1.6430641959088563e-14)

Considering these errors and the time and memory used for each determinant computation, the convert(..., rational, exact) method is the clear winner for a 6x6 univariate polynomial matrix, but the default method isn't grossly erroneous or ineffcient either.

 

Download poly_det_error.mw

plots:-implicitplot3d(
     (x-y)^2+(x-z)^2+(z-x)^2=3, x= -2..2, y= -2..2, z= -2..2,
     grid= [20$3], style= surface
);

Here is the solution. If you had Maple 2016, I would've used a DataFrame rather than a Matrix for the final output. That would make it eaier to read with column and row labels.

restart:

macro(ST= StringTools, PD= StringTools:-PatternDictionary, LT= ListTools, St= Statistics):
bid:= PD:-Create(ospd3):
words:= select(
     w-> ST:-AndMap(ST:-IsAlpha, w), #Remove words with non-alpha characters.
     [seq(ST:-UpperCase(PD:-Get(bid,i)), i= 1..PD:-Size(bid) - 1)]
):

nops(words);

80458

L:= sort~((St:-Tally@op~@[op])~(LT:-Classify(nops, ST:-Explode~(words))), key= -rhs):

c:= max(indices(Data, nolist));

39

interface(rtablesize= max(26, c)):

Matrix(
     (26,c),
     (i,j)-> `if`(assigned(L[j]) and nops(L[j]) >= i, convert(parse(lhs(L[j][i])), `local`), ``)
);

Matrix([[I, A, A, A, E, E, E, E, E, E, E, E, E, E, E, I, I, E, E, E, E, E, A, E, I, E, I, A, ``, ``, E, ``, I, ``, ``, O, ``, I, I], [A, I, E, E, A, A, A, A, A, I, I, I, I, I, I, E, T, I, O, O, R, O, N, I, E, I, A, I, ``, ``, O, ``, T, ``, ``, T, ``, T, T], [``, O, O, O, S, S, S, S, I, A, T, A, O, R, T, N, E, O, N, A, O, A, I, R, A, N, E, L, ``, ``, R, ``, A, ``, ``, I, ``, A, A], [``, E, I, S, O, R, I, I, T, O, R, T, T, O, R, T, N, T, T, I, I, L, E, T, O, S, O, E, ``, ``, T, ``, L, ``, ``, M, ``, L, E], [``, M, T, L, R, I, R, R, R, T, A, R, R, T, O, O, R, L, A, N, P, R, T, L, N, L, L, O, ``, ``, F, ``, E, ``, ``, E, ``, E, R], [``, N, N, I, L, O, O, O, O, R, O, O, A, A, N, R, A, R, R, L, S, T, L, C, T, O, R, R, ``, ``, N, ``, O, ``, ``, N, ``, M, S], [``, T, S, R, I, L, N, N, N, N, N, N, N, N, A, S, O, S, I, R, A, P, R, P, R, G, N, T, ``, ``, D, ``, R, ``, ``, A, ``, O, L], [``, S, P, N, N, N, L, L, S, S, S, S, S, S, S, A, D, N, L, T, C, C, S, U, M, X, T, P, ``, ``, I, ``, U, ``, ``, L, ``, R, O], [``, D, D, T, T, D, T, T, L, L, C, C, C, C, C, C, M, A, D, D, T, I, O, S, L, T, M, S, ``, ``, A, ``, D, ``, ``, P, ``, U, P], [``, C, U, D, D, T, D, C, C, C, L, L, P, L, L, L, C, H, P, M, N, N, M, A, U, F, P, M, ``, ``, M, ``, M, ``, ``, X, ``, D, U], [``, R, M, U, C, C, C, D, U, U, P, P, L, P, U, P, P, C, S, S, L, M, C, M, P, D, C, U, ``, ``, L, ``, P, ``, ``, C, ``, P, D], [``, U, R, M, U, U, U, U, D, P, M, M, M, M, P, U, S, P, M, W, H, H, F, V, S, A, F, N, ``, ``, U, ``, B, ``, ``, R, ``, B, M], [``, W, B, P, M, M, G, M, M, M, U, U, U, U, M, G, L, D, C, C, U, Y, U, Y, Y, ``, U, V, ``, ``, Q, ``, N, ``, ``, B, ``, N, B], [``, F, L, B, P, G, M, G, P, D, H, H, H, H, H, D, G, G, V, G, M, U, G, H, D, ``, D, Y, ``, ``, X, ``, S, ``, ``, J, ``, S, N], [``, P, G, C, Y, P, P, P, H, H, D, D, D, D, B, H, U, U, G, P, W, V, P, ``, V, ``, V, ``, ``, ``, C, ``, V, ``, ``, Y, ``, V, V], [``, L, C, H, B, B, B, B, G, G, B, G, G, B, G, M, H, F, U, U, G, X, Y, ``, Q, ``, Y, ``, ``, ``, P, ``, Y, ``, ``, ``, ``, Y, Y], [``, H, H, G, H, H, H, H, B, B, G, B, Y, Y, D, Y, F, M, X, V, V, G, X, ``, F, ``, B, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``], [``, B, F, K, G, Y, F, F, Y, Y, Y, Y, B, G, V, X, V, B, F, Y, ``, B, B, ``, Z, ``, K, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``], [``, Y, Y, F, K, F, Y, Y, F, V, F, F, F, F, Y, F, X, Y, B, H, ``, S, D, ``, H, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``], [``, G, W, Y, F, K, K, K, W, F, V, V, V, V, J, B, W, Q, Y, F, ``, D, H, ``, W, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``], [``, K, K, W, W, W, W, V, K, W, K, K, K, X, F, W, B, X, Q, B, ``, ``, ``, ``, C, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``], [``, V, V, V, V, V, V, W, V, K, W, X, W, W, W, Q, Z, W, ``, K, ``, ``, ``, ``, B, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``], [``, X, X, J, J, Z, Z, Z, X, X, X, W, Q, K, Q, V, J, V, ``, Q, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``], [``, J, J, Z, Z, J, J, X, Z, Q, Q, Q, X, Z, X, K, Y, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``], [``, Z, Z, X, X, X, X, J, Q, J, Z, Z, Z, Q, K, J, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``], [``, Q, Q, Q, Q, Q, Q, Q, J, Z, J, J, J, ``, Z, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``]])

All the numeric data is stored in L:

LTT:= table~(L):

LTT[7]["E"];

14338

So there 14,338 Es in seven-letter words.

``


Download length_by_letter.mw

Another way, if you have trouble remembering the @:

evalf(Int(x-> h(g(x)), x= 1..2);

Using unapply with quotes on its first argument is pointless (and slightly wasteful). You could just as well define g via

g:= a-> fsolve(a*y^2 - sin(y), y=2);

So, I wonder where this post that recommends unapply is so that I can go correct it.

Here's another way:

plot([<x|y_1>, <x|y_2>], style= point, symbolsize= 24, symbol= [cross,box]);

To compute n-norm where n = 1 or 2, use

evalf(Int(abs(x(t - 2*Pi) - x(t))^n, t= a..b)^(1/n));

To compute the infinity norm, use

numapprox:-infnorm(x(t - 2*Pi) - x(t), t= a..b);

In either case, make sure to choose a and appropriately. In the piecewise problem in the worksheet, for the infinity norm use

numapprox:-infnorm(eval(F, t= t- 2*Pi) - F, t= op([1,1,1], F)+2*Pi..op([-2,-1,-1], F));

     1.21380938300497*10^(-7)

Operands (op): Here's an abbreviated version of your piecewise:

F:=
piecewise(                                                                                                                         #op([0], F)

     5.442116637 <= t and t <= 8.035505284,                                                         #op([1], F)
     20.20246287+6.560150625*t-.5000000000*t^2-1.500000000*cos(t),   #op([2], F)
     8.035505284 <= t and t <= 8.583709290,                                                         #op([3], F)
     .4977821578                                                                                                               #op([4], F)

):
So op([1], F) is the conjunction 5.442116637 <= t and t <= 8.035505284. Negative numbers count back from the end so op([-2], F) = op([3], F) 8.035505284 <= t and t <= 8.583709290. Now I explode the first conjunction to see what the suboperands are:

5.442116637 <= t     #op([1,1], F)
and                                #op([1,0], F)
t <= 8.035505284     #op([1,2], F)


Note that the main operator in any expression is its zeroeth operand regardless of whether it occurs at the beginning (as does piecewise) or in the middle (as does and). Now I explode the first inequality to see what its suboperands are:

5.442116637   #op([1,1,1], F)
<=                      #op([1,1,0], F)
t                          #op([1,1,2], F)

All the above information about operands applies to any (unevaluated) function, not just piecewise.

In the fourth equation, c is being used as a function applied to the expression in parentheses to its right. To avoid this, you need a space or an explicit multiplication operator (*) between the c and the following left parenthesis.

It's not an error, but your logp and logd are treated as independent constants. If you intend for these to be log(p) and log(d), then you need to enter them like that, with the parentheses.

Good Question. Vote up.

I recommend that you use command plot rather than odeplot for this purpose. The command plot uses an adaptive sampling scheme to avoid lacunarity, whereas odeplot is only controlling for numeric error (using dsolve's error-control parameters) rather than appearance. Here's an example:

randomize(7): #To select a specific example.
ODEsys:= {
     diff(y(t),t$2) = randpoly([sin(t), diff(y(t),[t$k]) $ k= 0..1], degree= 2),
     ((D@@k)(y)(0) = 'rand(-99..99)()') $ k= 0..1
}:
Sol:= dsolve(ODEsys, numeric, range= 0..2*Pi, maxfun= 10^5, output= listprocedure):
plot(eval([y(t), diff(y(t),t)], Sol), 0..2*Pi, numpoints= 10^3, adaptive= 6);
data:= [plottools:-getdata(%)]:
M||(1..2):= data[k][-1] $ k = 1..2;

Fear not: The solution procedures in Sol are still controlling for numeric error to the same extent that they are when using odeplot. The adaptive scheme used by plot means that at least numpoints points will be used. As a last resort, you can use plot's sample option to add some more points in trouble spots. It's very rare that you'd need to do that.

 

You have too many square brackets in your input of A. It should be like this:

A:=Matrix([[1/sqrt(2), 0],[0, 1/sqrt(2)]]);

or, even simpler,

A:= <1/sqrt(2), 0; 0, 1/sqrt(2)>;

The shoot package isn't a part of standard Maple. It's a third-party package that you need to find and download. Maple can usually solve BVPs by other means.

I told you not to transcribe the output or command prompts into your messages. Do you have a problem with that?

I'm not sure what you mean by "get", "answer", or by the 0 in your print command. You can "get" a plot by replacing the print command with

plot([seq(X2||k, k= 1..1)], 0..blt);

Is that what you want?

Note that X2 by itself means nothing; it always needs to be (X2 || something).

Unless you can correctly format the output, please don't copy the output to your posts. And skip the command prompts ("> ") also. It's easier for us to read and to use if you just give the raw input.

 

c = ln((1+sqrt(5))/2), exactly.

Proof: Let S[n] denote the set whose cardinality you've denoted as A[n]. Then S[n+1] = S[n] union {all members of S[n] that we're allowed to add n+1 to} = S[n] union (S[n-1] union~ {n+1}). The outer union is disjoint because no member of S[n] contains n+1. Thus A[n+1] = A[n] + A[n-1]. It is well known that the asymptotic ratio of successive terms of this recursive sequence is (1+sqrt(5))/2 regardless of initial conditions, but I can give a more-detailed proof if you want.

P.S.: Some Maple code:

S[-1]:= {{}}:  S[0]:= {{}}:
for n to 22 do
     S[n]:= S[n-1] union map(`union`, S[n-2], {n})
od:
seq(nops(S[n]), n= 0..22);

     1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368

Maple won't allow the union~ that I used in the exposition because ~ can't be used between container objects of different sizes; so I needed to use map(`union`, ...) instead.

I can't verify that this will work without seeing your function. Let's say that the function is f(x). Try

simplify(expand(f(x+2*Pi) - f(x)));

If you get back 0, you can consider that to be a verification that the function is 2*Pi periodic. If you don't get back 0, try making some assumptions on x, such as 

simplify(expand(f(x+2*Pi) - f(x))) assuming x >= a, x <= c;

where c is some critical point between a and b, then

simplify(expand(f(x+2*Pi) - f(x))) assuming x >= c, x <= b;

I don't know how to address your more-general question: How to find a period of a function.

First, don't use . for multiplication; use * instead.

N:= 4;
y:= sum(A[2*n]*cos(2*n*x), n= 0..N);
eq1:= diff(y,x,x)+(a+2*q*cos(2*x))*y;
eq2:= map(combine, eq1, trig);
eq4:= map(collect, [coeffs(eq2, [seq(cos(2*n*x), n= 1..N+1)])], [seq(A[2*n], n= 0..N)]) =~ 0;

     [a*A[0]+q*A[2] = 0, (a-4)*A[2]+2*q*A[0]+q*A[4] = 0, q*A[2]+(a-16)*A[4]+q*A[6] = 0,
     q*A[4]+(a-36)*A[6]+q*A[8] = 0, q*A[6]+(a-64)*A[8] = 0, q*A[8] = 0]

Note that there's a cos(10*x) term and that the coefficient of 1 is always returned by coeffs.

I haven't tested the crashing aspect yet because obviously your int should be Int, and (not so obviously) the eval(...) right before the end do should be evalf(eval(...)). Make those changes and you'll get numeric answers immediately.

I don't see what thread safety has to do with it. This is not parallel processing code.

First 209 210 211 212 213 214 215 Last Page 211 of 395