tomleslie

13876 Reputation

20 Badges

15 years, 164 days

MaplePrimes Activity


These are answers submitted by tomleslie

and possible typos, that it is almost impossible that I have fixed them all correctly.

The combination of 2-D math input and 'exotic' naming conventions (eg inert subscripts which themselves contain inert subscripts, and inert subscripts which contain mathemetical symbols) make this worksheet almost impossible to comprehend.

A few brief points

  1. nu__beta, I__beta__T, and theta are all assigned, but these assignments are never used - so why do they exist
  2. There are a couple of places where an 'overdot' is being used which (obviously) is being interpreted as a derivative with respct to time - somehow I doubt this is the intent
  3. There are a couple of places where sin(psi+pi) and cos(psi+pi) are used. Lower-case pi is just a Greek letter with no particular significance. I have assumed that you actually wish to refer to the ratio of circumference to diameter - which would be Pi

The following code (also in the attachment badInt.mw where color highlighting has been used to indicate the most significant changes) is at least syntactiically correct, although the final result (ie the evaluated integrals) is probably too long/complicated to be of much use to a human reader - still with 22 variables I suppose that is to be expected!

  restart;
#
# As in the Op's original nu__beta is defined here, but never
# subsequently used - so why does this assignment exist in the
# OP's original?
#
  nu__beta:= sqrt
             ( 1 + 2*R^2*int( m__d*(4*beta*e__us*r - 2*e__us^2),
                              r = 0..1
                            )/I__beta__T
             ):
#
# As in the Op's original I__beta__T is defined, but never
# subsequently used - so why does this assignment exist in the
# OP's original?
#
  I__beta__T:= 2*R^2*int( m__d(-2*beta__p*e__us*r + e__us^2 + r^2),
                          r = 0..1
                        ):
#
# As in the Op's original theta is defined, but never
# subsequently used - so why does this assignment exist in the
# OP's original?
#
  theta:= theta__0 + A__1c*cos(psi) + B__1s*sin(psi):

  beta:= beta__0 + beta__1c*cos(psi) + beta__1s*sin(psi):
#
# The term r*beta (highlighted below) is problematic in the
# OP's original, where it appears more as rbeta with an overdot
# signifying differentiation with respect to time. No idea
# what the OP meant, so the following contains the simple
# product, which is the most likely(?) possibility
#
  alpha__psi:= simplify(   theta__0 
                         + (r/R - e__T)*theta__T 
                         + A__1*cos(psi)
                         + B__1*sin(psi)
                         - (lambda__1__psi*Omega*R + r*beta + beta*mu*Omega*R*cos(psi))
                           /
                           (Omega*r + mu*Omega*R*sin(psi))
                       ):
#
# See remark above about the term r*beta
#
# OP has used cos(phi+pi) and sin(psi+pi). I have assumed that
# in these expressions the OP wants to refer to ratio between
# circumference and diameter, which would be Pi. The greek letter
# pi is just that, a letter with no other significance. Changes
# highlighted
#
# OP also appears to want to include a mathematical symbol in an
# "inert" subscript - ie psi+pi. The only way I know to do this
# is to envlose the whole name in backticks. Note that any time
# this quantity is subsequently used, the backticks will be
# necessary - which is just asking for trouble!!
# 
  `alpha__psi+pi`:= simplify(   theta__0 
                              + (r/R - e__T)*theta__T
                              + A__1*cos(psi + Pi)
                              + B__1*sin(psi + Pi)
                              - (`lambda__1__psi+pi`*Omega*R + r*beta + beta*mu*Omega*R*cos(psi))
                                /
                                (Omega*r + mu*Omega*R*sin(psi))
                            ):
   F__z__psi:= simplify(1/2*rho*(Omega*r*R)^2*c*a__s*alpha__psi):
#
# Same problem as above with a mathematical symbol in an inert
# subscript - same solution
#
  `F__z__psi+pi`:= simplify(1/2*rho*(Omega*r*R)^2*c*a__s*`alpha__psi+pi`):

   F__r__psi:= simplify(-1/2*rho*(Omega*r*R)^2*c*a__as*beta*alpha__psi):
#
# Same problem as above with a mathematical symbol in an inert
# subscript - same solution
#
  `F__r__psi+pi`:= simplify(-1/2*rho*(Omega*r*R)^2*c*a__as*beta*`alpha__psi+pi`):

