tomleslie

13876 Reputation

20 Badges

15 years, 182 days

MaplePrimes Activity


These are replies submitted by tomleslie

which is why I asked him/her.

But I'm running 64-bit Maple (all versions from Maple 18 to Maple 2018) on 64-bit Windows 7, and the code I posted works on all of these

Trying my original code (developed in Maple 2018, because that is my current default) in Maple 2016, everything still works. I added the kernelopts(version) command just to output Maple version and OS: Maple 2016.2 running on 64-bit Windows 7

As can be seen from the code below, everything still works

  restart;
  with(Fractals:-LSystem):
  with(LSystemExamples):
  kernelopts(version);

`Maple 2016.2, X86 64 WINDOWS, Jan 13 2017, Build ID 1194701`

(1)

#
# Plot the 'nth' iteration of the
# dragon curve
#
  nth:=15:
  PlotExample(DragonCurve, nth);

 

#
# Rather than using the in-built example of the
# dragon curve, define it as a LindeMayer system
# from "first principles". See the Wikipedia
# article at https://en.wikipedia.org/wiki/L-system
#
# Define the initial state and the update rules
# for the Lindenmayer System description of the
# dragon curve
#
  state:= "FX":
  rules:= [ "X" = "X+YF",
            "Y" = "FX-Y"
          ]:
#
# Generate the nth iteration of this system
#
  nth:=15:
  for i from 1 by 1 to nth do
      state:= Iterate(state,rules);
  od:
#
# Define the "actions" for symbols in the LindeMayer
# description
#
  actions:=[ "F" = "draw:1",
             "+" = "turn:-90",
             "-" = "turn:+90"
           ]:
#
# Plot the final state
#
  LSystemPlot(state, actions);

 

 

 

Download dragCurve2.mw

