Carl Love

Carl Love

28070 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love


restart:

u:= -6*a+b+c:  v:= 3*a-4*b+c:

expand(u*v)/sqrt(expand(u*u)*expand(v*v));

(-18*a^2+27*a*b-3*a*c-4*b^2-3*b*c+c^2)/((36*a^2-12*a*b-12*a*c+b^2+2*b*c+c^2)*(9*a^2-24*a*b+6*a*c+16*b^2-8*b*c+c^2))^(1/2)

eval(%, [a*b=1, a*c=1, b*c=1, a^2=1, b^2=16, c^2=16]):

arccos(%);

Pi-arccos((3/782)*11730^(1/2))

evalf(%);

1.99928084710157

evalf(convert(%, degrees));

114.550354600260*degrees

 

``


Download AngleBetween.mw

Let n represent the number of degrees of freedom. Then

X:= Statistics:-RandomVariable(StudentT(n)):
T:= unapply(Statistics:-CDF(X,x), n,x);

plot(T(1,x), x= -3..3);

evalf(T(1,1));
                       0.750000000000000

Please ask any further questions about logic problems in a new thread.

Here is how to obtain a complete solution to the logic problem, and to prove its uniqueness, using my LogicProblem package (available at the Maple Applications Center).

Solved 2014-Feb-10 from Puerto Viejo de Talamanca, Limon, Costa Rica.

restart:

Statement of the logic problem:

Who Works Where?

Alex, Betty, Carol, Dan, Earl, Fay, George and Harry are eight employees of an organization

 

Constraint 0: They work in three departments: Personnel, Administration and Marketing with not more than three of them in any department.

 

Each of them has a different choice of sports from Football, Cricket, Volleyball, Badminton, Lawn Tennis, Basketball, Hockey and Table Tennis not necessarily in the same order.

 

Constraints:

1. Dan works in Administration and does not like either Football or Cricket.

2. Fay works in Personnel with only Alex who likes Table Tennis.

3. Earl and Harry do not work in the same department as Dan.

4. Carol likes Hockey and does not work in Marketing.

5. George does not work in Administration and does not like either Cricket or Badminton.

6. One of those who work in Administration likes Football.

7. The one who likes Volleyball works in Personnel.

8. None of those who work in Administration likes either Badminton or Lawn Tennis.

9. Harry does not like Cricket.

 

Questions:

1. Who are the employees who work in the Administration Department?

2. In which Department does Earl work?

 

Vars:= [Name, Dept, Sport]:

Name:= [alex, betty, carol, dan, earl, fay, george, harry]:

Constraints 0 & 2 together imply that the departments are divided thus:

person:= {person||(1..2)}:  admin:= {admin||(1..3)}:  market:= {market||(1..3)}:

Dept:= [person[], admin[], market[]]:

Sport:= [football, cricket, volleyball, badminton,
      lawn_tennis, basketball, hockey, table_tennis]:

Con1:= dan = admin1, (dan <>~ {football, cricket})[]:

Con2:= fay = person1, alex = person2, alex = table_tennis:

Con3:= (earl <>~ admin)[], (harry <>~ admin)[]:

Con4:= carol = hockey, (carol <>~ market)[]:

Con5:= (george <>~ admin union {cricket, badminton})[]:

Con6:= (football <>~ market union person)[]:

Con7:= (volleyball <>~ market union admin)[]:
Con8:= (badminton <>~ admin)[], (lawn_tennis <>~ admin)[]:

Con9:= harry <> cricket:

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

Work:= LogicProblem(Vars):

with(Work);

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

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

NULL

`Incomplete solution; need more constraints to complete:`

Matrix(8, 3, {(1, 1) = alex, (1, 2) = person2, (1, 3) = table_tennis, (2, 1) = betty, (2, 2) = _, (2, 3) = _, (3, 1) = carol, (3, 2) = _, (3, 3) = hockey, (4, 1) = dan, (4, 2) = admin1, (4, 3) = basketball, (5, 1) = earl, (5, 2) = _, (5, 3) = _, (6, 1) = fay, (6, 2) = person1, (6, 3) = volleyball, (7, 1) = george, (7, 2) = _, (7, 3) = _, (8, 1) = harry, (8, 2) = _, (8, 3) = _})

But the solution is complete enough to answer the two questions posed: Who are the employees that work in the Administration Dept.? In which department does Earl work?

Name &? Dept;

