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

You need to substitute a procedure (colloquially called a function) for x[1] rather than substituting an expression for x[1](whatever). Like this:

eval(junk, x[1]= ((a,b,c)-> R(b,c)*sin(omega*a + phi(b,c))));

Always use eval for these high-level calculus substitutions. Using subs isn't necessarily wrong, but eval is safer. The use of subs should be reserved for low-level purely syntactic substitutions.

I am highly skeptical of Kitonum's Answer. I don't doubt the computed critical value of D(theta)(0)---I got the same value. But I do doubt the solution curves. And I doubt the existence of a finite T such that theta(T) = Pi and D(theta)(T) = 0. My intuition is that diff(theta(t), t) (for t > 0) is a strictly positive, strictly decreasing function whose limit at infinity is 0.

Here are some computations to support these hypotheses:

restart:

I simplified your ODE. I hope that you'll agree that my form is equivalent.

ODE:= diff(theta(t),t$2) = sin(theta(t))*(cos(theta(t))-9.81);

diff(diff(theta(t), t), t) = sin(theta(t))*(cos(theta(t))-9.81)

The following dsolve solves the problem as a BVP. The value of the upper boundary T is up to you. As you make it higher, eventually either the BVP solver will give up, or you'll run out of patience waiting for it to finish.

T:= 9:

sol:= dsolve(
     {ODE, theta(0) = 2*Pi/3, theta(T) = Pi},
     numeric,
     abserr= 1e-9, maxmesh= 2^9
):

plots:-odeplot(
     sol, [[t,theta(t)-Pi], [t,diff(theta(t),t)]], 0..T,
     color= [red,blue], gridlines= false
);

Is theta'(T) = 0?

eval(diff(theta(t),t), sol(T));

HFloat(9.886613896682558e-13)

What is D(theta)(0)?

DTZ:= eval(diff(theta(t),t), sol(0));

HFloat(3.2496153618561823)

Now solve as an IVP using the high-accuracy taylorseries method.

sol2:= dsolve(
     {ODE, theta(0) = 2*Pi/3, D(theta)(0) = DTZ},
     numeric, method= taylorseries,
     abserr= 1e-9
):

My intuition is that the blue curve going negative simply represents the point where the Taylor series expansion is no longer accurate. If I ask for more accuracy, this point moves to the right.

plots:-odeplot(
     sol2, [[t,theta(t)-Pi], [t,diff(theta(t),t)]], 0..T,
     color= [red,blue], gridlines= false
);

 

 

 

Download Highly_unstable_ODE.mw

In general, there's no way to do it. But many builtin (or kernel) functions come from open-source libraries. For example, reading the code for isprime, one sees that it uses (for some inputs) gmp_isprime. That's part of the GMP open-source library. So, if you Google "gmp isprime", you'll quickly find that code in C.

How about saving everything to one .mla file?

save H||(1..n), "H.mla";

I just read your other Question, regarding Grid, and I now realize that you probably really need nine separate files. That can be done for the kth file by

save cat(H,k), sprintf("H%d.mla", k);

By the way, you may be confusing things by calling these .mla files. Use another extension. If you use .m, the files will be compressed into Maple's own text-based but not-human-readable format, which'll probably save an iota of time.

That needs to use nested seqs:

seq(seq([A[i],B[j]], i= 1..5), j= 1..4);

or

seq(seq([A[i],B[j]], j= 1..4), i= 1..5);

A better way, which doesn't require hardcoding the list sizes, is

seq(seq([i,j], j= B), i= A);

A method that works for an arbitrary list of lists L, each of arbitrary length, is

L:= [A,B]:
CP:= combinat:-cartprod(L):
'CP[nextvalue]()' $ mul(nops~(L));

 

You can't assign to a procedure's parameter, n in this case. You need to copy the parameter to a local variable, and then assign to that.  Like this:

cs:= proc(N::posint)::nonnegint;
description "Find the number of steps for a Collatz sequence to reach 1.";
local n::posint:= N, q::posint, r::identical(0,1), count::nonnegint;
     for count from 0 while n > 1 do
          q:= iquo(n, 2, 'r');
          n:= `if`(r=0, q, 3*n+1)
     end do;
     count
end proc:

Also, your count was off by one to my mind: cs(1) should be 0.