I have to admit that I'm struggling for suggestions as to why this code might not work on your installation - so excuse me if I'm stating the obvious things for you to check

  1. When you post code which doesn't work, it is in 2D input mode. How did my original code get converted to 2D input? Just don't! Download the code given in the above link and park it somewhere convenient. Shut down all Maple sessions. Start a new Maple session. Use the File->Open dialog to load the downloaded worksheet from wherever you parked it - and use the !!! toolbar button to execute it
  2. If this appears as 2D-input (which it shouldn't) then shut down the Maple session, and start it again. Go to Tools->Options->Display and ensure that "Input Display" is set to Maple Notation. Also check that Tools->Options->Interface->Default Format for New Worksheets is set to Worksheet. Having made these changes, hit the "Apply to Session" button at the bottom of Tools->Options popup.
  3. Now use the File->Open dialog, repeating stage1 above. Code should now at least appear in 1D-input mode. Execute using the !!! toolbar button
  4. If execution still fails with the same error message, then there would seem to be only two solutions
    1. It is a Maple installation problem - rare but possible: a Maple reinstallation might be required
    2. It is OS specific: I'm running 64-bit Win 7. If you are running anything else, that might be the issue

The dragon curve is one of the examples in Maple's Fractals() package, so can be plotted in a couple of lines of code.

If you consider this to be "cheating", then you can use the Lindemayer Systems subpackage to define your own dragon curve (and plot it).

The attached does it both ways, althoug for reasons I haven't worked out, the final plot for the second is rotated by Pi/2 compared with the first

restart;
with(Fractals:-LSystem):
with(LSystemExamples):

#
# Plot the 'nth' iteration of the
# dragon curve
#
  nth:=15:
  PlotExample(DragonCurve, nth);

 

#
# Rather than using the in-built example of the
# dragon curve, define it as a LindeMayer system
# from "first principles". See the Wikipedia
# article at https://en.wikipedia.org/wiki/L-system
#
# Define the initial state and the update rules
# for the Lindenmayer System description of the
# dragon curve
#
  state:= "FX":
  rules:= [ "X" = "X+YF",
            "Y" = "FX-Y"
          ]:
#
# Generate the nth iteration of this system
#
  nth:=15:
  for i from 1 by 1 to nth do
      state:= Iterate(state,rules);
  od:
#
# Define the "actions" for symbols in the LindeMayer
# description
#
  actions:=[ "F" = "draw:1",
             "+" = "turn:-90",
             "-" = "turn:+90"
           ]:
#
# Plot the final state
#
  LSystemPlot(state, actions);

 

 

 

Download dragCurve.mw

You have produced the most garbled, meaningless, code, I have seen in a long time!

Your first code sequence defines a procedure called 'dragon1()' - you then call something called 'dragon()' which is completely undefined! Am I supposed to assume that when you write

dragon(7, 1/4)

you actually want to call the procedure you have defined as dragon1()? If not, please supply code for the procedure dragon()

Actually, you won't get far calling the defined procedure dragon1(). It has multiple instances of unbalanced parentheses (ie '()' ) and brackets ( ie '[]'), as well as incorrect numbers and types of of arguments for the various plot commands which it contains. I'm usually fairly good at guessing what the intention of code might be, but this has so many logical and syntax errors, that I have absolutely no idea what you are trying to achieve. The following is the closest I can get to your original code, which actually executes - although I wouldn't say that it does anything particularly meaningful. It just produces a lot of pretty random plots.

restart;
dragon:= proc( m::integer,k::algebraic)  
               local b,i, p, c;
               uses plots, plottools;  
               p[1]:= plot( [ [0,0],[1-k,0],[1,k],[1,1] ] );  
               c[1]:= circle( [1,0], 0.5, color=blue ); # make this bigger and not "white", just so I can see it
               for i from 1 to m-1 do  
                   b:=[ 2^((i/(2))*cos((i*Pi)/(4))),
                        2^((i/(2))*sin((i*Pi)/(4)))
                      ];  
                   c[i+1]:= circle(b, 0.5, color=blue ); # made bigger just so I can see it
                                                         # Why is this treateed separately
                                                         # from all the other plots in the
                                                         # sequence for p[i+1] - seems perverse
                   p[i+1]:= ( plot
                              ( [ [ b[1],   b[2]-k ], # partially repeated below - why?
                                  [ b[1],   b[2]   ],
                                  [ b[1]-k, b[2]   ]
                                ],
                                color=black
                              ),
                              p[i],                   # why does p[i+1] contain all plots in p[i]?
                                                      # unnecessary repetition?
                                                      #
                              plot                    # looks like repeating part of the first
                              ( [ [b[1],   b[2]-k],   # plot in the p[i+1] sequence - pretty sure
                                  [b[1]-k, b[2]  ]    # this doesn't have to exist
                                ]
                              ),
                              translate
                              ( rotate
                                ( translate
                                  ( p[1],  # p[1]- should this be p[i]?
                                           # but for i>1, p[i] is a whole list
                                           # of plots for which translation might
                                           # be needed on a plot-by-plot basis
                                           # Best leave this untouched
                                   -b[1],
                                   -b[2]
                                  ),
                                  -Pi/2
                                ),
                                b[1], b[2]
                              )
                            );
                od;
                return [ p[m], seq(c[i],i=1..m)];
                end proc:

plots:-display( dragon(7, 1/4) );

 

 

 

Download oddPlot.mw

I did nothing with code you posted as dragon2(), since you chose to post this as a 'picture'. Since it is a 'picture', I can't load it, execute it, or in fact do anything meaningful with it. And I am sure as hell not going to retype it!

LOading code on this site should always be done using the big green up-arrow in the toolbar - that way people like me at least get something we can work with. Uploading 'pictures/images' is just totally useless

 

axiom:="FX":newf:="F":newx:="X+YF+":newy:="-FX-Y":

you define the variables 'axiom', 'newf', 'newx' and 'newy' as various strings. Since none of the variables 'axiom', 'newf', 'newx' and 'newy' are actually used by anything in your subsequent code, all of these definitions are totally and completely pointless

W:=l_system(12);

You define the variable 'W' in terms of the function l_system() evaluated with the argument '12'. Since the function l_system() is undefined in the code you supply, then l_system(12) cannot be evaluated, and hence 'W' is equally undefined. However since 'W' is not actually used anywhere in this code snippet, the fact that it is undefined just makes this line  totally and completely pointless

l:=turtle(0,Pi/2);

The function 'turtle()' is undefined in this code snippet and therefore cannot be evaluated, Hence 'l' is also undefined

In the future, instead of using cut-and-paste to insert more or less meaningless code snippets, I suggest you use the big green up-arrow in the toolbar to upload complete Maple worksheets. That way, somebody here might have some chance of guessing what your problem is

The attached works for me in Maple 2016

  restart;
  kernelopts(version);
  Tetra := proc(verts)
                local a,b,c,d;
                a := verts[1];
                b := verts[2];
                c := verts[3];
                d := verts[4];
                return [a,b,c], [a,b,d], [a,c,d], [b,c,d];
  end:

  Midpoint := proc(a,b)
                   return [(a[1]+b[1])/2, (a[2]+b[2])/2, (a[3]+b[3])/2];
              end:


  Refine := proc(tetra)
                 local a,b,c,d;
                 a:=tetra[1];
                 b:=tetra[2];
                 c:=tetra[3];
                 d:=tetra[4];
                 return [a, Midpoint(a,b), Midpoint(a,c), Midpoint(a,d)],  
                        [b, Midpoint(a,b), Midpoint(b,c), Midpoint(b,d)],
                        [c, Midpoint(c,b), Midpoint(a,c), Midpoint(c,d)],
                        [d, Midpoint(d,b), Midpoint(d,c), Midpoint(a,d)];
            end:

  RefineAll := proc(tlist)
                    return map(Refine,tlist);
               end:  

  Recurse := proc(f, input, n)
                  if  ( n <= 0) then
                       return input;
                  else
                       return Recurse(f, f(input), n-1);
                  fi;
             end:

  FirstT := [[-1,-1,0],[0,sqrt(3)-1,0],[1,-1,0],[0,sqrt(3)/3-1,2*sqrt(15)/5]]:
  with(plots):
  setoptions3d(axes=none, scaling=constrained,shading=XYZ,style=patch,orientation=[60,48]);
  polygonplot3d(map(Tetra,Recurse(RefineAll,[FirstT],3)));

`Maple 2016.2, X86 64 WINDOWS, Jan 13 2017, Build ID 1194701`

 

 

 


Download sierp.mw

Excerpt from the help for the RootFinding() package (emphasis added)

The RootFinding package is a suite of advanced commands for finding roots numerically. The routines in this package augment the root-finding functionality provided by fsolve, especially with respect to finding several roots concurrently.

Thus the RootFinding:-Analytic() command will numerically attempt to find all complex roots of the function given as its first argument, over the region of the complex plane specified by the subsequent arguments.

This numerical process will work provided the given function is 'analytic'. Roughly speaking, a complex analytic function has a complex derivative at every point of its domain, and in consequence has derivatives of all orders and agreeing with its Taylor series locally. (Wikipedia has a more detailed definition of 'analytic function').

 

1) Why does solve & RootFinding not concur in the case of chek?