Matrix(9, 9, {(1, 1) = ` `, (1, 2) = alex, (1, 3) = betty, (1, 4) = carol, (1, 5) = dan, (1, 6) = earl, (1, 7) = fay, (1, 8) = george, (1, 9) = harry, (2, 1) = person1, (2, 2) = X, (2, 3) = X, (2, 4) = X, (2, 5) = X, (2, 6) = X, (2, 7) = O, (2, 8) = X, (2, 9) = X, (3, 1) = person2, (3, 2) = O, (3, 3) = X, (3, 4) = X, (3, 5) = X, (3, 6) = X, (3, 7) = X, (3, 8) = X, (3, 9) = X, (4, 1) = admin1, (4, 2) = X, (4, 3) = X, (4, 4) = X, (4, 5) = O, (4, 6) = X, (4, 7) = X, (4, 8) = X, (4, 9) = X, (5, 1) = admin2, (5, 2) = X, (5, 3) = _, (5, 4) = _, (5, 5) = X, (5, 6) = X, (5, 7) = X, (5, 8) = X, (5, 9) = X, (6, 1) = admin3, (6, 2) = X, (6, 3) = _, (6, 4) = _, (6, 5) = X, (6, 6) = X, (6, 7) = X, (6, 8) = X, (6, 9) = X, (7, 1) = market1, (7, 2) = X, (7, 3) = _, (7, 4) = X, (7, 5) = X, (7, 6) = _, (7, 7) = X, (7, 8) = _, (7, 9) = _, (8, 1) = market2, (8, 2) = X, (8, 3) = _, (8, 4) = X, (8, 5) = X, (8, 6) = _, (8, 7) = X, (8, 8) = _, (8, 9) = _, (9, 1) = market3, (9, 2) = X, (9, 3) = _, (9, 4) = X, (9, 5) = X, (9, 6) = _, (9, 7) = X, (9, 8) = _, (9, 9) = _})

The Xs in the table represent excluded possibilities, the Os represent known equivalences, and the _s are the equivalences that have been neither proven nor disproven.

From this table we see that Dan, Betty, and Carol work in Administration and that Earl works in Marketing.

 

It is possible to get to a unique solution with the given constraints. Add the information that we just found out.

Satisfy([betty = admin2, earl = market1, george = market2]);

NULL

`Unique solution:`

Matrix(8, 3, {(1, 1) = alex, (1, 2) = person2, (1, 3) = table_tennis, (2, 1) = betty, (2, 2) = admin2, (2, 3) = football, (3, 1) = carol, (3, 2) = admin3, (3, 3) = hockey, (4, 1) = dan, (4, 2) = admin1, (4, 3) = basketball, (5, 1) = earl, (5, 2) = market1, (5, 3) = cricket, (6, 1) = fay, (6, 2) = person1, (6, 3) = volleyball, (7, 1) = george, (7, 2) = market2, (7, 3) = lawn_tennis, (8, 1) = harry, (8, 2) = market3, (8, 3) = badminton})

 

 

Download WhoWorksWhere.mw

You need to put the if statement inside the procedure, like this:

MARK:= (a,b,c,d)->
    if a.d-b.c = 0 then
         [0,0,0,0]
    else
         [d/(a.d-b.c), -b/(a.d-b.c), -c/(a.d-b.c), a/(a.d-b.c)]
    fi;

The print statement is not needed. Indeed, print is never an appropriate way for a procedure to return its output.

restart:
`mod/ReduceExponents`:= (p::polynom, n::posint)->
     evalindets(p, '`^`'(name, posint), T-> op(1,T)^(op(2,T) mod n)):
p:= x-> 1+x^3+x^17+x^19:
ReduceExponents(p(x)) mod 17;

ArrayInterpolation will not accept exact integer values; they must be converted to floating-point values with evalf. Also, do not use with inside a procedure; use uses instead. And I made your variables local. A will be the return value of the procedure.

InterProc := proc ()
uses CurveFitting;
local i, A, variable1, variable2;
     A := Matrix(10, 4);
     variable1 := evalf([0, 100]);
     variable2 := evalf([12, 20]);

     for i from 1 to 10 do
          A(i, 1) := evalf(3+i);
          A(i, 2) := 2*i+A(i, 1);
          A(i, 3) := A(i, 2)-1;
          A(i, 4) := ArrayInterpolation(variable1, variable2, A(i, 1));
     end do;
end proc;

Three errors I see:

  1. "if" must be with a lowercase "i".
  2. Need a semicolon at the end of the first line.
  3. The denominators need to be in parentheses: (a*d - b*c).

You should make your code into a procedure, like below. There is no need for the print command.

 

restart:

Inverse:= proc(M::Matrix(2,2))
local a,b,c,d,D;
    (a,b,c,d):= convert(M,list)[];
    D:= a*d-b*c;
    if D=0 then
         error "Matrix is not invertible."
    else
         < < d, -b > | < -c, a > > / D
    end if
end proc:

M:= < < a, b > | < c , d > >;

M := Matrix(2, 2, {(1, 1) = a, (1, 2) = c, (2, 1) = b, (2, 2) = d})

Inverse(M);

Matrix(2, 2, {(1, 1) = d/(a*d-b*c), (1, 2) = -c/(a*d-b*c), (2, 1) = -b/(a*d-b*c), (2, 2) = a/(a*d-b*c)})

M.Inverse(M);

Matrix(2, 2, {(1, 1) = a*d/(a*d-b*c)-b*c/(a*d-b*c), (1, 2) = 0, (2, 1) = 0, (2, 2) = a*d/(a*d-b*c)-b*c/(a*d-b*c)})

simplify(%);

