Carl Love

Carl Love

28085 Reputation

25 Badges

13 years, 98 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

It isn't exactly an issue of global vs. local. The issue is that assuming doesn't work on variables in procedures, even if they are global; but assume does work on them. It seems as though assuming was designed this way--the documentation at ?assuming,details does mention this property:

The assuming command does not scan Maple programs regarding the potential presence of assumed variables. To compute taking into account assumptions on variables found in the bodies of programs, use assume....

Perhaps someone else can comment on why it was designed this way.

Example:

restart:
f:= proc() global a; a end proc:
is(f()>0) assuming a>0;
                             false
assume(a>0);
is(f()>0);
                              true

 

 

 

 

 

 

 

There is no nontrivial solution to your equation. Your A has first row all zero. Thus, for any P, the [1,1] entry of A.P + P.A^%T will be 0. Thus it cannot equal your C, unless the scale factor is 0.

There's atomicweight for elements and atomicmass for isotopes. They are presented in kg by default. You can convert to amu:

macro(SC= ScientificConstants):
convert(SC:-GetValue(SC:-Element(oxygen, atomicweight)), units, kg, amu);
                        15.9994000000000

IsPrime:= proc(n) option cache; isprime(n) end proc:
APSearch:= proc()
     local SP:= 2, AD:= 210, n:= 7, k, S;
     do
          SP:= nextprime(SP);
          S:= SP + k*AD $ k = 1..n-1;
          if andmap(IsPrime, [S]) then
               return [SP, S]
          end if
     end do
end proc:     
APSearch();
              [47, 257, 467, 677, 887, 1097, 1307]

I put your data into a Matrix M with three columns. Then I gave the plot command

plot(
     [M[.., [1,2]], M[.., [1,3]]],
     labels= [time, `error`], legend= [error1, error2]
);

This command indicates a plot of two curves, the first being column 1 vs column 2 and the second being column 1 vs. column 3.

First, read the help page ?LinearAlgebra,General,LinearSolveItr .

To use conjugate gradient (without a preconditioner) to solve AX = b, do

infolevel[LinearAlgebra]:= 5:

X:= LinearAlgebra:-LinearSolve(
     A, b, method= SparseIterative, methodoptions= [itermethod= CG, precon= false]

);

To do preconditioned conjugate gradient, do the same, but leave off the precon= false. There are a number of other options, discussed on the help page, that you can set.

You can use a third argument to seq, the step increment:

seq(a[i], i= 3..1, -1)

The package Student is divided into subpackages: Calculus1, NumericalAnalysis, etc. You need to also load the subpackage with with:

with(Student):
with(Calculus1):

DiffTutor(exp(x^2));

There are arbitrarily long (but not infinitely long) arithmetic progressions of primes. This is the Green-Tao theorem, proved in 2004. See the Wikipedia article "Primes in arithmetic progression". For a progression of length greater than 6, you'll need the gap to be a multiple of 210 = 7*5*3*2.

I believe that what they intended is this:

MyString:= "bd847EK&#BJWbs287*&":
(uppers,lowers,digits,others):= ""$4:
for c in MyString do
     if c >= "A" and c <= "Z" then
          uppers:= cat(uppers, c)
     elif c >= "a" and c <= "z" then
          lowers:= cat(lowers, c)
     elif c >= "0" and c <= "9" then
          digits:= cat(digits, c)
     else
          others:= cat(others, c)
     end if
end do;
uppers, lowers, digits, others;

But you are correct that there is a way to do this without a loop. Note, though, that MyString can be arbitrarily mixed up.

You could use your own procedure instead of TangentLine, like this

restart:
with(VectorCalculus):
SetCoordinates( 'cartesian'[x,y,z] ):
MyTangentLine:= (V, Pt::(name=algebraic))->
    eval(V,Pt)+eval(VectorCalculus:-TangentVector(V),Pt)*op(1,Pt)
:
MyTangentLine( <sin(t)-t*cos(t), cos(t)+t*sin(t), t^2>, t= Pi/2);

It is fairly easy to modify combstruct[count] and combstruct[allstructs] so that they have they have the desired behaviour: that they accept a range for the size argument. Here's the code to do it.

restart:
unprotect(combstruct):
combstruct[count]:= overload([
     proc(S::anything, Sz::identical(size)=range(nonnegint))
          option overload;
          local k;
          add(combstruct[count](S, size= k), k= op(2,Sz))
     end proc,
     combstruct[count]
]):
combstruct[allstructs]:= overload([
     proc(S::anything, Sz::identical(size)=range(nonnegint))
          option overload;
          local k;
          {seq(combstruct[allstructs](S, size= k)[], k= op(2,Sz))}
     end proc,
     combstruct[allstructs]
]):
protect(combstruct):

Example of use:

with(combstruct):
allstructs(Combination(5), size= 1..2);
{{1}, {2}, {3}, {4}, {5}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {2, 3},
  {2, 4}, {2, 5}, {3, 4}, {3, 5}, {4, 5}}

count(Combination(5), size= 1..4);
                               30

To see all contexts,

op ~ (select(type, {Units:-GetUnits()}, indexed));

To see all the units for a given context, use this procedure:

UnitsOfContext:= c-> map2(op, 0, select(u-> u::indexed and op(u)=c, {Units:-GetUnits()})):

For example,

UnitsOfContext(troy);

There are several ways to do this problem that are more elegant than what I have below. However, I decided that you should see a straightforward approach first.

prod:= 1:  #Initialize accumulator variable.
for i to 100 do
     if isprime(i) then
          prod:= prod*sqrt(i)
     end if
end do:

prod;

Note that the print command in not an acceptable way to return results. You must be able to assign the results to a variable. Also note that it is not necessary to say isprime(i)=true; simply isprime(i) is enough.

Now here's a more elegant way:

sqrt(`*`(select(isprime, [$1..100])[]));


Like this:

restart:
test1r3 := (x,y)-> (1/2)*(-x+sqrt(x^2-4*y^2))/y:
n, N:= 100, 50:  # 50 frames, 100 points per frame
R:= evalf@RandomTools:-Generate(integer(range= 1..10), makeproc):
plots:-display([seq(plot([seq([k, test1r3(R(),R())], k= 1..n)], style= point), j= 1..N)], insequence);

First 348 349 350 351 352 353 354 Last Page 350 of 395