Carl Love

Carl Love

28095 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

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

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

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