tomleslie

13876 Reputation

20 Badges

15 years, 163 days

MaplePrimes Activity


These are answers submitted by tomleslie

exavtly what you want.

Maybe what is shown in the attached?

cheb.mw

as in the attached, which unfortunately will not display "inline" on this site because that capability seems to be currently broken

Download convU.mw

There is no Matlab code - pretend that you are a random user and want to download the MAtlab code you "posted" - Did it work?

With many restrictions, the place to start this kind of code conversion is

  1. You have some Matlab code in the form of an m-file - let's call it myMatlabCode.m
  2. In Maple you try Matlab:-FromMFile(myMatlabCode.m, options)

So if I'm not missing something - what is wrong with a simple printf() command as in the attached.

Sorry this cannot be displayed inline. It appears that some lamebrain at Maple has been working on this site (again) and broken the inline display (again). On past performance this fault won't be fixed for a week or so!!

Does no-one ever test software updates any more?

Download sciPrint.mw

You can fairly easily produce a "prime frequency" plot - up to a certain point where just generating the primes takes too much time to be interesting/useful

For example the attached shows the number of primes divided into bins of 1000, up to a maximum value of 10000000. I guess that you could conclude that this graph "settles down" to around 70 primes/1000. (For some reason this site will not display the contents of this file "inline" - I have no idea why!)

Download primeFreq.mw

