Carl Love

Carl Love

28035 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

Suppose that p is a univariate polynomial, and that you want to plot the complex roots of p of modulus less than 1. Then do

plot(
   [Re,Im]~(select(x-> abs(x) < 1, [fsolve(p, complex)])),
   style= point, symbol= solidcircle, symbolsize= 18, scaling= constrained
);

If p is something other than a univariate polynomial, then more-sophisticated steps are required for the solving, but the selecting and plotting are the same.

I don't know why you're having trouble implementing Kitonum's Answer. Here's a different way using eval instead of subs. Create a list (not a vector) of the symbolic variables in the matrix:

X:= [x1, x2];

That part only needs to be done once. Then for each evaluation that you want using the values from vector x, do

eval(hf, X =~ seq(a, a= x));

Thank for providing the extra infomation that the error does not occur when you initialize N[i] to []. Now I am sure that you're dealing with a bug in Maple's 2D Input. The bug is that when certain expressions such as N[i] evaluate to NULL in 2D Input, it's as if they weren't there at all. So your statement

N[i]:= N[i], Data[i,j][4];

is passed to the parser as

N[i]:= , Data[i,j][4];

which, of course, has an unexpected comma.

The best thing that you can do is simply not use 2D input. Maple's 2D input is a completely unredeemable piece of garbage that's riddled with bugs like this.

But you can also change it to this, which is a much more efficient way to write it anyway:

for i to 2 do 
   N[i]:= seq(Data[i,j][4], j= 1..8) 
end do:

Now you don't need to initialize N[i].

The other Answers are great, but to Answer your Question directly:

You need to use = rather than := to set up equations. Like this

Eq1:=  x = y/p:
Eq1:=  z = x*a+y*(1-b):
Eq1:=  x = 100*z/(p*r+r);

There is never a situation where one would put a free symbolic variable (such as a variable which is to be "solved for") on both the left side and right sides of assignment operators (:=). Doing so causes "recursive assignment".

The following method is similar to Kitonum's, but it'll work in 1D input, so that you can easily edit the results. Like Kitonum's method, you must be prepared to follow Maple's own indentation and spacing style. Here's my procedure:

Indent:= (P::procedure)-> 
   map2(
      printf,
      "%s\n",
      map(
         s-> `if`(s[1]= " ", s[5..], s),
         StringTools:-Split(debugopts(procdump= P), `\n`)[..-2]
      )
   )[]
:

Now apply that to your procedure; for example, using Kitonum's example procedure,

Indent(PrimeTwins);

PrimeTwins := proc(N)
local n, a, b, L;
   n := 0;
   a := 2;
   do
     b := nextprime(a);
     if b-a <= 2 then
       n := 1+n;
       L[n] := [a, b];
       a := b
     else
       a := b
     end if;
     if n = N then
       break
     end if
   end do;
   convert(L,list)
end proc

Now copy-and-paste the output to a 1D Input (aka Maple Input) region, a Code Edit Region, or an external text editor.

All that being said, I strongly prefer to simply indent my code with the space bar as I am entering it.

Put your cursor in the cell (or paragraph or execution group or output region) that you want to delete and press Ctrl-Delete. It  doesn't matter whether or not the cell is empty.

Actually, in Maple you can usually do away with do-nothing or pass-along parameters such as the u and v in your Question. Then the issue raised by Tom is less of an issue. The following produces identical final results to all of the previous Answers:

g:= alpha*beta:
h:= alpha+beta:
f:= D[1](g)*h:
f(u,v);

The u and v in the final line are arguments, not parameters. (Roughly speaking, they are "global" and not "local"---but arguments and parameters are the precise terms.)

The lines where you defined m and n have not been executed because you didn't press Enter after entering them.

Your PLOT commands work in this case, but like Rouben says, it'd be better to use display or plots:-display. PLOT (all uppercase letters) is an expert-level command. This is not to be confused with plot (all lowercase letters), which is a regular command.

