Carl Love

Carl Love

28035 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

Here's a fully symbolic implementation. (This is the way that most predefined Maple functions work.) If the input is numeric, then it insists that the input be a nonzero integer, and it gives a definite result. If the input is symbolic the result depends on how much is known (or assumed) about the input. If the input can be proven to be an integer, but not proven to be even or odd, then a piecewise result is returned. If the input can be proven to be nonzero and either even or odd, then a single expression is returned. If the input can be proven non-integer, then undefined is returned. If the input can't be proven to be integer or proven to be non-integer, then an unevaluated result is returned.

a:= proc(n::And(algebraic, Not(identical(0))), $)
     if n::numeric then
          proc(n::integer) option procname; 1/`if`(n::odd, n, -n^2) end proc(n)
     elif is(n::integer) then
          piecewise(n=0, undefined, n::odd, 1/n, n::even, -1/n^2)
     elif not coulditbe(n::integer) then
          undefined
     else
          'procname'(n)     
     end if
end proc:

 

Your problem has nothing to do with exp. You're missing two multiplication signs in expression H41. Look for the places in the input expression where there should be centered dots signifying multiplication. Juxtaposition of groups in parentheses doesn't imply multiplication, it implies function application. Fix that and your equation will be solved immediately.

To find problems like this, use indets. In this case, I called the final expression e and used indets(e, function). It's also obvious (to the trained eye) that P1, Z, and Zbar are too close to their following left parentheses in the output expressions. It sticks out like a sore thumb once you're used to looking for it.

You're trying to use an equation label reference. I can't help you with that aspect except to say that you can't simply type the number "1" to get a reference to equation 1. But I can help you if you're willing to assign your equations to a name, like this:

Eqs:= diff(x(t),t) - diff(y(t),t) - y(t) = -exp(t), x(t) + diff(y(t),t) - y(t) = t^2 + exp(2*t);

Then it's simply

dsolve({Eqs});

Note the curly braces { } around Eqs.

When you want to transfer data from one Maple session to another (which could be in the same worksheet, in a different worksheet, or even on a different computer), the easiest thing to use is the save and read commands. It doesn't matter what the type of data is (Matrices, tables, records, simple numeric variables); the simple format of these commands remains identical. Let's say that you can assign your data to variables AB, and C. Then make up a file name like "MyData.txt" and, in worksheet 1, issue the command

save A, B, C, "MyData.txt":

In worksheet 2, issue the command

read "MyData.txt":

At that point, the variables A, B, and C will become defined in worksheet 2 with exactly the same values that they had at the point that they were saved in worksheet 1.

Please see the worksheet that I just posted in the Posts section: "Diminishing Returns from Parallel Processing." In that worksheet, I use many file transactions to communicate among several Maple sessions in one worksheet, separated by restart commands.

The first session creates a very large list of random input for a test and saves it to a file. It also creates a Maple program and writes it to a text file with the fprintf command. It then reads the text back in using the FileTools:-Text:-ReadLine command and prints it to the screen.

The second group of sessions perform the test. They use the read command to execute the program created in the first session. That program in turn uses read to get the random input data. A file which holds the tests results is opened in append mode, and the current test results (which are simply three numbers) are added as the last line of the file using the fprintf command with the %m format.

The final session analyzes the results of all the tests. It uses the fscanf command with the %m format in a while loop to read the test results into Vectors.

If you want to plot the positive roots of Q against so= 4..5, use plots:-implicitplot:

#Show some respect for your reader:  Use spaces and blank lines.
m1:= 5:  m2:= 2:  m3:= 1.5:  a1:= 0.16:  a2:= 0.45:  a3:= 0.833:  d1:= 0.25:  d2:= 0.1:  d3:= 0.075:
ys:= a3*d3/(m3-d3):
d:= 0.5:
w3:= d*(m1-d1):  
w2:= d*d1*so-d*m1*so-2*a1*d*d1+a1*d*m1-a2*m1^2+a2*d1*m1+m1*m2*ys:
w1:= 2*a1*d*d1*so-a1*d*m1*so-a1^2*d*d1+a1*a2*d1*m1+a1*m1*m2*ys:
w0:= a1^2*d*d1*so:   #Use `w0`, not `wo`.

#Use an expression Q, rather than a function Q(s).
#Q:= s-> w3*s^3+w2*s^2+w1*s+w0:
Q:= w3*s^3+w2*s^2+w1*s+w0:

plots:-implicitplot(Q=0, so= 4..5, s= 0..10, gridrefine= 3);

The upper limit of 10 for s was just a guess, which happened to work. Ordinarily, you may need to adjust that upper limit a few times to make sure that you're seeing all the positive roots.

I find the ColorTools package exceedingly clunky to work with. The design is poor; the APIs are inconsistent. So here is a better version of ColorTools:-RGB24ToName:

RGB24toName:=
     (RGB::And(list(nonnegint), satisfies(L-> nops(L)=3 and max(L) < 256)))->
          ColorTools:-NearestNamedColor(
               RGB, 'metric'= "RGB", 'number'= 1, 'palette'= "all", 'threshold'= 1/255
          )[1][1]
:

Example:

RGB24toName([179, 193, 16]);

     "Resene LaRioja"