Matrix(2, 2, {(1, 1) = 1, (1, 2) = 0, (2, 1) = 0, (2, 2) = 1})

M:= Matrix(2,2);

M := Matrix(2, 2, {(1, 1) = 0, (1, 2) = 0, (2, 1) = 0, (2, 2) = 0})

Inverse(M);

Error, (in Inverse) Matrix is not invertible.

M:= LinearAlgebra:-RandomMatrix(2,2);

M := Matrix(2, 2, {(1, 1) = 44, (1, 2) = -31, (2, 1) = 92, (2, 2) = 67})

Inverse(M);

Matrix(2, 2, {(1, 1) = 67/5800, (1, 2) = 31/5800, (2, 1) = -23/1450, (2, 2) = 11/1450})

M.Inverse(M);

Matrix(2, 2, {(1, 1) = 1, (1, 2) = 0, (2, 1) = 0, (2, 2) = 1})

 

 

Download Inverse.mw

 

Use the function form on input, delta(x) and Delta(x), and define the following procedures, perhaps in your initialization file:

`diff/delta`:= x-> delta(x):
`diff/Delta`:= x-> Delta(x):
`print/delta`:= x-> delta*x:
`print/Delta`:= x-> Delta*x:

Now the function form will display as the multiplication form, it won't be affected by taking the derivative, and simplify will only see the function form and won't change it.

Your first line is x:= x0. That should be x0:= x.

Then you'll have a problem because your last two break statements are not in a loop. I suggest that you change your procedure to something like this:

proc_r:= proc(x :: realcons)
local x0;
     x0:= evalf(x);

     #reducing the value to between -Pi and Pi
     while x0 > evalf(Pi) do  x0:= x0 - 2*evalf(Pi)  end do;
     while x0 < evalf(-Pi) do  x0:= x0 + 2*evalf(Pi)  end do;

     #using the symmetry of sin to reduce to between -Pi/2 and Pi/2
     if x0 > evalf(Pi/2) then  x0:= evalf(Pi) - x0
     elif x0 < evalf(-Pi/2) then  x0:= evalf(-Pi) - x0
     end if;

     return x0
end proc:

proc_r(7);  
                                   0.71681469282042

If M is your Matrix, then do

ArrayTools:-AddAlongDimension(M,2);

@Andriy Here is your file with my modifications. All I did was change q and Np from globals into parameters. Please check that this generates the correct matrix, and compare the time to sequential code on a reasonably sized example. The Grid option will no doubt take longer on an example that is too small.

MatrElems_Carl1.mw

plot([cosh(x), x^2], x= -2..2);
f:= x-> x^2:
r:= fsolve(cosh(x)=x^2, x);
[r, f(r)], [-r, f(-r)];

I don't know what the ultimate goal is, so I am not sure that this is correct. But surely ormap is a better way to add a Vector to an Array of Vectors iff it is not already in the Array. This code increases the size of the Array by 1 each time a new entry is added.

proc_cerny1:= proc(A::Matrix, B::Matrix, C::Vector[row], N::nonnegint)
local x:= 2^N, S:= Array(0..0, fill= C), i, j:= 1, T, R;
     for i from 0 to x-1 while i <> j do
          T:= S[i].A;
          if not ormap(LinearAlgebra:-Equal, S, T) then
               j:= j+1;
               S(j):= T #not S[j]
          end if;

          R:= S[i].B;
          if not ormap(LinearAlgebra:-Equal, S, R) then
               j:= j+1;
               S(j):= R
          end if
     end do;
     S
end proc:

My solution allows you to create, display, and assign the sequence all in one step. It also works for lists and sets. You only need to append a ! to the object. I chose ! because it is reminiscent of a column. This does not affect the usage of ! for factorials.

This version only works in Maple 17. If you need it for earlier Maple, I can make some slight modifications.


restart:

local `!`:= overload([
     proc(a::anything, b::anything)
     option overload;
     local x:= b; #Force a check for a second argument
          seq(print(x, ``), x= [args[1..-2]]);
          print(args[-1]);
          args
     end proc,

     proc(L::{list, set})
     option overload;
     local x;
          seq(print(x, ``), x= L[1..-2]);
          print(L[-1]);
          L
     end proc,

     factorial
]):
          

S:= (A,B,C)!:

A, ``

B, ``

C

S;

A, B, C

S:= [a,b,c]!:

a, ``

b, ``

c

S;

[a, b, c]

S:= {a,b,c}!:

a, ``

b, ``

c

S;

{a, b, c}

Factorials still work.

n!, 4!;

factorial(n), 24

 


Download overload_!.mw

You have a first-order ODE, so dsolve will only allow one condition, even though the presence of the a should allow for another condition. We can fool dsolve into accepting a second condition by making a a constant function, i.e. a function whose derivative is 0, and then treating the system as a BVP.

restart:
fx:= diff(n(x),x)-a(x), diff(a(x),x) :
eval(n(x), dsolve({fx, n(0) = 1, n(1) = 2}, {a(x), n(x)}));

First 321 322 323 324 325 326 327 Last Page 323 of 395