RootFinding generates numerical solutions: solve() attempts to find analytic solutions. If you wish to explore the difference between these concepts, consider the problem of 5-th (or higher order) univariate polynomials. There is no known analytic solution - see for example https://en.wikipedia.org/wiki/Quintic_function. However numerical solution can usually be determined. Just because you want a problem to be solved analytically, does meean that it can be done

2) solve seems to overlap the RootFinding solutions ONLY AFTER definition to the parameter values are specified, why is that?

Because as the number of unknowns is reduced, the probability of finding some (but not all?) analytic solutions will (probably) increase. Basically you are making the problem "simpler". Although if you consider the case of the quintic (mentioned above), it doesn't matter whether the coefficients are numeric or symbolic - no analytic solution is possible - however much you want one.

3) Is there a way for the RootFinidng package to express the solutions analytically?

No! RootFinding generates numerical solutions

You have a choice - decide exactly what you want.

Numerical solutions for your problem are trivial to generate. A complete listing of corresponding analytic solutions is (probably?) unobtainable, although you are free to spend the rest of your life lookng for them

called X01A. You do not provide this file. Where does it exist?

I mean that some of the '+' and '-' signs in the second identity were wrong, so I fixed them to match the first identity - vv had also noted this issue

I have no idea why nearly every term got multiplied by '1' - some *feature* of using 2-D input (which as a general rule I never use!). Version without the superfluous '1*' operations is attached below

``

 

 

delta(x, y) = piecewise(x = y, 1, x <> y, 0)

 

 

{x}*is*the*fractional*part*of*x

 

``

 

 

`&Mscr;`(p, q) = {`mod`(p, q)+(1/4)*p*(q-1)}

"`&Dscr;`(p,q)="
1-delta({(1/4)*p}, 0)-delta({(1/4)*q}, 0)+delta({(1/4)*q}, 0)*delta({(q-1)*(1/4)}, 0)+1/2*(delta({(q-2)*(1/4)}, 0)+delta({(1/4)*q}, 0)-delta({(q-2)*(1/4)}, 0)*delta({(q-3)*(1/4)}, 0))

 