I believe that there are some cases where the same triplet of numbers corresponds to two or more different named colors in different palettes. In those cases, my RGB24toName may not return the name that you are expecting.

NearestNamedColor seems exceedingly slow. If that's an issue, I think that I can rewrite it to be faster.

By the way, the mathematical term in English for what you call "reciprocal functions" is inverse functions.

I don't know what exactly has changed regarding writebytes since Maple 12, but it seems like using writebytes to open a file is crude and potentially dangerous. I'd use FileTools:-Text:-Open with its options create, overwrite, and append. It doesn't say at ?writebytes whether or not the I/O is buffered. If it's not buffered, then there's no point in using the command except for the lowest-level programming.

Before you try to use a file in another program, it should be closed by the program that's creating it. This is true in any computer language or system. That filepos happens to work in this case is a quirk and unreliable. Use FileTools:-Text:-Close or simply fclose.

You have at least eight small problems:

1. In the equation assigned to H, you need a multiplication operator immediately after Jx^2.

2. The syntax for the dsolve call should be

nsol:= dsolve({eqs[], ic[]}, numeric);

not

nsol:= dsolve(eqs, ic, numerical);

3. You have seven unknown functions and only six equations. The unknown functions are R, p1, p2, psi, r, theta, and varphi. I guess that r should be R. If I make this correction in equation V:=, it corrects the problem.

4. You have two initial conditions for theta(0). I guess that thetaini should be theta0.

5. You have no initial conditions for psi. I guess that should be psi(0) = psi0.

6. You should use the exp function rather than e. The latter is just considered an unknown variable name.

7. You used a lowercase j rather than an uppercase J in the second subs clause of statement Hyy:=.

8. There is still an unsubstituted Jx somewhere in the system. My guess is that that should be J*sin(psi(t))*cos(varphi(t)).

If I correct all these problems, then the dsolve command runs without error.

Add option complex to the fsolve command. Then the solution is returned almost instantly. By default, fsolve only looks for real solutions.

Suppose that we have a procedure

P:= proc(x) 2*x end proc:

Then, naturally, proc() 2*x end proc() means the same thing as P(). It's natural syntax that's often used to create and invoke an anonymous procedure in one step. The same thing works for procedures defined with the arrow:

(x-> 2*x)(y^2);

map(Limit, f(a+h) - f(a), h= 0);

The change that you noticed must be a bug. The documented changes to the package are listed at ?updates,Maple2016,Logic.

If you construct the matrix correctly, then Maple will know that it's symmetric, and it will make the eigenvalues real. Otherwise, you'll get very small imaginary parts that can be ignored or removed with Re. But it's better to avoid those in the first place.

Example:

restart:
G:= GraphTheory:-RandomGraphs:-RandomGraph(99, .1):
L:= GraphTheory:-LaplacianMatrix(G, datatype= float[8]):
E:= fnormal(LinearAlgebra:-Eigenvalues(L)):
(min,max)(E);

     -0., 20.0828010137594

 

Assuming that you have no interest in the generated file being human readable, then the easiest thing to do is to write and read the matrices in ".m" format. This is Maple's internal format. Essentially the only difference from what you have above is that the format code is %m rather than %a. This format can be used for any Maple data structure, not just matrices.

restart:

file:= FileTools:-Text:-Open(
     "c:/users/owner/desktop/TestMatrices.txt",
     create, overwrite, append
):

n:= 9:   #number  of matrices

for k to n do
     M:= LinearAlgebra:-RandomMatrix(3);
     fprintf(file, "%m\n", M)
end do:

FileTools:-Text:-Close(file);

 

Start a new session, which could be in a different worksheet or even via command-line Maple.

restart:

file:= FileTools:-Text:-Open(
     "c:/users/owner/desktop/TestMatrices.txt"
):

for k while not FileTools:-AtEndOfFile(file) do
     M:= fscanf(file, "%m\n")[];
     printf("%a=%d: %d\n", 'k', k, LinearAlgebra:-Determinant(M))
end do:

k=1: -327244

k=2: -307260
k=3: -570297
k=4: -74874
k=5: 627941
k=6: -821055
k=7: -32964
k=8: 83178
k=9: 441574

FileTools:-Text:-Close(file);

 

Download percent-m_format.mw

 

This is like Kitonum's procedure, but it only displays non-isomorphic graphs, except for n=4. For that n, there is a bug in GraphTheory:-IsIsomorphic. So, for n=4, the procedure displays all 64 "raw" graphs. This procedure takes about 4 minutes for n=6. I wouldn't recommend running it for n=7 or greater. Note that there are over 2 million raw graphs for n=7.

AllGraphs:= proc(n::posint)
uses C= combinat, GT= GraphTheory, LT= ListTools, P= plots;
local  
     Gs:= map2(GT:-Graph, n, [C:-powerset(C:-choose({$1..n},2))[]]),
     NP:= plot(()-> 0, -1..1, color= white, axes= none),
     ng, ns
;    
     if n <> 4 then
          Gs:= map(`?[]`, [LT:-Categorize(GT:-IsIsomorphic, Gs)], [1])
     end if;
     ng:= nops(Gs);
     ns:= ceil(evalf(sqrt(ng)));
     P:-display(Matrix(ns, [GT:-DrawGraph~(Gs, style= circle)[], NP $ ns^2-ng]))     
end proc;

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