The problem is that rational is both a type and a proper property. By proper, I mean that it has its own definition as a property independent of its definition as a type. Properties are about the mathematical natures of abstract objects; whereas types are about the internal structures of actual objects exactly as they are stored in Maple's memory.

  • Your command is(.5, rational) is using rational as a property. It correctly states that the mathematical object .5 is a rational number, using the usual mathematical definition of such.
  • Your command type(.5, rational) is using rational as a type (the type command can only be used with types). It correctly states that .5 is not stored in a format using the Maple-specific definition of  rational (which is specifically an integer or a fraction, the latter being specifically a pair of integers (with common factors removed) combined with a tag (or 0th operand) "Fraction").
  • Your command is([.5], list(rational)) is using list(rational) as a type, and hence using rational as a type.
  • Your command is(sin(1)^2 + cos(1)^2, rational) incorrectly returns false. This is a bug---is should at least try a simplify before reaching a conclusion.

Acer said in a recent related thread that all types were valid properties. I don't fully agree with that. It's true in the sense that all commands that expect a property will (unfortunately) accept a type instead---at least all that I've checked. But the commands is, coulditbe, etc., can't do anything interesting with those unless they are proper properties.

 

You need to change the last line from

end do;

to

end do:

I can do it in under 7 seconds, using a completely different algorithm:

restart:
gc():
st:= time():
n:= 6:
N:= [$1..n]:
Sn:= combinat:-permute(n):
Id:= Matrix((n$2), (i,j)-> `if`(i=j, 1, 0)):
MF:= {seq(Id+Id[d,..], d= remove(p-> ormap(evalb, p =~ N), Sn))}:
MA:= {seq(seq(convert(M[p,..], listlist), M= MF), p= Sn)}:
Ones:= Matrix((n$2), fill= 1):
MA:= {seq(Ones - Matrix(M), M= MA)}:
time() - st;

The algorithm is

  1. Construct all permutations of [1..6].
  2. Select those permuations that are derangements.
  3. Construct all matrices of the form I+I[d], where I is the identity matrix and I[d] is the permutation matrix constructed from derangement d.
  4. Multiply every matrix by every permutation matrix. To save time, this is done with indexing rather than actual multiplication.
  5. Remove all duplicates from the list of matrices by converting to listlist form and using Maple's set constructor.
  6. Subtract each matrix from a matrix of ones.

On every system on which I've ever used Maple, the smallest reportable unit of computation time has been 1/64 of a second, which is about 16 milliseconds. I once saw a credible report of a system---Linux I believe---where the unit was 1/256 of a second.

To get accurate time measurements on a finer scale, you must do a large number of computations and average the time.

There's a difference between recursion and a recursive assignment. A recursive assignment is an assignment statement such as

x:= x + 1;

where x has not been initialized. Such an assignment is never allowed, whether it's in startup code or other code.

The Determinant command is part of a "package" that's not loaded when you initially load Maple. You simply need to do

with(LinearAlgebra):

in each session before using Determinant. An alternative is to use the package prefix whenever you use the command, as in LinearAlgebra:-Determinant(M). This can also be written LinearAlgebra[Determinant] (although there's a slight difference in the semantics). Finally, there's

use LinearAlgebra in Determinant(M) end use;

Of the four methods, I strongly prefer the second, LinearAlgebra:-Determinant, and I consider use of the others as substandard coding practices. Of the four, only the second unequivocally informs the reader that Determinant is a fixed identifier whose definition is hard coded in package LinearAlgebra. However, the with method is by far the most commonly used.


 

restart:

z:= x+y*I:

P||(1..3):= (1, z, 1+z^2):

P||(1..3):= (`<,>`@evalc@[Re,Im])~([P||(1..3)])[];

P1, P2, P3 := Vector(2, {(1) = 1, (2) = 0}), Vector(2, {(1) = x, (2) = y}), Vector(2, {(1) = x^2-y^2+1, (2) = 2*x*y})

(1)

The points are collinear (or aligned) if the direction vectors between any two distinct pairs are parallel. That corresponds to the following determinant being 0.

C:= LinearAlgebra:-Determinant(<P2-P1 | P3-P1 >);

x^2*y+y^3-2*x*y

(2)

algcurves[plot_real_curve](C, x, y, axes= boxed);

 

The blue part is the solution. Any three points on the real axis are collinear, so the solution obviously includes that. We guess that the rest of the solution is the circle of radius 1 centered at [1,0]. The following confirms that guess:

simplify(C, {(x-1)^2 + y^2 = 1});

0

(3)

 


 

Download Complex_locus.mw

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