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

If your expression for drag force is df, then all that you need is

Cd:= V-> df *~ V;

If you have more trouble, please post a Maple worksheet (not a .docx).

Whether you use a colon or a semicolon to terminate a statement in a loop makes no difference. The only one that matters is the one after the final end do.

The loop depth for which output is displayed is controlled by the environment variable printlevel. By default, this is set to 1, so only the output of unnested loops is displayed. If you increase it:

printlevel:= 2;

then the output of every command in your doubly nested loops will be shown. I strongly advise that you only use this technique for debugging because, in general, the volume of output will be overwhelming.

The proper way to display the output of commands within loops or other control structures is to use print. That is, for any X that you want displayed, use print(X).

To return the entry of minimal modulus in a single line of code, use

rts[min[index](abs~(rts))];

It is also possible (in a very short single line of code) to sort the entries by modulus. This is especially useful for lists of eigenvalues.

This can also be done with simplify with side relations:

sol:= dsolve({diff(y(t),t$2) + w^2*y(t) = p/m*exp(-a*t), y(0) = 0, D(y)(0) = 0}):
simplify(sol, {a= n*w, p= m*w^2*u});

 

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.
First 188 189 190 191 192 193 194 Last Page 190 of 395