The properties (in the strict Maple sense of "properties") of an object can be inquired with the about command; however, this is only useful if you've used the assume command, which is the command which gives objects properties.

Somewhat similar to properties are attributes, which can be inquired with attributes. An object will only have attributes if you give it attributes with setattribute. You can give attributes whatever meaning you want.

To see all subexpressions of an expression e, use indets(e, anything). The anything can be replaced with any type expression (in the strict Maple sense of "type" (see ?type)). For example, all the integrals in e can be found with indets(e, specfunc({Int,int})). This makes indets one of the most useful and most commonly used commands.

To have e broken down into a logical (but not visual) tree which includes the smallest detail of information, use ToInert(e). This is often too much information to wade through by reading; however, this information can be manipulated programmatically. Some of this information may be arranged in a logical fashion that doesn't exactly correspond to the internal representation of the object, but does correspond to the logical representation of the object.

To have e broken down into a more-visual tree, but which uses some more-cryptic abbreviations, use dismantle(e). This information, as far as I know, corresponds precisely to the internal representation. This information is quite difficult to manipulate programmatically.

Ultimately, everything in a computer is stored as numbers. If you really want to go down to that level, use disassemble(addressof(e)). This will break it down one tree level only. Each given number can be broken down further with disassemble if it's an address. It's a good idea to follow the dismantle tree when you are doing this.

You should put your Maple version in the header of your Question. There's check-off boxes and a pull-down menu for it.

Your zero-one Matrix can be created like this:

n:= 4:
subsMatrix:= <seq(x[], x= Iterator:-CartesianProduct([0,1]$n))>;

Your list of substitution equations can be created directly from the iterator like this:

A:= [seq(a[i], i= 1..n)]:
subsEqs:= [seq(
     select(e-> rhs(e)=0, A=~ convert(x[], list)),
     x= Iterator:-CartesianProduct([0,1]$n)
)];

So note that there's no need to create the subsMatrix if its only purpose was to be an intermediary for the creation of the subsEqs.

Your error? It's probably that you need to say LinearAlgebra:-RowDimension rather than simply RowDimension and likewise for ColumnDimension.

The Iterator package comes with Maple 2016. If you have older Maple, let me know.

In bcs, you need to put parentheses around f1 in the first boundary condition and around f3 in the fourth boundary condition.

The command indets(sys2 union {bcs11} union bcs, name) can be used to find such problems. It this case, it told me that D was being considered a name (as well as an operator).

You asked:

How can I see the order of vertices of square? Because, perhaps you sorted....

Kitonum's code maintains the four vertices of each square as a set, and all the squares themselves are in a set. Sets in Maple are sorted into stored in an order determined by Maple (mostly lexicographic order). To maintain the order of the vertices within the squares, it's necessary to store the squares as lists instead of sets. This causes duplicate squares, so they need to be divided into equivalence classes by their equality as sets, and have a representative of each equivalence class selected. A command that can form equivalence classes is ListTools:-Classify.

Here's a procedure that does this for any sphere with integer center and radius. This is based on Kitonum's code but is generalised to work for any sphere with integer center coordinates and radius. It takes significantly more time because of the equivalence class finding. The coding is more complex due to the many subtle list-set-table conversions required.

restart:


#Returns all squares on the sphere with center C and radius R such that all coordinates are
#distinct integers.

AllDistinctIntegerSquares:= proc(C::[integer,integer,integer], R::posint)
uses LT= ListTools, J= Iterator;
local S, L, s, p, V, X, c;
     for s in
          combinat:-choose(
               select(
                    X-> add((X-~C)^~2) = R^2,
                    {seq(
                         convert(X[], list),
                         X= J:-CartesianProduct(seq([$ map2(`+`, c, -R..R)], c= C))
                    )}
               ),
               3
          )
     do
          for p in combinat:-permute(s) do
               V:= map(`-`, p[2..3], p[1]);
               if inner(V[]) = 0 and `=`((add@`^`~)~(V,2)[]) then
                    L[p[1], p[2], p[2]+V[2], p[3]]:= ();
                    break
               end if
          end do
     end do;
     map(
          s-> s[1],
          {entries(
                LT:-Classify(l-> {l[]}, select(p-> nops({op~(p)[]})=12, [indices(L)])),
                nolist
          )}
     )
