tomleslie

13876 Reputation

20 Badges

15 years, 165 days

MaplePrimes Activity


These are answers submitted by tomleslie

On the other hand, when you issue the command

plot(Vector([1, 3, 4, 6]), Vector([8, 6, 2, 5]), style = point, symbol = asterisk, color = blue)

Maple will plot the points whose x-values is given by the contents of the first vector and whose y-coordinates are given by the corresponding entry of second vector. In othe words Maple will plot the points

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

You then have to decide what "symbol" you want to place at these points. You (currently) have a choice of

asterisk, box, circle, cross, diagonalcross, diamond, point, solidbox, solidcircle, soliddiamond.

You can also change the 'size' of the symbol with the option symbolsize=someNumber, and the color of the symbol with color=

Reading thre help page

?plot/options

in particular the sub-entries for 'symbol', 'symbolsize' and 'color' may be instructive

 

it is relatively simple to detect the name of the environment being being used, and thus substitute for it.

Download here

odeProb.mw

On a more general point the 'linalg' package has been deprecated since Maple 6 released in 1999. So you a using a package which was superseded 22 years ago. Unless you only have access to a seriously old Maple version, I'd rewrite using the LinearAlgebra() package

although (for reasons unknown) this only works with 1-D input :-(

Consider the picture below

Or try the attached warning.mw

 

the code

  restart;
#
# Procedure which does the work
#
  Duhamel:= proc( F::Array, t::Array, omega::numeric, m::numeric )
                  local  u:= Array(1..1,0),
                         A:= Array(1..1, 0),
                         B:= Array(1..1, 0),
                         j, dt;
                  for j from 2 by 1 to numelems(F) do
                      dt:= t[j]-t[j-1];
                      A(j):= A[j-1]+dt*(F[j-1]*cos(omega*t[j-1])+F[j]*cos(omega*t[j]))/2:
                      B(j):= B[j-1]+dt*(F[j-1]*sin(omega*t[j-1])+F[j]*sin(omega*t[j]))/2:
                      u(j):= (A[j]*sin(omega*t[j])+B[j]*cos(omega*t[j]))/m/omega:
                  od:
                  return eval(u);
            end proc:
#
# Construct an Array 'F' which contains random
# values in the arrange -1..1, and 't' which
# contains equally-spaced values
#
  nel:=2688:
  randomize():
  r:= rand(-1.0..1.0):

  F:= Array(1..nel, i-> r() ):
  t:= Array(1..nel, i-> (i-1)/1000.0 ):
#
# Run the procedure with the above F, t and
# omega=1, m=1
#

  ans:=Duhamel( F, t, 1, 1):
#
# Idle curiosity, plot the generated array as a
# function of index
#
  plots:-listplot(ans);

which is also given in the attached

duHam.mw

 

 

 

 

 

shown here

  restart;
  with(orthopoly):
  f:=diff( P(n, cos(theta)), theta, theta);
  int( convert( eval( f, n=2 ), diff), theta=0..Pi/4);

produces the answer -3/2. Is that what you are after?

 

 

 

The term 'Dag' in Maple-speak is an acronym for Directed Acyclic Graph.  As the help states,

All data in Maple is stored as a directed acyclic graph (DAG). An identifying tag for each DAG indicates what type of data it stores and how it is stored. Names, strings, lists, and positive and negative integers are examples of some DAG types

However DAGS are very much an internal Maple data structure of which the user should be blissfully unaware. Getting a DAG-related error is very, very unusual. This is why you have been asked to upload the code which generates the error (along with your OS).

The simple way to upload your code is to

  1. save the worksheet which producces the error
  2. Upload the worksheet using the big green up-arrow in the Mapleprimes toolbar

Just to demonstrate som thoughts on your problem, consider the worksheet below

balllsNtubes.mw

I'm unclear what you are trying to achieve, so the code in this file, replicated below

  restart;              
#
# Some utilities
#
# This one plots a "tube" between the points 'p1' and 'p2',
# of radius 'r'
#
  tubes:= proc( p1::list, p2::list, r::numeric, col::name)
                uses plots:
                local j:
                return tubeplot
                       ( [seq( p1[j]+(p2[j]-p1[j])*t, j=1..3)],
                         t=0..1,
                         radius=r,
                         tubepoints=20,
                         scaling=constrained,
                         style=surface,
                         color=col
                       );
          end proc:
#
# This one plots a ball with centre at'p1' of radius 'r'
#
  balls:= proc( p1::list, r::numeric, col::name)
                uses plottools:
                return sphere
                       ( p1,
                         r,
                         color=col,
                         style=surface
                       );
          end proc:
               

#
# generate a more or less arbitrary list of points
# where 'balls" are to be placed
#
  L1:=[ seq
        ( [5*cos(theta),5*sin(theta), 2*theta],
          theta=evalf(-Pi)..evalf(Pi), evalf(Pi/10)
        )
      ]:
#
# Plot of these 'balls' on a vertical stick
#
  plots:-display
         ( seq
           ( tubes( L1[j], [L1[j][1..2][],0], 0.1, blue),
             j=1..numelems(L1)
           ),
           seq
           ( balls( L1[j], 0.1*(j-numelems(L1)/2), red),
             j=1..numelems(L1)
           )
         );
#
# Plot of connected adjacent "balls"
#
  plots:-display
         ( seq
           ( tubes( L1[j], L1[j+1], 0.1, cyan),
             j=1..numelems(L1)-1
           ),
           seq
           ( balls( L1[j],  0.1*(j-numelems(L1)/2), yellow),
             j=1..numelems(L1)
           )
         );

shows two possibilities

  1. The first is a group of "balls" with vertical tubes to the plane z=0
  2. The second is the same group of "balls, with adjacent "balls" connected by tubes

so it produces the plots

These plots are generated  in an "efficient" manner. Your original code which produces a "ball" by using an implicitplot() command with numpoints= 100000 is just an ABSOLUTELY, HORRIBLY, INEFFICIENT way to produce a decent-looking "ball"

 

 

 

 

anim.mw

The attached uses the animate() command with the 'background' option, which is probably a better choice when it is relatively simple to parameterize the animation. It also means that teh 'backgroundonly has to be calculated once, rather than for each frame

The display() command with the 'insequence=true' is best restricted to cases where a simple parameterization is not possible,

if one only has to deal with "simple" cases.

Consider the "toy" example in the code

  restart;
  toPol:=z->simplify(mul(denom~([op([1..2], z)]))*z);

  eqns:=[ (a*x__1+b*x__2)/x__3+r*x__1^2/(e*x__2+d)=f,
           p*x__3/(q*x__1^2+r)+x__2=(s*x__1+x__2)/(t*x__3+u)
        ];

  toPol~(eqns);

which produces

So the function toPoly() *appears* to peform the transformation you want.

Beware -it *might* meed a little tuning in order to work on all possible equations!!

An obvious(?) issue (I think) would be if any denominator contained a rational fractional, in which case some kind of recursive application might be necessary

 

 

is given by

  restart;
  with(GraphTheory):
#
# Construct a random adjacency matrix representing an
# undirected, unweighted graph
#
  randomize():
  r:= rand(0..1):
  nVert:= 20:
  M:= Matrix( nVert,
              nVert,
              (i,j)-> `if`( i<j, r(), 0),
              shape=symmetric
            ):
#
# Construct the corresponding graph
#
  G1:= Graph(M):
#
# Utility which accepts two integers v1, v2 (vertices) and
#
#  1. checks that {v1, v2} is an edge
#  2. counts the number of vertices j in G1 for which
#
#     Distance(G1, v1, j) < Distance(G1, v2, j),
#
#     (excluding the case where j=v1)
#
  dist:= ( v1::integer, v2::integer)
          ->
          local j;
          `if`
          ( member
            ( {v1, v2},
              Edges(G1)
            ),
            add
            ( `if`
              ( `and`
                ( j<>v1,
                  Distance(G1, v1, j) < Distance(G1, v2, j)
                ),
                1,
                0
              ),
              j in Vertices(G1)
            ),
            `not an edge`
          ):
#
# Check some pairs of vertices
#
  dist(3, 9);
  dist(9, 3);
  dist(1, 3);

see also the attached

dist.mw

As you have stated, and I can verify, matrixplot() with both the options

heights=histogram, color=red

works as expected in Maple 2015, but produces a "deep black" plot in all subsequent releases up to and including Maple 2020.1.

I will submit an SCR.

The best I can come up with is a workaround using plottools:-cuboid(), which appears to function as desired, at least for simple cases, using the code

#
# Workaround: define a function which accepts a
# matrix and a "simple" color specification, then
# uses plottools:-cuboid() to "spoof" a 3-D
# histogram
#
  mhist:=( mat::Matrix,
           col::string
         ) -> [ seq
                ( seq
                  ( plottools:-cuboid
                    ( [ i-1, j-1,   0     ],
                      [  i,   j, mat[i,j] ],
                      color=col
                    ),
                    i=1..op([1,1], mat)
                  ),
                  j=1..op([1,2],mat)
                )
              ]:
  plots:-display( mhist(A, "X11 Thistle1" ));

which produces the figure below.

 

See also the attached

mathist.mw

 

 

 

The code below is a bit "ugly" but I haven't got time right now to do "pretty" - and in any case it seems to "work"

 

  restart;
  with(ArrayTools):
  with(ListTools):
  with(plots):
#
# Op's original sequence as an array
# (for test purposes)
#
  opArr:=Array([1,0,1,2,1,2,2,1,3,1,2,4,1,3,5,1,3,3,1,3,2,10,5.]):
#
# Initialise the output array (including
# number of term to compute)
#
  nVals:=100:
  a:=Array(1..nVals):
  a[1]:=1: a[2]:=0:
#
# Do the calculation
#
  for j from 3 to nVals do
      if   not member( a[j-1], a[1..j-2])
      then a[j]:= min(abs~(a[1..j-2]-~a[j-1]))
      else a[j]:=(j-1)-max(SearchAll( a[j-1], convert(a[1..j-2], list)));
      fi;
  od;
#
# Verify that computed array agrees with OP's
# original (up to the number of terms in OP's
# original)
#
  IsEqual( opArr, a[1..numelems(opArr)]);
#
# Examine/plot the generated Array
#
  a;
  listplot(a, style=point, symbol=solidcircle, color=red);

generates the sequence

[1, 0, 1, 2, 1, 2, 2, 1, 3, 1, 2, 4, 1, 3, 5, 1, 3, 3, 1, 3, 2, 10, 5, 8, 2, 4, 14, 4, 2, 4, 2, 2, 1, 14, 7, 1, 3, 17, 3, 2, 8, 17, 4, 13, 1, 9, 1, 2, 8, 8, 1, 4, 9, 7, 19, 2, 8, 7, 4, 7, 2, 5, 39, 20, 1, 14, 32, 7, 8, 12, 1, 6, 1, 2, 13, 31, 1, 4, 19, 24, 4, 3, 43, 4, 3, 3, 1, 10, 66, 23, 1, 4, 8, 24, 14, 29, 2, 23, 8, 6],

which *appear*s to be correct, together with the plot

See the attached

oddSeq.mw

 

 

 

 

are shown in the following

  restart:
  u[0] := x->exp(-x^2);
#
# One way
#
  for j from 1 to 10 do
      u[j]:=D(u[j-1]);
  od;
#
# Another way
#
  for j from 1 to 10 do
      u[j]:=(D@@j)(u[0]);
  od;

Both of which produce

 

 

is shown in the attached

#
# The OP's original problem
#
  restart;
  with(LinearAlgebra):
  Sx:=1/sqrt(2)*Matrix([[0,1,0],[1,0,1],[0,1,0]]):
  lam,v:=Eigenvectors(Sx):
  `<|>`(Normalize~([Column(v, 1..-1)],2)[]);
#
# Some general "toy" examples using functions on rows
# (or columns) or functions on rows+row elements (or
# columns and column elements)
#
  M:=RandomMatrix(3);
  `<|>`(Normalize~([Column(M, 1..-1)],2)[]);
  `<,>`(Normalize~([Row(M, 1..-1)],2)[]);
  `<|>`((z->z^~2/add(z))~([Column(M, 1..-1)],2)[]);
  `<,>`((z->z^~2/add(z))~([Row(M, 1..-1)],2)[]);

rowCol.mw

but the way to do it is shown in the attached

restart;
assume(c1, real);
interface(showassumed = 0);

pde1 := diff(u1(r, z), r) + u1(r, z)/r + diff(w1(r, z), z) = 0;
expand(subs(u1(r, z) = c1*r*U(z) + u(r, z), pde1));

pdeSub.mw

 

is with the code

  restart;
  kernelopts(version);
  eq:=diff( (1/2)*sin(2*alpha)+cos(alpha)*sqrt( sin(alpha)^2+1), alpha)=0;
  solve(%);
  sin~({%})[];

which also produces (1/3)*sqrt(3)

BTW you shouldn't add a new question, when it is a simple extension of a previous question

First 53 54 55 56 57 58 59 Last Page 55 of 207