For*all*odd*primes*p, q

 

WHEN ALL TERMS ARE PLACED ON THE LHS AND 0 ON THE OTHER, THE OUTPUT PLACES ALL p,q IN THE SET T, AS I EXPECTED.

restart; S := {}; with(combinat); with(numtheory); T := {}; F := {}; C := {}; AlphaTotal := {}; BetaTotal := {}

delta := proc (x, y) options operator, arrow; piecewise(x = y, 1, x <> y, 0) end proc

Identity := proc (p, q) options operator, arrow; frac(`mod`(p, q)+(1/4)*p*(q-1))+delta(frac((1/4)*p), 0)+delta(frac((1/4)*q-1/4), 0)-delta(frac((1/4)*q), 0)*delta(frac((1/4)*q-1/4), 0)+(1/2)*delta(frac((1/4)*q-1/2), 0)+(1/2)*delta(frac((1/4)*q-3/4), 0)-(1/2)*delta(frac((1/4)*q-1/2), 0)*delta(frac((1/4)*q-3/4), 0)-1 = 0 end proc

GenerateOddPrimeNumberPairs := proc (N) options operator, arrow; choose([seq(ithprime(k), k = 2 .. N)], 2) end proc

AssignToTrueOrFalseSet := proc (x, y) global T, F; if is(Identity(x, y)) = true then T := `union`({[x, y]}, T) else F := `union`({[x, y]}, F) end if end proc

QueryIdentity := proc (N) local P, k; P := GenerateOddPrimeNumberPairs(N); for k to nops(P) do AssignToTrueOrFalseSet(P[k][1], P[k][2]) end do end proc

QueryIdentity(20); T; F

BUT WHEN THE EQUALITY IS DEFINED AS FOLLOWS, SOME RESULTS ARE PLACED IN THE F SET. (INDICATING THE EQUALITY FOR ALL [p,q] is FALSE)

restart; S := {}; with(combinat); with(numtheory); T := {}; F := {}; C := {}; AlphaTotal := {}; BetaTotal := {}

delta := proc (x, y) options operator, arrow; piecewise(x = y, 1, x <> y, 0) end proc

Identity := proc (p, q) options operator, arrow; frac(`mod`(p, q)+(1/4)*p*(q-1)) = -delta(frac((1/4)*p), 0)-delta(frac((1/4)*q-1/4), 0)+delta(frac((1/4)*q), 0)*delta(frac((1/4)*q-1/4), 0)-(1/2)*delta(frac((1/4)*q-1/2), 0)-(1/2)*delta(frac((1/4)*q-3/4), 0)+(1/2)*delta(frac((1/4)*q-1/2), 0)*delta(frac((1/4)*q-3/4), 0)+1 end proc

GenerateNumberPairs := proc (N) options operator, arrow; choose([seq(ithprime(k), k = 2 .. N)], 2) end proc

AssignToTrueOrFalseSet := proc (x, y) global T, F; if is(Identity(x, y)) = true then T := `union`({[x, y]}, T) else F := `union`({[x, y]}, F) end if end proc

QueryIdentity := proc (N) local P, k; P := GenerateNumberPairs(N); for k to nops(P) do AssignToTrueOrFalseSet(P[k][1], P[k][2]) end do end proc

QueryIdentity(20); T; F

``

Download KDR2.mw

When you say

" I employed the sort command to sort through 10 solutions to a series of order 10 "

There is no sort command in the attached worksheet - clarify your problem

You have written an infinite 'do' loop in the 'proc' option of your examples, for reasons which escape me. If I correct this, then both the procedure and the functional operator version work equally well. Check the following

restart; GeneratePrimeNumberPairs1 := proc (N) combinat:-choose([seq(ithprime(k), k = 2 .. N)], 2) end proc; GeneratePrimeNumberPairs1(10)

restart; with(combinat); GeneratePrimeNumberPairs2 := proc (N) options operator, arrow; choose([seq(ithprime(k), k = 2 .. N)], 2) end proc; GeneratePrimeNumberPairs2(10)

``

Download procFunc.mw

There is absoutely nothing which can be done using arrow notation, which cannot be done by using a procedure - so don't waste your time trying to find something!

My best solution for this is to ignore the 'datatype=sfloat' suggestion I gave you last time(!), and use 'datype=anything'.

With this option, expressions will be returned as strings, but that can be fixed with the careful use of an elementwise 'parse()' statement, as in the following.