end proc:


AllDistinctIntegerSquares([2,4,6], 15);

{[[-12, -1, 4], [-9, 14, 8], [0, 9, 20], [-3, -6, 16]], [[-12, -1, 8], [-9, 14, 4], [0, 9, -8], [-3, -6, -4]], [[-12, -1, 8], [-8, 14, 11], [4, 9, 20], [0, -6, 17]], [[-12, 2, 1], [-9, 6, 16], [0, 18, 11], [-3, 14, -4]], [[-12, 2, 1], [-8, -1, 16], [4, -10, 11], [0, -7, -4]], [[-12, 2, 11], [-9, 6, -4], [0, 18, 1], [-3, 14, 16]], [[-12, 2, 11], [-8, -1, -4], [4, -10, 1], [0, -7, 16]], [[-12, 6, 1], [-9, 2, 16], [0, -10, 11], [-3, -6, -4]], [[-12, 6, 1], [-8, 9, 16], [4, 18, 11], [0, 15, -4]], [[-12, 6, 11], [-9, 2, -4], [0, -10, 1], [-3, -6, 16]], [[-12, 6, 11], [-8, 9, -4], [4, 18, 1], [0, 15, 16]], [[-12, 9, 4], [-9, -6, 8], [0, -1, 20], [-3, 14, 16]], [[-12, 9, 8], [-9, -6, 4], [0, -1, -8], [-3, 14, -4]], [[-12, 9, 8], [-8, -6, 11], [4, -1, 20], [0, 14, 17]], [[-9, 2, -4], [0, -10, 11], [13, 6, 16], [4, 18, 1]], [[-9, 2, 16], [0, -10, 1], [13, 6, -4], [4, 18, 11]], [[-9, 6, -4], [0, 18, 11], [13, 2, 16], [4, -10, 1]], [[-9, 6, 16], [0, 18, 1], [13, 2, -4], [4, -10, 11]], [[-8, -7, 8], [-3, 2, 20], [12, -1, 16], [7, -10, 4]], [[-8, -6, 11], [-3, 6, 20], [12, 2, 17], [7, -10, 8]], [[-8, -1, -4], [-3, 18, 4], [12, 9, 16], [7, -10, 8]], [[-8, -1, -4], [0, 18, 1], [12, 9, 16], [4, -10, 11]], [[-8, -1, 16], [-3, -10, 4], [12, -7, 8], [7, 2, 20]], [[-8, -1, 16], [-3, 18, 8], [12, 9, -4], [7, -10, 4]], [[-8, -1, 16], [0, 18, 11], [12, 9, -4], [4, -10, 1]], [[-8, 2, -5], [-3, 18, 8], [12, 6, 17], [7, -10, 4]], [[-8, 2, 17], [-3, -10, 8], [12, -6, 11], [7, 6, 20]], [[-8, 2, 17], [-3, 18, 4], [12, 6, -5], [7, -10, 8]], [[-8, 6, -5], [-3, -10, 8], [12, 2, 17], [7, 18, 4]], [[-8, 6, 17], [-3, -10, 4], [12, 2, -5], [7, 18, 8]], [[-8, 6, 17], [-3, 18, 8], [12, 14, 11], [7, 2, 20]], [[-8, 9, -4], [-3, -10, 4], [12, -1, 16], [7, 18, 8]], [[-8, 9, -4], [0, -10, 1], [12, -1, 16], [4, 18, 11]], [[-8, 9, 16], [-3, -10, 8], [12, -1, -4], [7, 18, 4]], [[-8, 9, 16], [-3, 18, 4], [12, 15, 8], [7, 6, 20]], [[-8, 9, 16], [0, -10, 11], [12, -1, -4], [4, 18, 1]], [[-8, 14, 11], [-3, 2, 20], [12, 6, 17], [7, 18, 8]], [[-8, 15, 8], [-3, 6, 20], [12, 9, 16], [7, 18, 4]], [[0, -1, 20], [4, 14, 17], [16, 9, 8], [12, -6, 11]], [[0, 9, 20], [4, -6, 17], [16, -1, 8], [12, 14, 11]]}

 

 

Download AllDistinctIntegerSquares.mw

