tomleslie

5177 Reputation

15 Badges

9 years, 243 days

MaplePrimes Activity


These are answers submitted by tomleslie

from the relevant help page

Called without arguments, the Date() command returns the current date (and time of day) as reported by the system clock.

although I don't think this handles any kind of "Daylight Saving", for which you might need

Date( 'timezone' = Calendar:-HostTimeZone() );

 

as in the attached (which renders better in a Maple worksheet than it does on ths site)

  with(plots):
  p1:= implicitplot3d( [x^2+y^2+z^2=1, x+y+z=0],x=-1..1, y=-1..1, z=-1..1, color=[red,blue], style=surface, transparency=0.5):
  p2:= intersectplot(x^2+y^2+z^2=1, x+y+z=0, x=-1..1, y=-1..1, z=-1..1, color=green, thickness=4):
  display([p1,p2]);

 

 

 


 

Download iPlot.mw

by using the ScientificConstants() package in Maple, which has all the atomic weights you woukd ever want to know,

Examine the attache

  with(ScientificConstants):
#
# function to return the atomic weight of an element.
# The returned value is in units of 'amu'
#
  gtWeight:= x-> [ x,
                   rhs
                   ( rhs
                     ( GetElement
                       ( x, atomicweight )[2]
                     )[1]
                   )
                 ]:
#
# Return the atomic weight of (say) carbon
#
  gtWeight('C');
#
# Return the atomic weights of the first 12 elements
#
  elems:=[H, He, Li, Be, B, C, N, O, F, Ne, Na, Mg]:
  gtWeight~(elems);

[C, 12.0107]

 

[[H, 1.00794], [He, 4.002602], [Li, 6.941], [Be, 9.012182], [B, 10.811], [C, 12.0107], [N, 14.0067], [O, 15.9994], [F, 18.9984032], [Ne, 20.1797], [Na, 22.989770], [Mg, 24.3050]]

(1)

 

Download atwt.mw

 

is actually the inability to compute the point [0,0] exactly using floating-point arithmetic. For the 7x7 grid, Maple actually calculates the centre point as [1e-10, 1e-10], (rather than [0,0]). Obviously, at the point [1e-10, 1e-10], the field is defined - and is huge, which explains the resulting plot.

Interestingly, for all other "odd" grid settings 3x3, 5x5,9x9, etc etc the origin appears to be calculated as exactly [0,0], whereas one might(??) expect that computing 0 using floating-point arithmetic, would always be a little "doubtful.

More details in the attached

I have converted this from a "post" to a "question"

  restart;
  with(plots):
#
# Illustrate OP's problem - the third plot is "wrong"
#
  expr:=[-x/(x^2+y^2)^1.5,-y/(x^2+y^2)^1.5]:
  fieldplot( expr,
             x = -1..1,
             y = -1..1,
             arrows=thick
           );
  fieldplot( expr,
             x = -1..1,
             y = -1..1,
             grid=[8,8],
             arrows=thick
           );
  fieldplot( expr,
             x = -1..1,
             y = -1..1,
             grid=[7,7],
             arrows=thick
           );

 

 

 

#
# So what is happening??
#
# If one calculates the grid points and the field components
# explicitly for various grid sizes (all with n odd) and then
# selects the "one in the middle", which *ought* to correspond
# to x=0,y=0, where the vector field is undefined, one gets
# the following
#
  seq
  ( [ n,[ seq
          ( seq
            ( [x, y, expr],
              y=-1..1, evalf(2/(n-1))
            ),
            x=-1..1, evalf(2/(n-1))
          )
        ][floor(n^2/2+1)][]
    ],
    n=3..13, 2
  );

[3, 0., 0., [Float(undefined), Float(undefined)]], [5, 0., 0., [Float(undefined), Float(undefined)]], [7, -0.1e-9, -0.1e-9, [0.3535533906e20, 0.3535533906e20]], [9, 0., 0., [Float(undefined), Float(undefined)]], [11, 0., 0., [Float(undefined), Float(undefined)]], [13, 0., 0., [Float(undefined), Float(undefined)]]

(1)

#
# In the above command, the floating-point calculation does
# produce [0,0] as a grid point for all grid sizes, other than
# n=7. When the grid point is *exactly* [0, 0], then the value
# of the vector field is [Float(undefined), Float(undefined)].
#
# However when n=7, rather than using the grid point [0, 0], the
# calculated grid point is at [-1.*10^(-10), -1.*10^(-10)], where
# the field is defined (but huge)
#
# The default for fieldplot() is to illustrate field strength
# with the *relative* drawn length of the arrows. The computed
# field strength at [-1.*10^(-10), -1.*10^(-10)] is so huge
# that the "relative" length of the arrows at all other grid
# points is essentially zero, and cannot be seen in the plot
#

