Carl Love

Carl Love

28025 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

Actually, the representation of the table as matrices fits across my screen.

restart:
interface(rtablesize= 27):
M:= [seq(seq(seq(< < a,0 > | < b,c > >, a= 0..2), b= 0..2), c= 0..2)]:
T:= Matrix(27,27, (i,j)-> M[i].M[j] mod 3);

 

The piecewise command is easier to use than a chain of if-then-else statements.

Grades:= proc(x::realcons)
local a,b,c,d,f;
     piecewise(
          x < 0, undefined, x < 59.5, f, x < 69.5, d, x < 79.5, c,
          x < 89.5, b, x <= 100, a, undefined
     )
end proc:

If you still want to use if statements, then use elif, which is short for else if. That way, you can turn a chain of nested if statements into a single statement:

Grades:= proc(x::realcons)
local a,b,c,d,f;
     if x < 0 then undefined
     elif x < 59.5 then f
     elif x < 69.5 then d
     elif x < 79.5 then c
     elif x < 89.5 then b
     elif x <= 100 then a
     else undefined
     end if
end proc:

You need a for loop, an if-then statement, the isprime command, and a counter variable.

CountPrimes:= proc(n::posint)
local j, count:= 0;
     for j from 2 to n do
          if isprime(j) then
               count:= count+1
          end if
     end do;
     count
end proc:

CountPrimes(15);
                              
6

Go to the Maple Applications Center, and download and install the OrthogonalExpansions package. Then

OrthogonalExpansions:-FourierSeries(evalc(x*exp(I*x)), x= -Pi..Pi, infinity);

The evalc is necessary to get the correct coefficients at i=1. Don't confuse the summation index i with the imaginary I.

 

The last constraint, constraint 21, "Eilish is not next to the person with straight hair", needs to be specified as Rel(Separated, Eilish, straight, PN, [1]), which says that they are separated by at least 1 when measured wrt position. You merely have Eilish <> straight. Since Separated is an export of the dynamic module, this constraint needs to be specified after the with of the module.

When I do this, the program reports multiple solutions. The second solution that it gives is the same as the solution on the website from which you got the problem. From my reading, the first solution that the program gives also satisfies every constraint. Please verify this.

 

Here's how to get the answers with fsolve. This can be modified to instead use the multivariate Newton procedure that Markiyan directed you to.

restart:
eqns:= {
     t*((p-.764*z-2.194768)^2-1.170308549+.529948*(z-.382)^2)-(1-t)*p,
     t*((p+.382*z+.661624*y-1.907568)^2-1.018097144+.529984*(-.866*y-.5*z-.382)^2)+(1-t)*y,
     t*((p+.382*z-.661624*y-2.470348)^2-1.31636154+.529984*(.866*y-.5*z-.382)^2)+(1-t)*z
}:

(a,b):= (0,1):  h:= 0.0001:
N:= round((b-a)/h)+1;

Sols:= Array(1..N, 1..4):
inits:= {y=1,z=1,p=1}:
tt:= a:
for n to N do
     Sol:= fsolve(eval(eqns, t= tt), inits);
     Sol:= eval([y,z,p], Sol);
     Sols[n,..]:= < tt, Sol[] >;
     tt:= tt+h;
     inits:= {([y,z,p] =~ Sol)[]}
end do:

The solutions can be plotted as a space curve as a function of t like this:

plots:-spacecurve(convert(Sols[.., 2..4], listlist), labels= [y,z,p]);

Use an animation, so that one of a, c, n becomes the time parameter. Here I use a as the time parameter.

restart:
f:= (a,c,n)->
     64*a^2*n-16*a^4*n-256*c^2*n+32*c^4*n-96*a^2*c^2+ 8*a^2*c^4+24*a^4*c^2
     -64*a^2*n^2+256*a^2-124*a^4+ 15*a^6+256*n^2+64*a^2*c^2*n
:
plots:-animate(plot3d, [f(a,c,n), c= 0..2, n= 0..4], a= 0..2);



The above ideas can be made into a custom convert procedure:

`convert/decimalfraction`:= (x::float)-> op(1,x)/``(10^(-op(2,x))):

convert(.25, decimalfraction);

x^(1/3) is complex valued for negative because Maple uses the principal branch with `^`. The real-valued alternative is surd.

plot(surd(x,3), thickness= 5);

You can generate the procedure by calling LinearAlgebra:-Eigenvectors on a symbolic 2x2 matrix A = < < a, b > | < c, d > > and then reverse engineering the results. Doing that, I got the following

Eigen:= proc(A::'Matrix'(2,2))
local
     a:= A[1,1], b:= A[2,1], c:= A[1,2], d:= A[2,2],
     s:= sqrt((a-d)^2+4*b*c)/2,
     e1:= (a+d)/2 + s, e2:= (a+d)/2 - s,
     ev1:= < c, (d-a)/2+s >, ev2:= < c, (d-a)/2-s >
;
     if s=0 then [] else [e1, e2, ev1, ev2] end if
end proc:

This procedure needs a little modification. There are cases where s=0 but there are still two linearly independent eigenvectors. For example, any nonzero vector is an eigenvector of the zero matrix.