#
# In order to display the following expression in a way which
# easy to check, inert integrals have been used, together with
# uneval quotes around the quantities F__z__psi, `F__z__psi'+pi`,
# F__r__psi and `F__r__psi+pi`. Note also the backticks around the
# second and fourth of these
#
  RHS:= R/(I__beta*Omega^2)*(   Int( 'F__z__psi'*(r - (beta__p*r - e__us)*beta__T),
                                     r = 0..1
                                   )
                              - Int( '`F__z__psi+pi`'*(r+(beta__p*r - e__us)*beta__T),
                                     r = 0..1
                                   )
                              - Int( 'F__r__psi'*((beta__T + beta__p)*r - e__us),
                                     r = 0..1
                                   )
                              + Int( '`F__r__psi+pi`'*((beta__T-beta__p)*r + e__us),
                                     r = 0..1
                                   )
                            );
#
# Use the value command to convert the inert integrals in the
# above to 'live' integrals. This produces a complicated nested
# piecewise expression which is too long to be of any interest
# to a human reader. The piecewise expressions only appear to be
# defined when 
#
#  0 < -sin(psi)*R*mu < 1
#
  simplify(eval(value(%)));

 

you can use various commands from the DynamicSystems package (as suggested by nm) - this may be "overkill".

The only real problem I see with your original worksheet is that by using square brackets ( ie '[]') around an expression you have converted it to a list datatype containing a single expression. Subsequent commands do not respond well to receiving a 'list' when they expect a simple 'expression'

The attached simply removes the offending '[]' and plots the simple magnitude of the resulting expression, to produce

Obviousy you can do this in decibels if you want ( as in 20*log10(mag) ) or whatever. Anyhow see the attached

tf.mw

 

 

the first thing you should try to undertsand is the difference between an equation and an assignment.

After that there arestill  assorted syntax and logic errors. Assorted fixes (with comments) are shown in the attached

  restart;
  with(Units[Standard]):
  with(ScientificConstants):
  local I;
#
# Define magbteic field - units should be 'tesla'
#
  B:=0.5*Unit(tesla);
#
# Define the charge on the electron, Get this from
# the Sicentific constants package, and make sure it
# comes with units -which should be coulombs
#
  q:= evalf(Constant(e, units));
#
# 'n' is the number of carries per unit volume so it
# has units of 1/(volume) - and the OP appears to want
# to use litres as volume, which is fine (although I'm
# a cubic metres person myself!)
#
  n:= 0.15*100000/Unit(litre);
#
# 'd' has a units of lenght - so using micron is fine
#
  d:= 10*Unit(micron);
#
# I is a current with units of 'amperes'
#
  I:= 0.1*10^(-5)*Unit(ampere);
#
# Compute the Hall vooltage - if God is in his heaven
# should have ubits of volts (which it does!
#
  Vh := B*I/(q*n*d);

which (amongst other things) produces the output

Vh := 2.080503043*10^10*Unit('V')

See the attached hall.mw  if you want to play with anything. Don't worry about the warning message

Warning, The imaginary unit, I, has been renamed _I

This just reflects the fact (by default) Maple uses 'I' to represent the sqare root of ( -1) so  using 'I' as some other variable (in your case current) can be (slightly) problematic.

 

 

do you want to specify RKF4 or indeed convert your BVP to an IVP (ie use a shooting method)?

In the attached odeProb.mw I have used 10 as an approximation for infinity, which appears to correspong to the pdf figure which you uploaded.

This produces the following plots

 

to be in any particular order, so the plot looks pretty random. The code

with(plots):
pts:= Matrix( [ [ 19.8, 12,    1.62 ],
                [ 24.7, 14,    1.2  ],
                [ 26,   16,    1.25 ],
                [ 35.1, 20,    0.84 ],
                [ 37.8, 20.83, 0.74 ],
                [ 10.8, 9,     3.98 ],
                [ 16.1, 12,    2.46 ],
                [ 38.3, 18,    0.52 ],
                [ 24.5, 16,    1.42 ],
                [ 15.8, 11,    2.35 ],
                [ 28.2, 17.8,  1.19 ],
                [ 56.8, 27,    0.37 ],
                [ 25.4, 17,    1.34 ],
                [ 29.3, 18.1,  1.12 ]
             ]
           ):
  display( [ pointplot3d
             ( pts,
               symbol=solidsphere,
               symbolsize=20,
               color=red
             ),
             pointplot3d
             ( pts,
               style=line,
               color=blue,
               thickness=5
             )
           ],
           labels=["X", "Y", "Z"],
           labelfont=[times, bold, 16]
         );

proiduces the plot

See the attached plot3.mw

but if you want to list the divisors of an integer 'n', then use the

NumberTheory:-Divisors(n)

