Carl Love

Carl Love

28025 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

If f and g are lists, then you may do, simply,

plot([f,g], style= point);

For f and g any indexed structures (list, array, table, sequence), you can do

plot([[seq(f[k], k= 1..10)], [seq(g[k], k= 1..10)]], style= point);

You may add nondefault colors, point shapes, and point sizes by using the options color, symbol, and symbolsize, respectively. For example,

plot([f,g], style= point, color= [green, red], symbol= [cross, diamond], symbolsize= 24);

Every occurence of c() in your code is a separate invocation (or call) of the random-number-generating procedure created by rand(0..1). If you need a stable value, then assign it to a variable (such as your d) and just use that variable.

It's impossible. Applying factor to the polynomial proves that it has no rational roots.

Try this. I've made several simplifications to your code.

restart:
X:= Vector([1, 2, 3, 4, 5, 6], datatype= float[8]):
Y:= Vector([2, 3, 4, 3.5, 5.8, 7], datatype= float[8]):

SLRrepeatedsample:= proc(X,Y,N,CI)
uses ArrayTools, Statistics, RandomTools;
local x, y, n, ymu, ySE, yvar, x2, b, bCI, i;
     n:= Size(X,1);
     b:= LinearFit([1,t], X, Y, t, output= parametervalues);
     ySE:= LinearFit([1,t], X, Y, t, output= residualstandarddeviation);
     x2:= X^~2;
     for i from 1 by 1 to N do
          x:= Generate(float(range= min(X)..max(X)));
          ymu:= b[1]+b[2]*x;
          ySE:= (1+1/n+sqrt(((x-Mean(X))^2)/(add(x2[j],j=1..n)-n*(Mean(X))^2)));
          yvar:= RandomVariable(Normal(ymu, ySE));
          y:= Sample(yvar, 1)[1];
          X(n+1):= x;
          x2:= X^~2;
          Y(n+1):= y;
          b:= LinearFit([1,t], X, Y, t, output= parametervalues);
          ySE:= LinearFit([1,t], X, Y, t, output= residualstandarddeviation);
          n:= Size(X, 1);
     od;
     bCI:= LinearFit([1, t], X, Y, t, confidencelevel= CI, output= confidenceintervals);
     return b, bCI;
end proc:

SLRrepeatedsample(X, Y, 2, .95);

For large A, it's much faster to compute the orbit without computing the powers of A. Also, this solution avoids the list-building-by-appending technique, which takes time O(n^2) where n is the list length.

Orbit:= proc(A::Matrix, V::Vector, n::nonnegint)
# returns [seq(A^k.V, k= 0..n)] without explicitly computing powers of A
local O:= Array(0..n, [V]), k;
     for k to n do O[k]:= A.O[k-1] end do;
     convert(O, list)
end proc:

If you want to apply it to a list of Vectors, use map2. I don't see any significant reason why returning a list of lists is better than returning a list of Vectors; plots:-pointplot will accept both.

Here's one way to do it. While building each A[k+1], I limit lookup access to A[k] to a procedure that traps index-out-of-bounds errors, which are diverted to value 0.

restart:
a:= 1:  b:= -1: #For example
N:= 100:
A:= Array(1..N):
AA:= proc(k,i,j) try A[k][i,j] catch: 0 end try end proc:
A[1]:= < < -1, 1 > | < 0, 1 > >:
for k to N-1 do
     A[k+1]:= Matrix(
          k+2, k+2,
          (i,j)-> a*(k+1)*AA(k,i,j) + b*((1+j)*AA(k,i-1,j) - j*AA(k, i-1, j-1))
     )
end do:    

You are making a mistake with your for-loop syntax. You have

for i= 1..r do ... end do;

but that should be

for i from 1 to r do ... end do;

You're not ruining my vacation. I love nothing more than showing people how to use my LogicProblem package, and I only worked on these at night when there wasn't anything local to do. Besides, I did most of this one while waiting for my flight in the San Jose, Costa Rica airport.

You made two mistakes in coding this problem (the "Meet the Challenge" or "Book Swap" problem). The first is that you need to make the surnames a separate variable. The second is that all of the constants' names need to be unique. So, even though the books brought are the same as the books borrowed, I make the names distinct by prepending br_ or bo_.

After defining the variables and constants thus, all of the constraints except #20 are straightforward equalities. #20 needs to be specified in a procedural form accepted by the package. I too tired right now to explain in detail how these procedures work, but I urge you to read my comments to the code of the package, especially the long comment preceding procedure `Know/Proc`.

Please make a separate thread for each new logic problem.

 

Solved 2014-Feb-17

restart:

"Book Swap" logic problem

Eight married couples meet to lend one another some books. Couples have the same surname, employment and car. Each couple has a favorite color. Furthermore we know the following facts:

 