Simply include z=t with the equations that you pass to solve and include z in the output variables.

L1:= {4*x + 3*y + z = 0, x + y - z - 15 = 0}:
solve(L1 union {z=t}, {x,y,z});

BinomialMod2:= (n,k)-> `*`(Bits:-Split(Bits:-Implies(k,n))[]);

This is about 32,000 times faster than binomial(n,k) mod 2 when the input is 5-digit integers. For larger integers, it is even faster than that.

 

Note that the gridlines do not appear in the actual plot. They are an artifact of this forum, MaplePrimes.

restart: #Put restart on its own line, in its own execution group.

hgk:= 0.9:  vgk:= 5:  vb:= 25:  rg:= 0.15:

tb:= 22*sqrt(1+tan(x*Pi/180)^2+tan(y*Pi/180)^2)/vb;

(22/25)*(1+tan((1/180)*x*Pi)^2+tan((1/180)*y*Pi)^2)^(1/2)

tgk:= 2*sqrt(121*tan(x*Pi/180)^2+(11*tan(y*Pi/180)-hgk)^2)/vgk+0.15;

(2/5)*(121*tan((1/180)*x*Pi)^2+(11*tan((1/180)*y*Pi)-.9)^2)^(1/2)+.15

X:= -18..18:  Y:= 0..12:

Pts:= select(
     P-> evalf(eval(tgk-tb, [x,y]=~P)) < 0,
     [seq(seq([x,y], x= X), y= Y)]
):

plot(
     Pts,
     style= point, symbol= cross,
     view= [X,Y], axes= boxed, labels= [x,y]
);

 


Download tan_pointplot.mw

Your procedure does not work because you did not specify a return value. The last line of the procedure should be simply S to return S.

You have the right idea, but your procedure is much more complicated than it needs to be. You never need to have something like

do "statement"; break; od;

because it is equivalent to just

"statement";

Also, there's no need to do S:= S union {}. That statement does not change S. You only need to account for the ones. Here's all that you need:

m:= proc(n::list)
local S:= {}, i;
     for i to nops(n) do
          if n[i]=1 then
               S:= S union {i}
          fi
     od;
     S

end proc;

The above code is for educational purposes only, because it is not an efficient way to perform the task. I just wanted to illustrate the correct loop structure. For an efficient way, see Acer's Answer.


Solved 2014-Feb-21 by Carl Love

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

Alan's Birthday Seating logic problem

 

It's Alan’s birthday and he's having a party. Seven other people will attend: Amy, Brad, Beth, Charles, Debbie, Emily and Frances.

 

Everyone will sit around the circular dining table. The seating arrangement must meet the following conditions:

 

• Amy and Alan sit together

• Brad and Beth sit together

• Charles sits next to either Debbie or Emily

• Frances sits next to Debbie

• Amy and Alan do not sit next to either Brad or Beth

• Brad does not sit next to Charles or Frances

• Debbie and Emily do not sit next to each other

• Alan does not sit next to either Debbie or Emily

• Amy does not sit next to Charles

 

List the numeric variable first so that answers are reported in order by that.

Vars:= [PN,Name]:

Name:= [Alan, Amy, Brad, Beth, Charles, Debbie, Emily, Frances]:

PN:=[$1..8]:

Birthday:= LogicProblem(Vars):

with(Birthday);

Warning, Birthday 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]

Define some abbreviation functions for NextTo and "not NextTo".

NT:= (a,b)-> NextTo(a, b, PN):

NNT:= (a,b)-> Rel(Separated, a, b, PN, [1]):


Reinitialize():

Con1:= Alan=1, Amy=8:

Con2:= NT(Brad, Beth):

Con3:= OR([NT(Charles, Debbie), NT(Charles, Emily)]):

Con4:= NT(Frances, Debbie):

Con5:= NNT(Amy, Brad), NNT(Amy, Beth), NNT(Alan, Brad), NNT(Alan, Beth):

Con6:= NNT(Brad, Charles), NNT(Brad, Frances):

Con7:= NNT(Debbie, Emily):

Con8:= OR([NNT(Alan, Debbie), NNT(Alan, Emily)]):

Con9:= NNT(Amy, Charles):


Satisfy([Con||(1..9)]);

NULL

`Multiple solutions.  Two of the possibilities:`

Matrix(8, 2, {(1, 1) = 1, (1, 2) = Alan, (2, 1) = 2, (2, 2) = Charles, (3, 1) = 3, (3, 2) = Debbie, (4, 1) = 4, (4, 2) = Frances, (5, 1) = 5, (5, 2) = Beth, (6, 1) = 6, (6, 2) = Brad, (7, 1) = 7, (7, 2) = Emily, (8, 1) = 8, (8, 2) = Amy}), Matrix(8, 2, {(1, 1) = 1, (1, 2) = Alan, (2, 1) = 2, (2, 2) = Emily, (3, 1) = 3, (3, 2) = Brad, (4, 1) = 4, (4, 2) = Beth, (5, 1) = 5, (5, 2) = Charles, (6, 1) = 6, (6, 2) = Debbie, (7, 1) = 7, (7, 2) = Frances, (8, 1) = 8, (8, 2) = Amy})

 


Download Birthday_LP.mw

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