command. This will return 'n' itself as a divisor, which yu do nt consider 'proper'. So if you want only proper divisors, then use

NumberTheory:-Divisors(n)[1..-2]

You state that your algorithm takes ~18secs to compute the proper divisors of 17^6. The NumberTheory:-Divisors() command will return the same answer in 5ms.

If you want to know how many divisors you have when when you construct a number as a product of primes, then this is a simple combination problem, so you can use the combinat:-numbcomb() command. This command will count the "empty combination" and the "all entries" combination, neither of which is a "proper" divisor. It will not include the value '1' which is a "proper" divisor. So logically, you need

combinat:-numbcomb([ p1, p2, p3,......pN]) - 2 +1= combinat:-numbcomb([ p1, p2, p3,......pN]) - 1

See the \attached for some examples

Download prims.mw

The following code

  restart;
  with(plots):
#
# Generate some random points
#
  r:= rand(-10.0..10.0):
  npts:= 100:
  pts1:= [seq( [r(), r()], n=1..npts)]:
#
# Compute the complex hull of these points
#
  lv:= ComputationalGeometry:-ConvexHull(pts1):
#
# Draw the original points and those on the polygon
# forming the complex hull
#
  display
  ( plot
    ( pts1[ convert( {$i=1..npts}
                     minus
                     convert(lv, set),
                     list
                   )
          ],
      style=point,
      symbol=solidcircle,
      symbolsize=16,
      color=blue
    ),
    plot
    ( [ pts1[lv][], pts1[lv[1]] ],
      style =pointline,
      symbol=solidcircle,
      symbolsize=16,
      color=red
    )
  );

produces the following figure

See the attached

ch.mw

 

 

 

I suspect you have not implemented Acer's suggetions correctly
 

Download anim.mw

yuo have to supply numeric values for all 'parameters' Your system contains 'k', 'lambda' and 'inifinity'. In the attached I have provided (arbitrary) numeric values for these quantities.

I also fixed a couple of typos.

  restart;
  with(plots):
  sys:= f(x) - x*diff(f(x), x) - 3*diff(g(x), x) = 0,
        f(x)^2 - f(x)*diff(f(x), x)*x + 3*g(x)*diff(f(x), x) = 3*diff(f(x), x $ 2) + 18*k*diff(f(x), x$2)*diff(f(x), x)^2,
        3*diff(h(x), x)*f(x) - diff(h(x), x)*f(x)*x + 3*g(x)*diff(h(x), x) = diff(h(x), x $ 2):
  bcs := f(0) = lambda,
         g(0) = 0,
         f(infinity) = 0,
         h(0) = 1,
         h(infinity) = 0:
  dsys := eval({bcs, sys}, [k = 2, lambda = 1, infinity = 5]):
  dsol := dsolve(dsys, numeric):
  odeplot( dsol,
           [ [x, f(x)],
             [x, g(x)],
             [x, h(x)]
           ],
           color=[red, green, blue]
         );

which produces

 

 

Download odeProb.mw

as the most "rediscovered" property of primes. Consider

  1. Any number greater than 5 can be written (modulo 6) as n=0, 1, 2 ,3, 4, 5 modulo 6
  2. Any number  greater than 5 which satisfies n=0,  2,  4 modulo 6 is even, so cannot be prime.
  3. Any number  greater than 5 which satisfies n=3 modulo 6, is divisible by 3 so cannot be prime.
  4. Hence prime greater than 5, can be written as either
    1. n=1 modulo 6: in other words it is 6*r+1, for some integer r
    2. n=5 modulo 6: in other words it is 6*r+5, which can also be written as 6*(r+1)-1, ie 6*q-1
  5. Hence any prime greater than 5 is of the form 6*r+1 or 6*r-1

is just to define a siimple function - see the attached

  restart;
  with(Logic):
  local O:
  P1 := (&not O) &and (&not C) &implies (&not Q);
#
# The contrapositive of
#
#    A -> B
#
# is
#
#   (not B) -> (not A)
#
# so define a function which performs this
#
   CP:= pr-> BooleanSimplify( &not op(2, pr) )
             &implies
             BooleanSimplify( &not op(1, pr) ):
#
# Contrapositive of P1
#
   CP(P1);

logic1.mw

