Carl Love

Carl Love

28035 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

Your code doesn't work because you are just reusing the same Matrix M each time. When you change the entries in a Matrix, it's still considered the same Matrix. This is different than the behavior of a list, which is considered immutable, meaning that if an entry changes, then it's considered an entirely new list. Try this:

restart:

CartProdSeq:= proc(L::seq(list), $)
local S,j;
    eval(subs(S= seq, foldl(S, [_i||(1..nargs)], seq(_i||j= L[j], j= nargs..1, -1))))
end proc:

PRIME:= 2:

for M in CartProdSeq([$0..PRIME-1] $ 16) do
     if Determinant(Matrix(M)) mod PRIME <> 0 then
          Mats[cat("", M[])]:= [][]
     end if
end do:

Mats:= [indices(Mats, nolist)]:

This code also handles your second request---it converts every Matrix to a compact string.

Edit: This has a bug. Corrected code is in my first Reply below.

Here are some bifurcation plots for this map. There is some quite interesting chaotic bifurcation for a small range of a.

restart:

f:= x-> exp(x^2*(a-x)):

Iterate:= proc(a, x0:= 1., n:= 2000)
local A:= hfarray(1..n, [x0]), f:= subs(:-a= a, eval(:-f));          
     evalhf(
          proc(f, A, n)
          local k;
               for k from 2 to n do A[k]:= f(A[k-1]) end do
          end proc
          (f, A, n)
     );
     evalf[4]~(convert(A[1000..], set))
end proc:

Points:= table():

for a1 from -3. by .01 to 3. do
     Points[a1]:= map(p-> [a1,p], Iterate(a1))[]
end do:

plot(
     [entries(Points, nolist)], style= point, symbol= point,
     symbolsize= 1, labels= [a, ``], gridlines= false
);

 

There is apparently some chaotic bifurcation between a=1.4 and 1.7. Let's look at that area more closely.

Points:= table():

for a1 from 1.4 by .002 to 1.7 do
     Points[a1]:= map(p-> [a1,p], Iterate(a1))[]
end do:

plot(
     [entries(Points, nolist)], style= point, symbol= point,
     symbolsize= 1, labels= [a, ``], gridlines= false
);

 

 

 

Download bifurcation.mw

The "hairiness" of these plots is a defect of MaplePrimes. They don't appear like that when viewed in Maple.

Does this help?

a:= 1:  b:= 2:
Names:= <'a', 'b'>:
NewNames:= subsindets(Names, name, convert, `local`);

Names;

Now the names in NewNames will never evaluate.

The above won't work on indexed names such as a[0]. I'm working on code for that. (It's done: See my first Reply below.)

By the way, the purpose of the quotes `` isn't to prevent or delay evaluation; it's to construct names (specifically symbols) from strings that contain special characters or which would otherwise evaluate as code. So, `u0` is identical to u0 because it contains no special characters. The quotes are needed on `local` because local is a keyword which would evaluate as code.

 

Of course. Just add linestyle= spacedash to the verticalasymptoteoptions.

eq:= a*x+b*y=c*x+d*y:
`=`(selectremove(has, (lhs-rhs)(eq), x));

You usually need to solve for the same number of variables as there are equations. So, you need to pick the right 10 variables to solve for. It's clear from your "by hand" solution that you want to eliminate vx, vy, and the eight tgt variables. That's 10. So, if you do the following, you'll get exactly the same solutions as you got "by hand".

Sol:= solve(eqs, {vx, vy, seq([tgtX[k], tgtY[k]][], k= 1..4)}):
{tgtX[4]=eval(tgtX[4], Sol), tgtY[4]=eval(tgtY[4], Sol)};

You can give a list of points as the first argument of the regular plot command and by default you'll get an interpolated curve. It's just "connect the dots." So, in the simplest case, the command would be

plot(list of points);

No other arguments are needed.

Answering your Question directly, yes, there's an option that you can give to plots:-pointplot to achieve the same thing. That option is style= line.

What's needed is a better way to form Cartesian products. Using a nested seq or for loop can't be generalized to an arbitrary number of factors. Using combinat:-cartprod is awkward and too slow. The following is the best procedure from an extensive post on Cartesian product procedures by Joe Riel. The procedure is by Joe Riel, with some small modifications by me, mostly so that it would fit on one line.

CartProdSeq:= proc(L::seq(list), $)
local S,j;
    eval(subs(S= seq, foldl(S, [_i||(1..nargs)], seq(_i||j= L[j], j= nargs..1, -1))))
end proc:

Using it for your situation,

ex:= V[2] + a[5]*V[5] + a[6]*V[6] + a[7]*V[7] + V[9]:
v:= [a[5], a[6], a[7]]:
seq(eval(ex, v =~ k), k= [CartProdSeq(seq([0,x], x= v))]);

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.

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