I can get Maple to put it into the following relatively simple Sum form, which is not as simple as the one shown in the paper. Note that the only difference in the input is that I used Sum with an uppercase S. That's the inert form of sum, but diff still knows what to do with it.

The following commands have inert forms that the other commands know how to handle. In all cases, the inert form is the same word capitalized: sumproductdiff, int, eval, limit.

w:= Sum(Sum(f*sin(m*Pi*x/a)*sin(n*Pi*y/b), n = 1 .. l), m = 1 .. k):
w0:= Sum(Sum(f0*sin(m*Pi*x/a)*sin(n*Pi*y/b), n = 1 .. l), m = 1 .. k):


PPED:=
    E*h*(
         diff(w,x,y)^2 - diff(w,x,x)*diff(w,y,y) -
         diff(w0,x,y)^2 + diff(w0,x,x)*(diff(w0,y,y))
    )
;

E*h*((Sum(Sum(f*m*Pi^2*cos(m*Pi*x/a)*n*cos(n*Pi*y/b)/(a*b), n = 1 .. l), m = 1 .. k))^2-(Sum(Sum(-f*m^2*Pi^2*sin(m*Pi*x/a)*sin(n*Pi*y/b)/a^2, n = 1 .. l), m = 1 .. k))*(Sum(Sum(-f*sin(m*Pi*x/a)*n^2*Pi^2*sin(n*Pi*y/b)/b^2, n = 1 .. l), m = 1 .. k))-(Sum(Sum(f0*m*Pi^2*cos(m*Pi*x/a)*n*cos(n*Pi*y/b)/(a*b), n = 1 .. l), m = 1 .. k))^2+(Sum(Sum(-f0*m^2*Pi^2*sin(m*Pi*x/a)*sin(n*Pi*y/b)/a^2, n = 1 .. l), m = 1 .. k))*(Sum(Sum(-f0*sin(m*Pi*x/a)*n^2*Pi^2*sin(n*Pi*y/b)/b^2, n = 1 .. l), m = 1 .. k)))

simplify(%);

E*h*Pi^4*((Sum(m*cos(m*Pi*y/b), m = 1 .. l))^2*(Sum(m*cos(m*Pi*x/a), m = 1 .. k))^2-(Sum(sin(m*Pi*y/b), m = 1 .. l))*(Sum(m^2*sin(m*Pi*x/a), m = 1 .. k))*(Sum(sin(m*Pi*x/a), m = 1 .. k))*(Sum(m^2*sin(m*Pi*y/b), m = 1 .. l)))*(f^2-f0^2)/(a^2*b^2)

 

 

Download diff_double_sum.mw

Note that the formulae that you entered aren't quite as general as those in the paper. In the paper, the sums have coefficients that depend on n and m.

Is this what you're looking for?

linspace:= proc(r::range(complexcons), n::posint)

local a:= op(1,r), h:= (op(2,r)-a)/n, k;
     [seq(a+k*h, k= 0..n)]
end proc:

linspace(0..1., 4);

     [0., .250000000000000, .500000000000000, .750000000000000, 1.00000000000000]

The name linspace comes from a very similar function in Matlab.

Why not simply have a variable, Nlists, that you add 1 to every time you find a list?

Nlists:= Nlists + 1;

Since your task seems so large (you mentioned 11 trillion lists in another Questions), you should describe it in more detail so that we can discuss its feasibility. Perhaps there is already a combinatorial formula to count it. Perhaps your lists could be generated by the Iterator or combstructs package. Note that you can't fit 11 trillion lists on even a large disk. You'll need to use an iterator of some sort. That is, the lists need to be created, examined, counted, and garbage collected in a loop. Maple will handle the garbage collection on its own.

The bottom of your Question is about the data structure that you should use. I think that a DataFrame would be good for this. A DataFrame is like a Matrix except that the rows and columns are indexed by labels rather than by numbers. I think that your columns should be labeled by weather phenomena and the rows should be labeled by date and hour. See ?DataFrame.

There are no functional differences. If there were, we'd occasionally have to ask people when they asked Questions here what edition they had so that we could answer. That has never happened as far as I'm aware. In Maple V (about 15 years ago), there was a small difference in the student edition: Precision was limited to 100 digits. I'm not aware of any differences after that.

First 215 216 217 218 219 220 221 Last Page 217 of 395