Looks like the inline display is broken on this site again :-(

I agree with your remarks about the second question - the output of

Canonicalize(P5, {O, C, Q}, form=MOD2)

js just wrong!

 

if I fix a couple of typos to remove some discontinuities in the function definition, and to ensure that i i defined for all values of the parameter 'A' in the range -6..6, then restructure the code a bit, I come up with the attached. Be aware that the animation is not as "smooth" as I would expect, even when I use a frame count whihc means that the file is too big for the animation to display inline on this site.


Download anim.mw

is shown in the attached

  restart:
  aProc:=  proc()
                local j:
                unapply
                ( piecewise
                  ( x<=0,
                    0,
                    seq( [x<j*h, _passed[j]][], j=1.._npassed),
                    0
                  ),
                  x, h
                );
           end proc:
          

  B[0]:=  (1/6)*x^3/h^3:
  B[1]:=  (1/6)*(4*h^3-12*h^2*x+12*h*x^2-3*x^3)/h^3:
  B[2]:= -(1/6)*(44*h^3-60*h^2*x+24*h*x^2-3*x^3)/h^3:
  B[3]:=  (1/6)*(64*h^3-48*h^2*x+12*h*x^2-x^3)/h^3:

  func:= aProc( entries(B, nolist, indexorder));
  func(4,2);

func := proc (x, h) options operator, arrow; piecewise(x <= 0, 0, x < h, (1/6)*x^3/h^3, x < 2*h, (1/6)*(4*h^3-12*h^2*x+12*h*x^2-3*x^3)/h^3, x < 3*h, -(1/6)*(44*h^3-60*h^2*x+24*h*x^2-3*x^3)/h^3, x < 4*h, (1/6)*(64*h^3-48*h^2*x+12*h*x^2-x^3)/h^3, 0) end proc

 

2/3

(1)

  B[0]:=  (1/24)*x^4/h^4:
  B[1]:= -(1/24)*(5*h^4-20*h^3*x+30*h^2*x^2-20*h*x^3+4*x^4)/h^4:
  B[2]:=  (1/24)*(155*h^4-300*h^3*x+210*h^2*x^2-60*h*x^3+6*x^4)/h^4:
  B[3]:= -(1/24)*(655*h^4-780*h^3*x+330*h^2*x^2-60*h*x^3+4*x^4)/h^4:
  B[4]:=  (1/24)*(625*h^4-500*h^3*x+150*h^2*x^2-20*h*x^3+x^4)/h^4:
 
  func:= aProc( entries(B, nolist, indexorder));
  func(4,2);

func := proc (x, h) options operator, arrow; piecewise(x <= 0, 0, x < h, (1/24)*x^4/h^4, x < 2*h, -(1/24)*(5*h^4-20*h^3*x+30*h^2*x^2-20*h*x^3+4*x^4)/h^4, x < 3*h, (1/24)*(155*h^4-300*h^3*x+210*h^2*x^2-60*h*x^3+6*x^4)/h^4, x < 4*h, -(1/24)*(655*h^4-780*h^3*x+330*h^2*x^2-60*h*x^3+4*x^4)/h^4, x < 5*h, (1/24)*(625*h^4-500*h^3*x+150*h^2*x^2-20*h*x^3+x^4)/h^4, 0) end proc

 

11/24

(2)

 

Download pwFunc.mw

 

when plotting/manipulating more-or-less standard geometric objects, it is usually a good idea to check out the plottools() package.

See the attached

  with(plots):
  with(plottools):
  display
  ( reflect
    ( hemisphere
      ( [0, 0, 0],
        3
      ),
      [0,0,0]
    ),
    style=surface,
    scaling=constrained,
    axes=boxed,
    color=red
  );

 

 


Download hemi.mw

 

From the Excel help

Formula

Description

Result

=MROUND(10, 3)

Rounds 10 to the nearest multiple of 3.

9

=MROUND(-10, -3)

Rounds -10 to the nearest multiple of -3.

-9

=MROUND(1.3, 0.2)

Rounds 1.3 to the nearest multiple of 0.2.

1.4

=MROUND(5, -2)

Returns the #NUM! error message because -2 and 5 have different signs.

#NUM!

Unfortunately

  1. The code supplied by CarlLove requires the second argument to be positive, which the Excel MROUND() command does not require
  2. The code supplied by vv, "works" when the two arguments are of opposite sign - which it shouldn't

It is trivial to fix either of the above. One way is in the attached

  restart;
  MROUND := (x,m) -> `if`( signum(x)=signum(m),
                           round(x/m)*m,
                           "Error must be same sign"
                         ):
  MROUND(10,3);
  MROUND(-10,-3);
  MROUND(1.3,0.2);
  MROUND(5, -2);

9

 

-9

 

1.4

 

"Error must be same sign"

(1)

 

Download mround.mw

First 46 47 48 49 50 51 52 Last Page 48 of 207