Carl Love

Carl Love

28160 Reputation

25 Badges

14 years, 8 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

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);

While I applaud Mehdi's enthusiasm for some of the subtler details of indexing, I feel that his Answer suffers from "information overload" when one considers the level at which the Question was asked.

I think that this is the most natural way to create an 80-element column Vector of zeros:

V:= < [0$80] >:

See ?MVshortcuts and ?$ .

Common sense:

  1. Profit = Revenue - Cost  (money in - money out)
  2. Cost = Fixed cost + (cost per unit)*(units sold)
  3. Revenue = units sold * price

Units sold is however a function of price. But it helps here to express price as a function of units sold. Let p be price and x be units sold. The second to fourth sentences of the problem say that

p = 1400-20*(x-13)

Putting it together, we have

Profit = x*(1400 - 20*(x-13)) - (2000 + 1140*x)

limit(sum(1/(n+k), k= 1..n), n= infinity);
                             ln(2)

limit((n!)^(1/n)/n, n= infinity);
                            exp(-1)

d:= binomial(5,2):
mu:= add(min(pair), pair= combinat:-choose(5,2))/d;
                               2
var:= add((min(pair)-mu)^2, pair= combinat:-choose(5,2))/d;
                               1


You'll want the creation command for your Matrix to take account of the sparsity pattern, so use LinearAlgebra:-BandMatrix, like this:

macro(LA= LinearAlgebra):
d:= [$1..80]:
M:= LA:-BandMatrix(
     [(d/4)[5..80], [0$77], (d/2)[3..80], [0$79], 2*d, [0$79], (d/2)[1..78], [0$77], (d/4)[1..76]],
     datatype= float[8]
):

The command that you want is cat, short for "concatenate":

A:= 45:  ExportMatrix(cat("MIN", A, ".txt"), MINM):

You can also use sprintf, short for "string print formatted":

ExportMatrix(sprintf("MIN%d.txt", A), MINM):

First 349 350 351 352 353 354 355 Last Page 351 of 396