Note that the this is restricted to primes with 7 or fewer digits. The latest Mersenne prime (according to https://oeis.org/A000043) has 12978189 digits - so we are not even in the same ballpark/country/planet/solarsystem.

The number of atoms in the universe only has around 80 digits - so a Mersenne prime with 12978189 digits has to be considered really really, REALLY big - beyond human imagination

 

is to use op(2, expr), as shown in the attached

In Maple the parentheses {} and [] have special meanings, The former delimits a mathematical set, and the latter a list. Do not use these purely for "grouping" terms in simple mathematiccal expressions - use only ()

  op(2, a^x);
  op(2, Y[1,3]^(-1/3));
  op(2, Y[1,3]^a);

x

 

-1/3

 

a

(1)

 

Download expo.mw

from wikipedia, my highlighting

A monomial, also called power product, is a product of powers of variables with non-negative integer exponents

So anything which contains sqrt(t),( ie t1/2) cannot be a monomial because the variable t has a non-integer exponent

 

A warning:- I'm not very good at Graph Theory!

The attached defines a function which returns all vertex cut sets, using an exhaustive search, along with  couple of examples. As is always the case with exhaustive enumeration, this may (will?) become prohibitly expensive for "large" graphs.

  restart;
  with(GraphTheory):
#
# A couple of "test" graphs
#
  G1:= Graph({{1,2},{1,3},{2,3},{1,4},{3,4},{4,5},{5,6},{4,6}}):
  G2:= CompleteGraph(2,2,2,2):
#
# Function to exhaustively enumerate all vertex cut sets
#
  cv:= grph-> local j;
              [ seq
                ( `if`
                  ( not IsConnected(DeleteVertex(grph, j)),
                    j,
                    NULL
                  ),
                  j in combinat:-choose
                                 ( numelems(Vertices(grph)),
                                   VertexConnectivity(grph)
                                 )
                )
              ]:

#
# For graph G1, get all the vertext cut sets
#
  v:=cv(G1);
#
# Draw graph G1 with the vertex cut set highlighted
#
  HighlightVertex(G1,v[]);
  DrawGraph(G1);
  

[[4]]

 

 

#
# For graph G2, get all the vertex cut sets
#
  v:=cv(G2);
#
# Draw graph G2 with one of the vertex cut sets highlighted
#
  HighlightVertex(G2,v[1]);
  DrawGraph(G2);

[[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 7, 8], [1, 2, 5, 6, 7, 8], [3, 4, 5, 6, 7, 8]]

 

 

 

Download vCutSet.mw

why the command GraphTheory:-VertexConnectivity() does not provide the answer you seem to want.

The attached worksheet contains

  1. A "simple" example from the VertexConnectivity help page where the removal of a single node (I'd say node 4) renders the graph disconnected
  2. The example you provide,ie  ie CompleteGraph(2,2,2,2); where it is necesary to remove six nodes to disconnect the graph. I wouldn't like to have to prove it, but from teh "symmetry" of the graph, I'm guessing any six out of the eight vertexes would work

So what else do you need? What else does Mathematica provide?

  restart;
  with(GraphTheory):
  G := Graph({{1,2},{1,3},{2,3},{1,4},{3,4},{4,5},{5,6},{4,6}});
  DrawGraph(G);
  VertexConnectivity(G);

GRAPHLN(undirected, unweighted, [1, 2, 3, 4, 5, 6], Array(1..6, {(1) = {2, 3, 4}, (2) = {1, 3}, (3) = {1, 2, 4}, (4) = {1, 3, 5, 6}, (5) = {4, 6}, (6) = {4, 5}}), `GRAPHLN/table/1`, 0)

 

 

1

(1)

  restart;
  with(GraphTheory):
  G:=CompleteGraph(2,2,2,2):
  DrawGraph(G);
  VertexConnectivity(G)

 

6

(2)

 

Download VertConn.mw

from your wiorksheet before saving and the message will go away.

You should only get this message when you are saving a worksheet with output.

BTW for this example, if you do save the worksheet with output, the resulting file isn't big -about 22kB on my machine

for giving the impressions that most ODEs have an exact solution. The reverse is true. Very few ODEs have an exact solution and for the others, numeric methods are necessary. As in the attached

odeNum.mw

use the built-in command? Of course you can write your own. Both are shown in the attached.

  restart;
  f:=t->cos(t):
#
# "Do-it-yourself" Taylor series
#
  term:= (var, ind, pt)-> (var-pt)^ind*(D@@ind)(f)(pt)/ind!;
  add( term(x, j, 0), j=0..10);
#
# Or use the built-in command
#
  taylor(f(x), x=0, 11);
  convert(%, polynom);

proc (var, ind, pt) options operator, arrow; (var-pt)^ind*((D@@ind)(f))(pt)/factorial(ind) end proc

 

1-(1/2)*x^2+(1/24)*x^4-(1/720)*x^6+(1/40320)*x^8-(1/3628800)*x^10

 

series(1-(1/2)*x^2+(1/24)*x^4-(1/720)*x^6+(1/40320)*x^8-(1/3628800)*x^10+O(x^12),x,12)

 

1-(1/2)*x^2+(1/24)*x^4-(1/720)*x^6+(1/40320)*x^8-(1/3628800)*x^10

(1)

 

Download tayl.mw

I find that massaging a maple expression into a "different" but equivalent form is a bit of a waste of time. For any particular example, it can usually be achieved, but the same method applied to a slightly different example may fail. It also has a nasty habit of producing quite a complicated sequence of commands - so i it worth the effort?

Having said that, your second example ("factoring" the quadratic can be done as shown in the attached.(and there are probably many alternatives!)

BTW I don't think you can disable automatic simplification so that a*a will be of type '^' rather than type '^'

  expr:=a*x+6*x^2-10;
  add(simplify~(add~([selectremove( j->has(j, x), [op(expr)])])));

a*x+6*x^2-10

 

-10+x*(a+6*x)

(1)

 

Download manip.mw

simultaneously expect to be able to set the value of 'w' as a user-controlled parameter for explore, and also define it as one of the plot ranges, ie w= -dia/2..dia/2

Fix this and everything seems to work - see the attached

 restart:
 S := (w, dia) -> w*(dia^2 - w^2):
 cplot := [sqrt(-ww^2 + (dia/2)^2), -sqrt(-w^2 + (dia/2)^2)]:
 d:=sqrt(dia^2 - w^2):
 with(plots):
 Explore
 ( display
   ( [ plot
       (cplot,
        ww= -dia/2..dia/2,
        color=blue,
        scaling=constrained
        ),
       plot
       ( 1/2*~[-w, -w, w, w, -w],
         1/2*~[-d, d, d, -d, -d],
          title=typeset( "w= %1, dia=%2, Strength = %3", w, dia, S(w, dia)),
          caption=typeset( "Opt w=", evalf(dia/sqrt(3.))),
         scaling=constrained
       )
     ]
   ),
   parameters=[   w= 0.0..10.0,
                  dia=0.0..20.0
              ],
   initialvalues=[ w=6.0,
                   dia=12.0                    
                 ]    
 );

Download explt.mw

Or isn't using the command PointInPolygon() just a bit simpler?

As in the attached

  restart:
  with(plots):
  with(plottools):
  with(ComputationalGeometry):
#
# Define the polygon
#
  poly:=[[0,0],[200,0],[200,300],[250,400],[500,300],[500,500],[0,500]]:
#
# A couple of point , one inside, one outside
#
  apt:=[100,400]: #a point inside the polygon
  bpt:=[300,300]: #a point outside the polygon
#
# Check whether points are inside or outside
#
  PointInPolygon( apt, poly );
  PointInPolygon( bpt, poly );
#
# Draw the situation as a simple visual check
#
  display( [ polygon(poly, color=yellow),
             point(apt, symbol=solidcircle, symbolsize=24, color=red),
             point(bpt, symbol=solidcircle, symbolsize=24, color=blue)
           ]
         );

"inside"

 

"outside"

 

 

 

Download ptPoly.mw

First 36 37 38 39 40 41 42 Last Page 38 of 207