#################################################################
#
# Workaround, define a "tolerance" around [0,0], within which
# the field strength is delared as undefined
#
  tol:= 1e-06:
  func1:= (p, q)->`if`( `and`( abs(p) < tol,
                               abs(q) < tol
                             ),
                        Float(undefined),
                        eval( expr[1], [x=p, y=q] )
                     ):
  func2:= (p, q)->`if`( `and`( abs(p) < tol,
                               abs(q) < tol
                             ),
                        Float(undefined),
                        eval( expr[2], [x=p, y=q] )
                      ):
#
# Now fieldplots work "correctly"
#
  fieldplot( [ func1,func2 ],
             x = -1..1,
             y = -1..1,
             arrows = thick
           );
  fieldplot( [ func1, func2 ],
             x = -1..1,
             y = -1..1,
             grid = [8,8],
             arrows = thick
           );
  fieldplot( [ func1, func2 ],
             x = -1..1,
             y = -1..1,
             grid = [7,7],
             arrows = thick
           );
                    

 

 

 

 

Download fplotProblem.mw

There are some weird non-printing, non-ASCII characters in the file name - I don't know why., These have to be removed in order for everything to work as you expect, See the attached

  restart;
  interface(version);
  with(StringTools):
#
# NB the string in the following is cut+paste from
# OP's worksheet in order to "preserve" any weird
# (eg non-printing?) characters
#
  a:="Microsoft_Edge_‎08_‎29_‎2019.html";
#
# and yes, Reverse() goes nuts!
#
  Reverse(a);
#
# Filter out non-ASCII characters
#
  b:=Implode(select( IsASCII, Explode(a)));;
#
# Now Reverse() works
#
  Reverse(b);

`Standard Worksheet Interface, Maple 2019.1, Windows 7, May 21 2019 Build ID 1399874`

 

"Microsoft_Edge_‎08_‎29_‎2019.html"

 

"lmth.9102���_92���_80���_egdE_tfosorciM"

 

"Microsoft_Edge_08_29_2019.html"

 

"lmth.9102_92_80_egdE_tfosorciM"

(1)

 

 


 

Download strProb.mw

is that the statement 1C=1K is perfectly valid if one is thinking of temperature increments.

However the statement 1C=274.15K is equally valid if one is thinking of "absolute" values - and believe me I hesitated before using the term "absolute", because of the possibility of confusing the word "absolute" with the kelvin temperatue scale.

So faced with the problem that 1C=1K and 1C=274.15K are equally valid, how does one combine temperatures from different scales. By default, Maple uses the former (which you may think is incorrect - but frankly I think is a 50:50 call). If you want to add temperatures from different "scales" in some kind of "absolute" sense, then you should (probably) use convert commands, as in the attached.

