Carl Love

Carl Love

28070 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

My favorite way is to use the trace command. For any (non-builtin) procedure P , you can give the command

trace(P):

before executing the procedure. Then when you execute code containing a call to P, you'll see when P is called, what its arguments are, what its return value is, and some of what happens inside P.

You can have trace turned on for any number of procedures at the same time.

Here are some somewhat elegant procedures to determine whether intervals intersect and what the intersection is. They work for any number of any type of real interval: open, closed, infinite, half-open, etc.


restart:

TypeTools:-AddType(
     Interval,
     proc(r)
          try RealRange(op(r)) catch: return false end try;
          true
     end proc
):
 

DoIntervalsIntersect:= proc(R::seq(Interval), $)
local r,x;
     coulditbe(x in `intersect`(seq(SetOf(RealRange(op(r))), r= R)))
end proc:

DoIntervalsIntersect(1..3, 5..6, 2..4);

false

(1)

DoIntervalsIntersect(1..3, 2..4);

true

(2)

DoIntervalsIntersect(1..1, -1..2);

true

(3)

DoIntervalsIntersect(0..Open(1), 1..2);

false

(4)

IntersectIntervals:= proc(R::seq(Interval), $)
local r,x;
     try r:= (x-> `property/object`[x])(x) assuming seq(x::RealRange(op(r)), r= R)
     catch: return {}
     end try;
     `if`(r::realcons, {r}, r)
end proc:

IntersectIntervals(1..2, 1.25..3, 1.2..1.4);

RealRange(1.25, 1.4)

(5)

IntersectIntervals(1..Open(3), Open(2)..4);

RealRange(Open(2), Open(3))

(6)

IntersectIntervals(0..Open(1), 1..2);

{}

(7)

IntersectIntervals(0..1, 1..2);

{1}

(8)

 

NULL


Download Intersect_Intervals.mw

With a few minutes (less than five) of pattern matching with the "naked eye", I came up with the following formula:

int(diff(P(n,x), x)*diff(P(m,x), x), x= -1..1) = `if`((m+n)::odd, 0, min(m,n)*(min(m,n)+1))

I verified the formula up to n=30, m=30. I suspect that the formula could be easily proved.

Here's how to create patterns for visual inpection:

interface(rtablesize= infinity):
M1:= Matrix(30, (m,n)-> int(diff(P(m,x), x)*diff(P(n,x), x), x= -1..1));

ColumnRelations:= proc(M::Matrix, {free::symbol:= :-_v})
uses LA= LinearAlgebra;
local k;
     evalc(map2(`.`, <seq(free[k], k= 1..op([1,2], M))>, LA:-NullSpace(M))) =~ 0
end proc:

ColumnRelations(M, free= v);

If the output in your worksheet can be regenerated quickly, then you should remove the output before saving it. You can use the menu selection Edit -> Remove output -> From worksheet.

Yes, you should consider dividing your worksheet. When the GUI gets bogged down, as often happens with lengthy output, there's no equivalent of the Stop button that will stop it. I've often had to kill the GUI, which kills the whole Maple process.

The worksheet below has the complete answers to your three questions, using a slightly different technique than Kitonum (very slightly different). I only post it because I was composing it at the same time that he was composing his.

restart:

l1 := [1, 1, 1, 0, 0, 0, 0, 0, 0]:

l2 := [0, 0, 0, 1, 1, 1, 0, 0, 0]:

l3 := [0, 0, 0, 0, 0, 0, 1, 1, 1]:

l4 := [1, 0, 0, 1, 0, 0, 1, 0, 0]:

l5 := [0, 1, 0, 0, 1, 0, 0, 1, 0]:

l6 := [0, 0, 1, 0, 0, 1, 0, 0, 1]:

l7 := [0, 0, 1, 0, 1, 0, 1, 0, 0]:

 

A:= Matrix([l||(1..7)]):

b:= Vector(7, fill= 15):

 

Answer for your first question:

Sol:= LinearAlgebra:-LinearSolve(A, b, free= t);

Sol := Vector(9, {(1) = -30+2*t[8]+3*t[9]+2*t[6], (2) = 30-2*t[8]-2*t[9]-t[6], (3) = 15-t[9]-t[6], (4) = 30-t[8]-2*t[9]-2*t[6], (5) = -15+t[8]+2*t[9]+t[6], (6) = t[6], (7) = 15-t[8]-t[9], (8) = t[8], (9) = t[9]})

(1)

The free variables are:

Free:= [indets(Sol, name)[]];

[t[6], t[8], t[9]]

(2)

 

Answer for your third question:

Sol:= convert(Sol, list):
S:= {$0..8}:
n:= nops(Free):
Sols:= table():
for T in combinat:-permute([S[]], n) do
     A:= Free =~ T;
     if {eval(Sol, A)[]} = S then Sols[A]:= [][] end if
end do:
{
indices(Sols, nolist)};

{}

(3)

Nothing is in the set, so the answer to your third question is "No".

 

Answer for your second question:

S:= {$2..8}:
Sols:= table():
for T in combinat:-permute(`$`~([S[]], n), n) do
     A:= Free =~ T;
     if {eval(Sol, A)[]} = S then Sols[A]:= [][] end if
end do:
indices(Sols, nolist);

[t[6] = 2, t[8] = 4, t[9] = 7], [t[6] = 6, t[8] = 4, t[9] = 4], [t[6] = 3, t[8] = 2, t[9] = 8], [t[6] = 6, t[8] = 7, t[9] = 4], [t[6] = 4, t[8] = 8, t[9] = 4], [t[6] = 8, t[8] = 4, t[9] = 4], [t[6] = 7, t[8] = 6, t[9] = 4], [t[6] = 8, t[8] = 6, t[9] = 3], [t[6] = 6, t[8] = 2, t[9] = 6], [t[6] = 2, t[8] = 3, t[9] = 8], [t[6] = 2, t[8] = 6, t[9] = 6], [t[6] = 7, t[8] = 8, t[9] = 2], [t[6] = 3, t[8] = 4, t[9] = 6], [t[6] = 4, t[8] = 2, t[9] = 7], [t[6] = 6, t[8] = 8, t[9] = 2], [t[6] = 8, t[8] = 6, t[9] = 2], [t[6] = 8, t[8] = 7, t[9] = 2], [t[6] = 6, t[8] = 4, t[9] = 6], [t[6] = 4, t[8] = 3, t[9] = 6], [t[6] = 4, t[8] = 6, t[9] = 6], [t[6] = 4, t[8] = 2, t[9] = 8], [t[6] = 4, t[8] = 6, t[9] = 4], [t[6] = 2, t[8] = 4, t[9] = 8], [t[6] = 6, t[8] = 8, t[9] = 3]

(4)

So the answer to your second question is "Yes", and the above are all the possibilities.

 

 

Download zero-one_system.mw

Assuming that the input is floating point, the command that you want is frem(..., evalf(2*Pi)). If your input contains symbolic Pi that you'd like to keep in the output, let me know.

Here's a procedure that does what you want:

YourProc:= proc(
     fx::algebraic,
     `x= a..b`::And(name=range(realcons), satisfies(r-> op([2,1], r) < op([2,2], r))),
     n::posint,
     {functionoptions::list({symbol, name= anything}):= []},
     {pointoptions::list({symbol, name= anything}):= []}
)
local
     x:= op(1, `x= a..b`),
     a:= op([2,1], `x= a..b`),
     r:= op([2,2], `x= a..b`) - a,   #b-a
     Df:= unapply(diff(fx, x), x),
     k,   #index
     xs:= [seq(a+k*r/n, k= 0..n)]
;
     plots:-display(
          plot(fx, `x= a..b`, functionoptions[]),
          plot([seq([k, Df(k)], k= xs)], style= point, pointoptions[]),
          _rest
     )
end proc:

And an example of its use:

YourProc(
     x^2, x= -2..2, 5,
     functionoptions= [color= green],
     pointoptions= [symbol= cross, symbolsize= 24],
     axes= boxed
);

The last three arguments are optional. You could just as well use it as

YourProc(x^2, x= -2..2, 5);

Note that intervals in Maple are specified as 2..5 rather than [2,5]. However, if you insist on using [a,b], I can easily change the procedure to accomodate that.

As a workaround, you can use Maple Input (aka 1D input).

The direct cause of your problem is that you're not allowed to assign to a parameter, in this case M. You can make a local copy of M like this:

M1:= copy(M);

Then make all assignments to M1 and return M1.

There are also a few places where you used = that should've been :=.

You should begin your procedure with 

uses LinearAlgebra;

or

uses LA= LinearAlgebra;

Don't rely on the with statement being active in your procedure---sometimes it may be, sometimes it may not be.

Suppose that your dsolve result is assigned to ans:

ans:= dsolve(...);

Then do

u:= unapply(eval(u(t), ans), t);

If g=0, then f can be arbitrary and the jacobian will still be zero. That's why the fourth solution shows f unchanged.

plot3d([r, theta, Pi/6], theta= 0..2*Pi, r= 0..1, coords= spherical);

Acer's Answer is very complete. Here's a quick-and-dirty version that works in any Maple GUI. Define two procedures to be used as binary operators:

`&<`:= (a,b)-> a*exp(I*b*Pi/180):

`&+`:= proc(a,b)
local x,y;
     (x,y):= op(evalf(polar(a+b)));
     '`&<`'(x, evalf(y*180/Pi))
end proc:

Now,

(5 &< 30) &+ (4 &< 60);

Your matrix is only Hermitian if all the variables are real. If you do substitute real values for the variables, then the imaginary parts of those two eigenvalues will be zero. Is it possible to prove, in general, that those imaginary parts are real (other than by saying that the eigenvalues came from a Hermitian matrix)? I doubt it. It's well known that there are real algebraic numbers that can't be expressed in radical form without using imaginary numbers. For example, consider the roots of x^3 - 3*x + 1.

First 229 230 231 232 233 234 235 Last Page 231 of 395