Obviously you will have to fix the file path/name to something relevant for your machine

   restart;
#
# Return Version
#
   kernelopts(version);
#
# Generate a vector containging an expression and
# a random 50-digit number, then export it to a
# text file
#
   Digits:=50:
   p:=rand(0.0..1.0):
   V:=Vector( [1234*x+5467, p()]);
   ExportVector( "C:/Users/TomLeslie/Desktop/vectest.txt",
                             V
                         );
#
# Import the same file and parse() anything whose
# datatype is 'string'
#
   fixexpr:= x -> `if`(type(x, string), parse(x), x):
   V2:=fixexpr~( ImportVector
                           ( "C:/Users/TomLeslie/Desktop/vectest.txt",
                               datatype=anything
                          )
                       );

I'm still surprised you had this working "seamlessly" in Maple 18 ?!

is the use of option remember - in the case of the calculating a Fibonacci sequence, it means that for Fib(30), Fib(29) and Fib(28) are known - so calculating Fib(30) becomes trivial.

You will not always achieve improvements like this when using the proc() form rhather than the functional operator form.

My intention was to illustrate that using the proc() form allows more capability for code optimisation than the simple functional operator - you can do just som much more to make your code fast/efficient.

If you don't yet have these, I would recommend downloading/reading the pdf versions of the User and Programming manuals from the MapleSoft website at

https://www.maplesoft.com/documentation_center/

As an example - consider generating the Fibonacci sequence. The attached does this

  1. Using the relevant command from the combinat package - quick/efficient
  2. Using functional operator form, aka arrow notation - slow/inefficient
  3. Using a 'dumb' procedure - equally slow/inefficient
  4. Using a 'clever' procedure - about as quick/efficient as (1) above

  restart:

#
# Generate the first 'n' Fibonacci numbers
# using the relevant command, form the
# combinat package - on the basis that the
# underlying code was written by someone at
# MapleSoft, and so is (presumably) pretty
# efficient. Check the resource usage/time
# etc
#
  n:=30:
  printf("\n\n\n Using command from combinat()\n\n"):
  CodeTools:-Usage(seq(combinat:-fibonacci(j), j=1..n));
#
# Do the same thing with a functional operator.
# This will probably take a ~5 secs, depending
# on your machine. Note the increase in memory
# used and cpu time
#
  fib:=x->`if`(`or`(x=1, x=2), 1, fib(x-1)+fib(x-2)):
  printf("\n\n\n Using functional operator\n\n"):
  CodeTools:-Usage(seq( fib(j), j=1..30));
#
# Do the same thing with a 'dumb' user-written
# procedure. In terms of time/resources didn't
# gain much/anything over the functional operator
# form
#
  Fibonacci1 := proc( n )
                     if   `or`(n=1, n=2)
                     then return 1
                     else return Fibonacci1(n-1) + Fibonacci1(n-2)
                     fi;
               end proc:
  printf("\n\n\n Using 'dumb' user procedure\n\n"):
  CodeTools:-Usage(seq(Fibonacci1(j), j=1..30));
#
# Do the same thing with a 'clever' user-written
# procedure - check the 'option remember', which
# is what makes the difference. Note that this is
# about as fast/efficient as using the relevant
# command from the combinat() package
#
  Fibonacci2 := proc( n )
                     option remember;
                     if   `or`(n=1, n=2)
                     then return 1
                     else return Fibonacci2(n-1) + Fibonacci2(n-2)
                     fi;
               end proc:
  printf("\n\n\n Using 'clever' user procedure\n\n"):
  CodeTools:-Usage(seq(Fibonacci2(j), j=1..30));




 Using command from combinat()

memory used=109.31KiB, alloc change=0 bytes, cpu time=0ns, real time=1000.00us, gc time=0ns

 

1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040

 




 Using functional operator

memory used=465.35MiB, alloc change=32.00MiB, cpu time=3.98s, real time=4.01s, gc time=0ns

 

1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040

 




 Using 'dumb' user procedure

memory used=465.35MiB, alloc change=0 bytes, cpu time=3.70s, real time=3.71s, gc time=78.00ms

 

1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040

 




 Using 'clever' user procedure

memory used=8.16KiB, alloc change=0 bytes, cpu time=0ns, real time=0ns, gc time=0ns

 

1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040

(1)

 

Download proctest.mw

 

First 100 101 102 103 104 105 106 Last Page 102 of 207