One think you should be careful about is the occurence of "zero" on any temperature scale. Whislst it is true that "0 inches" is equal to "0 metrres", it is obviously not true that 0C=0F=0K. However (probably as a result of Maple's simplification rules), a "0" with any temperature unit, returns a "unitless" zero. This has pretty mindblowing consequences, because (as shown in the attached)

is( 0*Unit(Celsius)=0*Unit(Fahrenheit));

will return true!!! Now I'd call that a BUG.

combine(20*Unit(Celsius)+30*Unit(K),units);

50*Units:-Unit(K)

(1)

convert(20*Unit(Celsius,preserve),temperature, kelvin)+ 30*Unit(K);
evalf(%);
20*Unit(Celsius)+convert(30*Unit(kelvin, preserve), temperature,Celsius);
evalf(%);

(6463/20)*Units:-Unit(K)

 

323.1500000*Units:-Unit(K)

 

-(4463/20)*Units:-Unit(`&deg;C`)

 

-223.1500000*Units:-Unit(`&deg;C`)

(2)

is( -1*Unit(Celsius)=-1*Unit(Fahrenheit));
is( 0*Unit(Celsius)=0*Unit(Fahrenheit));
is( 1*Unit(Celsius)=1*Unit(Fahrenheit));

false

 

true

 

false

(3)

 


 

Download tempTrouble.mw

 

Only workaround I can come up with is

  1. Select the lprint() output
  2. Right-click to pull up the context menu, then use Convert To -> Plain Text.
  3. Then the usual CTRL-C/CTRL-V

This works for me in the attached


 

restart:
kernelopts(version);
interface(prettyprint);
lprint(<1,2;3,4>);

`Maple 2019.1, X86 64 WINDOWS, May 21 2019, Build ID 1399874`

 

3

 

Matrix(2,2,{(1, 1) = 1, (1, 2) = 2, (2, 1) = 3, (2, 2) = 4},datatype = anything
,storage = rectangular,order = Fortran_order,shape = [])

 

Matrix(2,2,{(1, 1) = 1, (1, 2) = 2, (2, 1) = 3, (2, 2) = 4},datatype = anything
,storage = rectangular,order = Fortran_order,shape = []);

Matrix(2, 2, {(1, 1) = 1, (1, 2) = 2, (2, 1) = 3, (2, 2) = 4})

(1)

 


 

Download lpr.mw

From the help for AllPairsDistance

This procedure is an implementation of the Floyd-Warshall all-pairs shortest path algorithm

However this i only a partial step on the way to computing the "betweenness centrality", because

  1. The basic algorithm outputs only the distance - not the path itself (ie the intermediate vertexes)
  2. To compute the betweenness centrality, one needs to find all the paths with the same shortest distance between each two vertexes.

see the attached

  restart:

  with(combinat):
  randomize():
#
# r1() and r2() are used to construct non-zero
# random numbers in the range -10..-1, 1..10
#
  r1:=rand(0..1):
  r2:=rand(1..10):
#
# r3() provides random numers in the range
# -10..10 (so 0 is possible)
#
  r3:=rand(-10..10):
#
# Generate 3 non-zero random numbers, then
# 7 other random numbers. Produce a random
# permutation of the resulting 10  numbers.
#
# Repeat 10 times, once for each row of the
# matrix
#
  Matrix
  ( [ seq
      ( randperm
        ( [ seq
            ( (2*r1()-1)*r2(),
              j=1..3
            ),
            seq
            ( r3(),
              j=1..7
            )
          ]
        ),
        k = 1..10
      )
    ]
  );

Matrix(10, 10, {(1, 1) = 6, (1, 2) = -2, (1, 3) = -2, (1, 4) = 10, (1, 5) = 9, (1, 6) = -6, (1, 7) = 1, (1, 8) = -2, (1, 9) = 8, (1, 10) = -8, (2, 1) = 3, (2, 2) = -7, (2, 3) = -6, (2, 4) = -9, (2, 5) = 8, (2, 6) = -6, (2, 7) = 10, (2, 8) = -2, (2, 9) = 4, (2, 10) = -1, (3, 1) = -7, (3, 2) = -9, (3, 3) = -4, (3, 4) = -4, (3, 5) = 1, (3, 6) = -9, (3, 7) = -1, (3, 8) = -8, (3, 9) = -1, (3, 10) = -8, (4, 1) = 2, (4, 2) = -6, (4, 3) = -3, (4, 4) = 2, (4, 5) = 10, (4, 6) = -6, (4, 7) = 1, (4, 8) = 0, (4, 9) = 3, (4, 10) = 5, (5, 1) = -4, (5, 2) = 7, (5, 3) = 10, (5, 4) = -3, (5, 5) = 0, (5, 6) = -2, (5, 7) = 2, (5, 8) = 8, (5, 9) = 9, (5, 10) = -1, (6, 1) = 5, (6, 2) = -3, (6, 3) = -7, (6, 4) = -3, (6, 5) = 10, (6, 6) = -5, (6, 7) = -1, (6, 8) = 9, (6, 9) = -8, (6, 10) = -1, (7, 1) = -2, (7, 2) = 1, (7, 3) = 4, (7, 4) = 9, (7, 5) = -2, (7, 6) = -7, (7, 7) = 7, (7, 8) = 9, (7, 9) = 1, (7, 10) = -9, (8, 1) = -8, (8, 2) = -2, (8, 3) = 0, (8, 4) = 10, (8, 5) = -2, (8, 6) = 3, (8, 7) = -8, (8, 8) = -7, (8, 9) = 2, (8, 10) = 3, (9, 1) = 10, (9, 2) = 8, (9, 3) = -9, (9, 4) = -5, (9, 5) = 5, (9, 6) = 1, (9, 7) = -2, (9, 8) = -2, (9, 9) = -10, (9, 10) = -6, (10, 1) = 5, (10, 2) = 8, (10, 3) = -9, (10, 4) = -6, (10, 5) = 7, (10, 6) = 9, (10, 7) = -4, (10, 8) = 3, (10, 9) = 7, (10, 10) = 9})

(1)

 

 

 


 

Download nearlyRandMat.mw

what is "known" and what is "unknown" in this problem. Under the assumbtion that slope and intercept of the line to be fitted is known, as well as the standard deviation of the noise term, then the attached may be useful

It constructs x-values, then "noisy" y-values, then fits this noisy data to a simple linear model. So it *should* return the slope and intercept of the equation used to generate it - but of course it won't *quite*. The quality of the fit will depend on how many samples and the standard deviation of the noise term.

Anyhow, fo what it is worth, check the attache

  restart;
  with(Statistics):
  with(plots):
  randomize():
#
# generate Nsamp "possible" x-values - actual values are
# arbitrary
#
  Nsamp:=100:
  X:=[seq(j, j=0..Nsamp-1)]:
#
# Define slope and intercept, again values are
# arbitrary
#
  slope:=2:
  cept:=-3:
#
# Define a zero-mean normal random variable with standard
# deviation given by sigma and get "Nsamp" samples from
# this distribution
#
  sigma:=5.0:
  noise:=Sample( RandomVariable(Normal(0, sigma)), Nsamp):
#
# Construct "noisy" Y-values
#
  Y:=[seq( slope*X[i]+cept+noise[i], i=1..Nsamp)]:
#
# Fit a linear model to the noisy data [X, Y]
#
  feq:=Fit(a+b*x, X, Y, x);
#
# Plot "noisy" points and fitted line
#
  display( [ pointplot( X, Y, symbol=solidcircle, symbolsize=12),
             plot( feq, x=X[1]..X[Nsamp])
           ]
         )
  
  

-HFloat(2.6283217482495957)+HFloat(1.9841870915256559)*x

 

 

 


 

Download regTest.mw

Well your original worksheet (ie code1.mw ), has a PDE whose solution requires four boundary conditions and two initial conditions, but you only supplied four boundary constions and one initial condition (most of which were syntactically incorrect!) so, rather obviously, this problem cannot be solved,

You latest worksheet ( ie code.mw ) has a PDE whose solution requires four boundary conditions and two initial conditions, but contains no initial/boundary conditions at all, so, rather obviously,, this problem cannot be solved either. However the text accompanying, this worksheet "specifies" (I use the word loosely),

the boundary conditions are:

w(0,t)=0
wx(0,t)=0
wxx(L,t)=0
wxxx(L,t)=0

 

and the initial conditions are:

 

w(x,0)=0
wt(x,0)=0

If I interpret these correclty, and insert them into your worksheet, then the PDE can be solved (numerically) as shown in the attached.

Do I believe this solution???? Probably no!. The value w(x,t) grows so rapidly as a function of time, that it is diffciult to envisage this PDE+conditions reperesenting any "real-world" phenomenon. With this caveat, the attached shows a plot of w(x,t), over the range x=0..L, t=0..1, as well as a couple of plots for x=10, t=0..1 and x=20, t=0..1 just to demonstrtae the "explosive" growth in the function w(x,t).
Obviously all sorts of other plots/values could be generated - but since I have no ide what you want........ anyhow for what it is worth, check the attached

restart:

E := 210: D_0 := 4: d_0 := 2.56: d := (D_0 + d_0)/2:
L := 63:x_c := L/2:I_0 := x -> 1/4*Pi*(D_0^4 - d_0^4):
rho := 7850:A_0 := x -> 1/4*Pi*((D_0 - d_0)*x_c/L + d)^2:
mt := 99.32:mc := 54.5:mh := 39:mb := 30:nb := 3:g := 9.8:
p := (mb*nb + mc + mh + mt)*g:rhoA := 1.2:VA := 12:ct := 1.6:
Ab := 60:

PDE := diff(E*I_0(x)*diff(w(x, t), x $ 2), x $ 2) + rho*A_0(x)*diff(w(x, t), t $ 2) - p*diff(w(x, t), x $ 2) = 1/2*rhoA*VA^2*ct*Ab*nb:
bcs:=w(0,t)=0, D[1](w)(0,t)=0, D[1,1](w)(0,t)=0, D[1,1,1](w)(0,t)=0:
ics:=w(x,0)=0, D[2](w)(x,0)=0:
sol:=pdsolve(PDE, [bcs,ics], numeric, range=0..L, time=t):
sol:-plot3d( w, x=0..L, t=0..1);
sol:-plot( w, x=10, t=0..1);
sol:-plot( w, x=20, t=0..1);

 

 

 

 

 

Download solPDE.mw

 

 

Whichone you select depends precisely on what you plan on doing with these vectors.

The attached shows one(simple)  possibility

  restart;
  with(VectorCalculus):

  f:=(l, theta)->[ l*sin( convert(theta*degrees, radians)),
                   l*cos( convert(theta*degrees, radians))
                 ]:
  V0:= RootedVector(root=[0,0], [0,1]):
  V1:= RootedVector(root=[0,0], f(1, 30)):
  V2:= RootedVector(root=V1, f(3/2, 60)):
  PlotVector( [V0, V1, V2],
              color=[red, blue, green],
              width=[0.03, relative=false],
              head_length=[0.2, relative=false],
              axes=nnone
            );

 

 


 

Download simpleVects.mw

- and there are many others!

NB the 3-d plot looks better in a worksheet than it does on this site (which apparently(?) can't deal with the "transparency" option)

  restart;
  with(geom3d):
#
# Cylinder definition
#
  cylR:=3:
  cylH:=2:
#
# Define four points - using symmetry
#
  point(a,  x1,  sqrt(cylR^2-x1^2), 0):
  point(b,  x1, -sqrt(cylR^2-x1^2), 0):
  point(c, -x1, -sqrt(cylR^2-x1^2), cylH):
  point(d, -x1,  sqrt(cylR^2-x1^2), cylH):
#
# determine 'x1' so that length ab is the
# same as length ac
#
  assign(solve([x1>0, distance(b,c)=distance(a,b)], x1));

#
# Get coordinates of a, b, c, d
#
  coordinates~([a, b, c, d])[];
#
# check edge lengths
#
  distance(a, b), distance(b, c), distance(c, d), distance(d, a);
#
# Check diagonals are the same length
#
  distance(a, c), distance(b, d);

[2, 5^(1/2), 0], [2, -5^(1/2), 0], [-2, -5^(1/2), 2], [-2, 5^(1/2), 2]

 

2*5^(1/2), 2*5^(1/2), 2*5^(1/2), 2*5^(1/2)

 

2*10^(1/2), 2*10^(1/2)

(1)

#
# Draw the construction
#
  segment(sab, [a, b]):
  segment(sbc, [b, c]):
  segment(scd, [c, d]):
  segment(sda, [d, a]):
  p1:= draw([sab, sbc, scd, sda], color=black):
  p2:= plottools:-cylinder([0,0,0],3,2, color=red, style=surface, transparency=0.9):
  plots:-display([p1, p2], view=[-5..5, -5..5, -5..5]);

 

 


 

Download sqCyl.mw

when I look at this question, and your previous question posted here

https://www.mapleprimes.com/questions/227697-Help-Plots-Gridlines

I think you might want something like the attached

  restart;
  with(plots):
  with(plottools):
  sol:=solve( [ x^2-y=0, y-(x+5)=0],
              [x, y],
              explicit
            ):
  f:= x-> line([rhs~(x[1]),rhs~(x[2])][], color=red):
  display( [ inequal( [ x^2-y<0,
                        y-(x+5)<0
                      ],
                      x=-4..4,
                      y=0..10,
                      color=white
                    ),
             textplot( [ [ rhs~(sol[1])[],
                           "A",
                           align=right
                         ],
                         [ rhs~(sol[2])[],
                           "B",
                           align=left
                         ]
                       ],
                       font=[times, bold, 18]
                     ),
             seq( f( solve
                     ( [ x^2-y=0, (y+i)-(x+5)=0],
                         [x, y],
                         explicit
                     )
                   ),
                  i=0..5, 0.5
                )
           ],
           size=[600, 600]
         );

 

 

NULL

Download inegplot2.mw

 

 

to your original code, one can produce the attached

with(plottools):
with(plots):
display( line([.8, 0], [1, .2], color = red),
         line([.6, 0], [1, .4], color = red),
         line([.4, 0], [1, .6], color = red),
         line([.2, 0], [1, .8], color = red),
         line([ 0, 0], [1,  1], color = red),
         line([0, .2], [.8, 1], color = red),
         line([0, .4], [.6, 1], color = red),
         line([0, .6], [.4, 1], color = red),
         line([0, .8], [.2, 1], color = red),
         rectangle([0, 1], [1, 0], color=white, thickness = 1),
         axes=none
       )

 

 

Download chat.mw

 

 

3 4 5 6 7 8 9 Last Page 5 of 115