1. Daniella Black and her husband work as Shop-Assistants.

2. The book "The Seadog" was brought by a couple who drive a Fiat and love the color red.

3. Owen and his wife Victoria like the color brown.

4. Stan Horricks and his wife Hannah like the color white.

5. Jenny Smith and her husband work as Warehouse Managers and they drive a Wartburg.

6. Monica and her husband Alexander borrowed the book "Grandfather Joseph".

7. Mathew and his wife like the color pink and brought the book "Mulatka Gabriela".

8. Irene and her husband Oto work as Accountants.

9. The book "We Were Five" was borrowed by a couple driving a Trabant.

10. The Cermaks are both Ticket-Collectors who brought the book "Shed Stoat".

11. Mr and Mrs Kuril are both Doctors who borrowed the book "Slovacko Judge".

12. Paul and his wife like the color green.

13. Veronica Dvorak and her husband like the color blue.

14. Rick and his wife brought the book "Slovacko Judge" and they drive a Ziguli.

15. One couple brought the book "Dame Commissar" and borrowed the book "Mulatka Gabriela".

16. The couple who drive a Dacia, love the color violet.

17. The couple who work as Teachers borrowed the book "Dame Commissar".

18. The couple who work as Agriculturalists drive a Moskvic.

19. Pamela and her husband drive a Renault and brought the book "Grandfather Joseph".

20. Pamela and her husband borrowed the book that Mr and Mrs Zajac brought.

21. Robert and his wife like the color yellow and borrowed the book "The Modern Comedy".

22. Mr and Mrs Swain work as Shoppers.

23. "The Modern Comedy" was brought by a couple driving a Skoda.

 

Who likes Violet? And can you find out everything about everyone from this?

 

Vars:= [Wife, Husband, Surname, Occupation, Car, Color, Brought, Borrowed]:

 

Wife:= [Daniella,Hannah,Jenny,Monica,Victoria,Irene,Veronica,Pamela]:

Husband:= [Stan,Owen,Alex,Mathew,Oto,Robert,Paul,Rick]:
Surname:= [Black, Kuril, Horricks, Smith, Cermak, Zajac, Swain, Dvorak]:
Occupation:= [shop,ware,acc,ticket,docs,teach,agri,shoppers]:

Car:= [fiat,wartburg,trabant,ziguli,moskvic,skoda,renault,dacia]:

Color:= [red,brown,white,pink,green,blue,violet,yellow]:

Books:= [mulatka, modern, dame, we, shed, seadog, grandfather, slovacko]:

Brought:= map2(cat, br_, Books);

[br_mulatka, br_modern, br_dame, br_we, br_shed, br_seadog, br_grandfather, br_slovacko]

Borrowed:= map2(cat, bo_, Books):

Con0:= (Brought <>~ Borrowed)[]:
Con1:= Daniella = Black, Black = shop:
Con2:= br_seadog = fiat, fiat = red:
Con3:= Owen = Victoria, Owen = brown:
Con4:= Stan = Horricks, Stan = Hannah, Stan = white:
Con5:= Jenny = Smith, Jenny = ware, Jenny = wartburg:
Con6:= Monica = Alex, Monica = bo_grandfather:
Con7:= Mathew = pink, pink = br_mulatka:
Con8:= Irene = Oto, Oto = acc:
Con9:= bo_we = trabant:
Con10:= Cermak = ticket, ticket = br_shed:
Con11:= Kuril = docs, docs = bo_slovacko:
Con12:= Paul = green:
Con13:= Veronica = Dvorak, Dvorak = blue:
Con14:= Rick = br_slovacko, Rick = ziguli:
Con15:= br_dame = bo_mulatka:
Con16:= dacia = violet:
Con17:= teach = bo_dame:
Con18:= agri = moskvic:
Con19:= Pamela = renault, Pamela = br_grandfather:

Constraint 20 is tricky. It means at least what I have below. The current version of my package does not directly handle relative dependent clauses ("that Mr and Mrs Zajac brought"). I am working on a version that does handle them. But the current version does handle any type of constraint that can be specified with a procedure in a certain format that I designed for the package. It is easier to write these procedures after the with of the module has been executed (so that you can use the module's methods in the procedure), so I defer the rest of the specification of Constraint 20 until then.

Con20:= Pamela <> Zajac:
Con21:= Robert = yellow, yellow = bo_modern:
Con22:= Swain = shoppers:
Con23:= br_modern = skoda:

read "C:/Users/Carl/desktop/logic_problems.mpl":

BookSwap:= LogicProblem(Vars):

with(BookSwap);

Warning, BookSwap is not a correctly formed package - option `package' is missing

[`&!!`, `&-`, `&<`, `&>`, `&?`, `&G`, `&Soln`, AutoGuess, CPV, CollectStats, ConstNum, Consts, ConstsInV, DifferentBlock, Equation, FreeGuess, GoBack, Guess, InternalRep, IsComplete, IsUnique, NC, NV, PrintConst, Quiet, Reinitialize, SameBlock, Satisfy, Separated, UniquenessProof, VarNum, VarNumC, X_O]

Con20:=
     Pamela <> Zajac,
     Proc(proc()
     local
          #"The book that Pamela borrowed."
          book1:= ConstNum(Pamela) &Soln VarNum(Borrowed),
          #"The book that the Zajacs brought."
          book2:= ConstNum(Zajac) &Soln VarNum(Brought)
     ;
          if book1 = 0 and book2 = 0 then #Nothing known yet
               false, false
          elif book1 > 0 and book2 = 0 then
               false, false, [Zajac = Consts[book1 - CPV]]
          elif book2 > 0 and book1 = 0 then
               false, false, [Pamela = Consts[book2 + CPV]]
          elif book1-CPV <> book2 then #Contradicts this constraint.
               true
          else #This constraint is already satisfied.
               false, true
          end if
     end proc, []):
      

Reinitialize();

Satisfy([Con||(0..23)]);

NULL

`Unique solution:`

Matrix(8, 8, {(1, 1) = Daniella, (1, 2) = Mathew, (1, 3) = Black, (1, 4) = shop, (1, 5) = trabant, (1, 6) = pink, (1, 7) = br_mulatka, (1, 8) = bo_we, (2, 1) = Hannah, (2, 2) = Stan, (2, 3) = Horricks, (2, 4) = agri, (2, 5) = moskvic, (2, 6) = white, (2, 7) = br_dame, (2, 8) = bo_mulatka, (3, 1) = Jenny, (3, 2) = Robert, (3, 3) = Smith, (3, 4) = ware, (3, 5) = wartburg, (3, 6) = yellow, (3, 7) = br_we, (3, 8) = bo_modern, (4, 1) = Monica, (4, 2) = Alex, (4, 3) = Cermak, (4, 4) = ticket, (4, 5) = dacia, (4, 6) = violet, (4, 7) = br_shed, (4, 8) = bo_grandfather, (5, 1) = Victoria, (5, 2) = Owen, (5, 3) = Kuril, (5, 4) = docs, (5, 5) = skoda, (5, 6) = brown, (5, 7) = br_modern, (5, 8) = bo_slovacko, (6, 1) = Irene, (6, 2) = Oto, (6, 3) = Zajac, (6, 4) = acc, (6, 5) = fiat, (6, 6) = red, (6, 7) = br_seadog, (6, 8) = bo_shed, (7, 1) = Veronica, (7, 2) = Rick, (7, 3) = Dvorak, (7, 4) = teach, (7, 5) = ziguli, (7, 6) = blue, (7, 7) = br_slovacko, (7, 8) = bo_dame, (8, 1) = Pamela, (8, 2) = Paul, (8, 3) = Swain, (8, 4) = shoppers, (8, 5) = renault, (8, 6) = green, (8, 7) = br_grandfather, (8, 8) = bo_seadog})

 

Download BookSwap_LP.mw

If you try to pass a sequence to convert it mistakes that as mulitple arguments, which it doesn't know how to handle. It is easier to work with lists than sequences.

a:= [seq(taylor(cos(x),x=0,i),i=[2,4,6])]:
convert(a, polynom);

The soccer problem is very easy with my LogicProblem package because all of the constraints translate directly to equalities and inequalities.  Your file did not attach, so I can't see what you did wrong.

 

Solved 2014-Feb-15 from Puerto Viejo de Talamanca, Limon, Costa Rica by Carl Love

 

restart:

Soccer Logic Problem

 

There are 7 boys on a soccer team. Each boy has a different position, jersey number, and height. Find out each person's height, position, and number.

 

* Justin is the goalie

* The right forward is #10

* The goalie is 6' 4''

* Joe is 6' 1''

* Ryan is right forward

* The person next to Ryan is #14

* The person who is 6' 4'' is #16

* #10 is 5' 8''

* The left forward is #15

* Brad is right defense

* Brendan is #20

* Michael is 7' 1''

* Miguel is #6

* Michael is left forward

* #42 is right defense

* Brad is 6' 2''

* #6 is center defense

* #15 is 7' 1''

* #20 is 6' 7''

* Miguel is 5' 10''

* #14 is 6' 1''

* The person who is 6' 7'' is left defense

* Joe is center forward

 

Vars:= [Name,Pos,Number,Height]:

Name:= [justin, joe, ryan, brad, brendan, michael, miguel]:

Pos:= [goalie, rt_for, lt_for, rt_def, cen_def, lt_def, cen_for]:

Number:= [10, 14, 16, 15, 20, 6, 42]:

Height:= [`5'8"`, `5'10"`, `6'1"`, `6'2"`, `6'4"`, `6'7"`, `7'1"`]:

There is some trouble in deciding what "next to" means in the sixth constraint, "The person next to Ryan is #14". It certainly means at least that Ryan <> #14. This is the least-constraining option, and we'll use it as a start. If we get a unique solution, then we're done.

Cons:= [justin=goalie, rt_for=10, goalie=`6'4"`, joe=`6'1"`, ryan=rt_for, ryan<>14,
     `6'4"`=16, 10=`5'8"`, lt_for=15, brad= rt_def, brendan=20, michael=`7'1"`,
     miguel=6, michael=lt_for, 42=rt_def, brad=`6'2"`, 6=cen_def, 15=`7'1"`,
     20=`6'7"`, miguel=`5'10"`, 14=`6'1"`, `6'7"`=lt_def, joe=cen_for
]:

read "C:/Users/Carl/desktop/logic_problems.mpl":

Soccer:= LogicProblem(Vars):

with(Soccer):

Warning, Soccer is not a correctly formed package - option `package' is missing

Satisfy(Cons);

NULL

`Unique solution:`

Matrix(7, 4, {(1, 1) = justin, (1, 2) = goalie, (1, 3) = 16, (1, 4) = `6'4"`, (2, 1) = joe, (2, 2) = cen_for, (2, 3) = 14, (2, 4) = `6'1"`, (3, 1) = ryan, (3, 2) = rt_for, (3, 3) = 10, (3, 4) = `5'8"`, (4, 1) = brad, (4, 2) = rt_def, (4, 3) = 42, (4, 4) = `6'2"`, (5, 1) = brendan, (5, 2) = lt_def, (5, 3) = 20, (5, 4) = `6'7"`, (6, 1) = michael, (6, 2) = lt_for, (6, 3) = 15, (6, 4) = `7'1"`, (7, 1) = miguel, (7, 2) = cen_def, (7, 3) = 6, (7, 4) = `5'10"`})

 

 

Download Soccer_LP.mw

 

I can't reproduce your problem, so I am not sure this will fix it. In procedure `*`, you should refer to global `*` as :-`*`. You should also make i local.

m:= module() option package; export `*`;
    `*`:= proc( a::list, b::list) option overload;
     local i;
        return add(i, i  in zip(:-`*`, a, b));
    end proc;    
end module;

Let me know if that helps. And if you can get a reproducible example of the problem, please post it.

 

Your data are too large. Try scaling down by a factor of 1000.

F1 := Vector([1500, 1750, 2250, 4000, 4300, 5000, 7000]):
Statistics:-MaximumLikelihoodEstimate(Weibull(beta, eta), F1 /~ 1000);

Weibull has a linear scaling property for the first parameter, so the answer using your original data is

applyop(x-> 1000*x, [1,2], %);

I used solve to solve the resulting n^2 x n^2 system of linear equations. There may be a more-efficient method.

restart:

The procedure:
Solve:= proc(A::Matrix(square), B::Matrix(square), C::Matrix(square))
# Solves matrix equation A.X + X.B = C for X.
local
     i, j, x,
     X:= Matrix(rtable_dims(A), symbol= x),
     xs:= {seq(seq(x[i,j], j= rtable_dims(X)[2]), i= rtable_dims(X)[1])}
;
     if [rtable_dims(A)] <> [rtable_dims(B)] or [rtable_dims(B)] <> [rtable_dims(C)] then
          error "Incompatible matrix dimensions"
     end if;
     eval(X, solve(convert(A.X+X.B =~ C, set), xs));
end proc:

Example of use:
(A,B,C):= ('LinearAlgebra:-RandomMatrix(3,3)' $ 3);

x:= Solve(A,B,C);

 

Verification:
A.x + x.B;

LinearAlgebra:-Equal(%, C);      

                                       true

Download Matrix_equation.mw

restart:
5*sqrt(1-sb^2) = 6*sqrt(1-sb^2)*sa*sqrt(1-sa^2)+4*sb,
42*sqrt(1-sa^2) = 3*sqrt(1-sa^2)*sb*sqrt(1-sb^2)+4*sa:
fsolve({%}, {sa=.995, sb=.743});

 

Next time, please post your equations in plaintext form so that I do not need to type them in.

There is a huge variety of nonsensical input that you can give to Maple for which it does not issue an error message. Don't try to ascribe meaning to the output. (There is an old saying of computer science: GIGO---Garbage In, Garbage Out.) As far as I know, there is never a reason to give FAIL as input. See ?FAIL and ?boolean .

According to the technical definitions of bug and feature, a situation which is not described in a program's documentation cannot be considered as either one. A bug is a situation where a program acts contrary to its documentation; a feature is a useful situation where a program acts in accordance with its documentation.

First 319 320 321 322 323 324 325 Last Page 321 of 395