tomleslie

13876 Reputation

20 Badges

15 years, 168 days

MaplePrimes Activity


These are answers submitted by tomleslie

If you are planning to plot points, gernerating two tables probably isn't the best way to start, since you will have to convert these tables to lists or vectors - but it can be done. See the attached

Probably better to generate two lists directly which makes plotting them 'simpler' -see the second approach in the attached


 

restart

delta := .5; for n to 10 do alpha[n] := 1/(1+n); D1[n] := product(3*delta*alpha[k]-alpha[k]+1, k = 1 .. n)-product(1-alpha[k]*(1-delta), k = 1 .. n) end do; plot([entries(alpha, 'nolist')], [entries(D1, 'nolist')])

1/2

 

.5000000000

 

1/3

 

.8333333340

 

1/4

 

1.093750001

 

1/5

 

1.312500001

 

1/6

 

1.503906250

 

1/7

 

1.675781250

 

1/8

 

1.832885742

 

1/9

 

1.978352865

 

1/10

 

2.114364624

 

1/11

 

2.242507934

 

 

restart

delta := .5; N := 10; alpha := [seq(1/(1+j), j = 1 .. N)]; D1 := [seq(product(3*delta*alpha[k]-alpha[k]+1, k = 1 .. j)-product(1-alpha[k]*(1-delta), k = 1 .. j), j = 1 .. N)]; plot(alpha, D1)

[1/2, 1/3, 1/4, 1/5, 1/6, 1/7, 1/8, 1/9, 1/10, 1/11]

 

[.5000000000, .8333333340, 1.093750001, 1.312500001, 1.503906250, 1.675781250, 1.832885742, 1.978352865, 2.114364624, 2.242507934]

 

 

 


 

Download twoplots.mw

The characters you are using as "angle brackets" looks odd and as far as I can tell isn't ascii - was it entered from the keyboard? See also comments in the attached - whihc works

  restart;
  with(VectorCalculus):
  SetCoordinates('cartesian'[x, y, z]):
#
# Op's original defintion for this was
#
# F:=VectorField(Cy,-x,0D);
#
# The "angle bracket" characters look
# odd - no idea how they were inserted
# and they aren't even ASCII?
#
  StringTools:-IsASCII( C );
  StringTools:-IsASCII( D );

false

 

false

(1)

#
# Either of the following work. If you
# want to use angle brackets these should
# be the greater/lessthan keyboard characters
#
  F:=VectorField(<y,-x,0>);
  F:=VectorField([y,-x,0]);

Vector(3, {(1) = y, (2) = -x, (3) = 0})

 

Vector(3, {(1) = y, (2) = -x, (3) = 0})

(2)

 

Download angbra.mw

 

is that the command

LinearAlgebra:-DeleteRow()

accepts a vector, but will return (1-dimensional) matrix.

You have every right to ask, what is the difference between a vector and a 1-D matrix!! Unfortunately, some other commands which accept a vector, will not accept a 1-dimensional matrix.

I agree with CarlLove that you are doing  this the "hard way". I'm also curious as to whether you actually want VectorCalculus:Norm(), rather than LinearAlgebra:-Norm() - but only you know this!

See the attached

  restart;

  A:= Vector[column](5, [x, y, z, w, 1]);
  whattype(A);
  B:= LinearAlgebra:-DeleteRow(A, LinearAlgebra:-RowDimension(A));
  whattype(B);

Vector(5, {(1) = x, (2) = y, (3) = z, (4) = w, (5) = 1})

 

Vector[column]

 

Matrix(%id = 18446744074371480742)

 

Matrix

(1)

  VectorCalculus:-Norm( A[..-2] );
  LinearAlgebra:-Norm( A[..-2], 2, conjugate=false);

(w^2+x^2+y^2+z^2)^(1/2)

 

(w^2+x^2+y^2+z^2)^(1/2)

(2)

 


 

Download doNorm.mw

Which treats the coordinate transformation slightly differently (and more intuitively?)

Note that with the coordinate definition used in the attached, the "at-rest" pendulum is hinged at [0,0,l] with its free end at [0,0,0]. This appears(?) to correspond to the definition given in the pdf supplied by the OP.

In Carl's answer it is hinged at [0,0,0] with its end at [0,0,-l]. The difference between the two solutions is just a translation along the z-axis - so not really significant!

  restart;

#
# Parameters
#
  l:=1:
  g:= 9.8:
#
# Odes and initial conditions: the latter are
# arbitrarily chosen
#
  odes:= diff(theta(t),t$2) = diff(phi(t),t)^2*sin(2*theta(t))/2 - g*sin(theta(t))/l,
         diff(phi(t),t$2) = -2*diff(theta(t),t)*diff(phi(t),t)*cot(theta(t)):
  ics:= phi(0)=0, D(phi)(0)=1, theta(0)=Pi/3, D(theta)(0)=0.1:
#
# the coodinate transformation from
#
#  [l, phi(t), theta(t)] -> [x, y, z]
#
  f:= tau-> [ l*sin(theta(tau))*cos(phi(tau)),
              l*sin(theta(tau))*sin(phi(tau)),
              l*(1-cos(theta(tau)))
            ]:
#
# Animate the solution
#
  plots:-odeplot
         ( dsolve({odes, ics}, numeric),
           f(t),
           t=0..10,
           frames=100,
           labels=[x,y,z]
         );

 

 


 

Download conPend.mw

  1. Don't use square brackets (ie'[]') just to group terms of an expression. In Maple square brackets are reserved to designate/access elements of indexable quantity
  2. In general you should avoid using square brackets (ie '[]') just to provide a convenient subscript for a variable name. If yuo want an inert subscript use a double undesrscore instead ie a__1, rather than a[1]
  3. Your first equation contains many terms wich look a bit like Wy6(py1-py0) Now is that the (undefined) function Wy6() with the argument py1-py0 or is it the product of the quantities Wy6 and py1-py0 ???? If the latter, then either
    1. insert an explict multiplication sign where required
    2. if you plan to use the "implied mulitplication feature of 2-D input then you need a space between the term being multiplied - ie  Wy6 (py1-py0) rather than Wy6(py1-py0Difficult to spot the difference isn't it, which is why I'm not a fan
  4. Given that your expression starts with a factor of 1/2, I don't think that the answer you want is 2 Wy6 py1-2 Wy6 py10 I'm guessing it should be Wy6 py1- Wy6 py10 Even this answer implies that in (3) above, you generally have ,ultiplication rather than function application.
  5. Diff() with a capital D is the innert differentiation command - pretty sure you don't want that

In the attached I have fixed many (but not all, particularly the subscripts issue) and (maybe) I get the desired(?) answer although I have made too many guesses about yur intent to be confident

J__y := 1/2*(W__y1(a[c]^y-(diff(S[1](t), t, t))^y)^2+W__y2*((diff(S[1](t), t))^y)^2+W__y3*(S[1]^y)^2+W__y4*(`#mscripts(mi("&phi;",fontstyle = "normal"),mi("c"),none(),none(),mo("&period;"),none(),none())`-`#mscripts(mi("&phi;",fontstyle = "normal"),mi("S"),none(),none(),mo("&period;"),none(),none())`)^2+W__y5*`&phi;__S`^2+W__y6*(p__y1-p__y10)^2+W__y7*(p__y2-p__y20)^2+W__y8*(p__y3-p__y30)^2+W__y9*(p__y4-p__y40)^2)

(1/2)*W__y1(a[c]^y-(diff(diff(S[1](t), t), t))^y)^2+(1/2)*W__y2*((diff(S[1](t), t))^y)^2+(1/2)*W__y3*(S[1]^y)^2+(1/2)*W__y4*(`#mscripts(mi("&phi;",fontstyle = "normal"),mi("c"),none(),none(),mo("&period;"),none(),none())`-`#mscripts(mi("&phi;",fontstyle = "normal"),mi("S"),none(),none(),mo("&period;"),none(),none())`)^2+(1/2)*W__y5*phi__S^2+(1/2)*W__y6*(p__y1-p__y10)^2+(1/2)*W__y7*(p__y2-p__y20)^2+(1/2)*W__y8*(p__y3-p__y30)^2+(1/2)*W__y9*(p__y4-p__y40)^2

(1)

diff(J__y, p__y1)

W__y6*(p__y1-p__y10)

(2)

``

Download bitOfAMess.mw

 

 

First of all read https://en.wikipedia.org/wiki/Lint_(software) which states

lint, or a linter, is a tool that analyzes source code to flag programming errors, bugs, stylistic errors, and suspicious constructs

The Maple LInt operation is accessed using mint, wmint or maplemint - depending on usage details. My own opinion on "linters" is that this is not (usually) the best way to pick up basic syntax errors. In most(?) programming languages, basic syntax errors will be reported by a compiler/linker/parser/interpreter, without resoting to the 'linter' for the particular programming language.

My own use of linting, is generally to check for the last couple of items in the above Wikipedia extract. This immediately gets one into an argument about what constitutes a "stylistic error" or a "suspicious construct" - since neither of these are necessarily syntactically incorrect.

Since one is checking code (which may be syntactically correct), I am usually quite tolerant about the exact location where the 'linter' reports an issue - but I do like to check the issues!

In the example you supplied, the 'linter' actually returned two "complaints"

    |\^/|      Maple 2020 Diagnostic Program
._|\|   |/|_.  Copyright (c) Maplesoft, a division of Waterloo Maple Inc. 2020
 \  MINT   /   All rights reserved. Maple is a trademark of
 <____ ____>   Waterloo Maple Inc.
      |        
on line     7:     z:=cat("A
                          ^ Syntax error
A "then" was found without a previous matching "if".
An "end" may be needed to close the "in" construct from line 3.

Procedure foo( x ) on lines 1 to 9 of foo.mpl
  These local variables were assigned a value, but otherwise unused:  z

The first issue relates to your use of multiline strings - anyy 'linter' which didn't flag this piece of code isn't worthy of the name. Whether you regard this as a "syntax error", a "stylistic error", or a "suspicious construct" for me is a bit academic - Just don't do it!

The second issue is also interesting, since your code has the line

local z := ""

Why did you initialise 'z' to an empty string, when the only time 'z' is used in your procedure is when it is assigned to something completely different: thus the initialization is pointless: so not syntactically incorrect - but stylistically?, or suspicious?

 to define this function would be

f:=x-> x^5+2*x^3+3 ;

but according to you original question, you are required to enter the part of your Maple command that is to the right of the ":=", so examining the above carefully, that would be

x-> x^5+2*x^3+3 ;

And then you are further required to Do not include the semi-colon (";") at the end. so again, really complicated, serious thought would result in

x-> x^5+2*x^3+3

I mean - how difficult can this get?

 

because (pedantically) a set should only contain unique elements - and it shouldn't matter what the elements are! So I would see this as a shortcoming of Maple.

Having said that, it is pretty simple to work around. There is little point in using any kind of 'set' construction, because the uniquification property of a set (disappointingly) isn't going to happen for a set of vectors. So (purely as a workaround) I'd probably end up with something like the attached

  restart:
  m:=5;
  with(LinearAlgebra):
  with(ListTools):
  with(LinearAlgebra[Modular]):
  n:= 10:
  M:= Matrix([[3, 4*168], [4,3]]);
  L:= Matrix([[3],[4]]);
  K:= Array(0..n, i->Mod(m,(M^i).L,integer)):
  K:= Array(MakeUnique([entries(K, 'nolist')],1, (i,j)->Equal(i,j)));

m := 5

 

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

 

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

 

Array(%id = 18446744074370503734)

(1)

 

Download uniquify.mw

 test:= proc(x):
             return x+1, x^2:
        end proc:
  A,B:=test(y);
  A:=test(y)[1];
  B:=test(y)[2];

y+1, y^2

 

y+1

 

y^2

(1)

 

Download retVals.mw

by entering

?->

at the Maple prompt

is shown in the attached

  restart:
  with(plots):
  L1:=sort( [fsolve( x^8-1-I,x)],
            (j,k)-> arctan(Im(j), Re(j)) > arctan(Im(k), Re(k))
          ):
  L2:= [ L1[], L1[1] ]:
  display( [ complexplot
             ( L2,
               style=point,
               symbol=solidcircle,
               symbolsize=24,
               color=red
             ),
             complexplot
             ( L2,
               color=blue,
               thickness=3
             )
           ],
           gridlines=true
         );

 

 

NULL


 

Download cmplPlot.mw

It *seems* easy to include units in calculations, but most software I have used are either

  1. too simple to include all unit possibilities
  2. too complicated for anyone to sensibly use

Maple is no exception - I would say that it falls into the second catgory above. By attempting to cover absolutely all possibilities of units, it becomes infuriatingly difficult to use.

My only recommendation would be to split the problem into two parts

  1. There is a system of equations whihc do not require any units at all - so write these in a unit free way
  2. For specific values, one or more of the above equations have to be evaluated with a given set of parameters, each of whihc may have an associated unit. So set up a list of parameters (with explicitly declared units) and use expressions of the form eval(systemProperty, parameters) where necessary

See the examples in the following

  restart;
#
# Set up Units
#
  with(Units[Natural]):
  UseSystem(SI);
#
# Set up system parameters with explicit 'unit'
# definitions
#
  pars:= [ Mass=3000*Unit(kg), Accel=1.5*Unit(m/s^2), Radius=(0.08282 - 0.006)/2*Unit(m),
           Rat=5, Jmtr= 1.42*10^(-2)*Unit(kg*m^2), stiff=48*Unit(N*m/radian)
         ];
#
# Perform all calculations without reference to
# units
#
  Torque := Mass*Accel*Radius;
  Jload:=Mass*Radius^2;
  MotorTorque:= Torque/Rat;
  InertiaRatio:=Jload/Rat^2/Jmtr;
  Freq := 1/(2*Pi)*sqrt(stiff/Jload);

UseSystem(SI)

 

[Mass = 3000*Units:-Unit(kg), Accel = 1.5*Units:-Unit(m/s^2), Radius = 0.3841000000e-1*Units:-Unit(m), Rat = 5, Jmtr = 0.1420000000e-1*Units:-Unit(kg*m^2), stiff = 48*Units:-Unit(N*m(radius))]

 

Mass*Accel*Radius

 

Mass*Radius^2

 

Mass*Accel*Radius/Rat

 

Mass*Radius^2/(Rat^2*Jmtr)

 

(1/2)*(stiff/(Mass*Radius^2))^(1/2)/Pi

(1)

#
# If necessary, evaluate system properties for a specific
# set of parammeters (with units), eg
#
  eval( InertiaRatio, pars);
  eval( Freq, pars);

12.46756141

 

.5241261350*Units:-Unit(m(radius)^(1/2)/(m^(1/2)*s))

(2)

 

Download unitProblem2.mw

#
# The projectile function
#
  ex11 := t -> -16*t^2 + 384*t;
#
# A plot of the projectile function
#
  plot( ex11, 0..20);
#
# the time value at which the the projectile
# function is a maximum
#
  tmax:=solve(diff(ex11(t),t));
#
# the height value at the maximum
#
  ex11(tmax);

proc (t) options operator, arrow; -16*t^2+384*t end proc

 

 

12

 

2304

(1)

 

Download proj.mw

If I were doing this "seriously" I would come up with a procedure which accepts the function, the endpoints, the number of intervals and the "method" (ie left-hand, right-hand, or mid-point). It would be "similar to that produced by CarlLove in this thread.

However you seem to think that such a "procedure" is "difficult". Actually, it is more difficult  without such a procedure, because now there is no convenient way to produce the information you want for multiple conditions, unless you actually edit and re-run the worksheet for each case.

However the attached will enable you to do this (ugly) way of running multiple conditions - just change the entries

  a:= 1: b:= 5: N:= 30:
  f:= x->1+x^sin(x):

at the top of the worksheet and re-execute the whole thing.

It will produce relevant plots and values for three choices of method (left-hand, right-hand, mid-point) using only "simple-mided" code. It also includes an execution group using Maple's built-in RiemannSum() command, for comparison

  restart:
  with(plots):
#
# Parameters - change as necessary
#
  a:= 1: b:= 5: N:= 30:
  f:= x->1+x^sin(x):
#
# Plot of the function
#
  p0:= plot(f, a..b):
#
# Generate X-values and Y-values for
# end-point and mid-point values
#
  X:= Array(0..N, [seq(j, j=a..b, (b-a)/N)]):
  Y:= Array(0..N, f~(X)):
  Ymid:=f~(X+~(b-a)/(2*N)):
#
# Staircase plot based on left-hand values
#
  pleft:= plot( [ [ a, 0 ],
                  [ X[0] ,Y[0] ],
                  seq
                  ( [ [ X[i+1], Y[i]   ],
                      [ X[i+1], Y[i+1] ]
                    ][],
                    i=0..N-1
                  ),
                  [ b,0 ]
                ]
              ):
#
# Staircase plot based on right-hand values
#
  pright:= plot( [ [ a,0 ],
                   seq
                   ( [ [ X[i],   Y[i+1] ],
                       [ X[i+1], Y[i+1] ]
                     ][],
                     i=0..N-1
                   ),
                   [ X[N], Y[N] ],
                   [ b, 0 ]
                 ]
               ):
#
# Staircase plot based on mid-point values
#
  pmid:= plot( [ [ a, 0 ],
                 [ X[0] ,Ymid[0] ],
                 seq
                 ( [ [ X[i+1], Ymid[i]   ],
                     [ X[i+1], Ymid[i+1] ]
                   ][],
                    i=0..N-1
                  ),
                  [ b,0 ]
                ]
              ):
#
# Display function plot and staircase based on
# left-hand values
#
  display( [ p0, pleft ],
           color= [red, black],
           axes= none,
           caption= typeset
                    ( "Approximate integral using left hand sums is %1",
                      evalf((b-a)/N*add(Y[0..N-1]))
                    ),
           captionfont= [times, bold, 20]
         );
#
# Display function plot and staircase based on
# right-hand values
#
  display( [ p0, pright ],
           color= [red, black],
           axes= none,
           caption= typeset
                    ( "Approximate integral using right hand sums is %1",
                      evalf((b-a)/N*add(Y[1..N]))
                    ),
           captionfont= [times, bold, 20]
          );
#
# Display function plot and staircase based on
# mid-point values
#
  display( [ p0, pmid ],
           color= [red, black],
           axes= none,
           caption= typeset
                    ( "Approximate integral using midpoint sums is %1",
                      evalf((b-a)/N*add(Ymid[0..N-1]))
                    ),
           captionfont= [times, bold, 20]
          );
  

 

 

 

#
# Using Maple's in-built commands for the same
# calculation. This might be considered the
# "easy" way to solve the problem
#
  with( Student[Calculus1]):
  RiemannSum( f(x),
              x=a..b,
              partition=N,
              method='left',
              output=plot
            );
  RiemannSum( f(x),
              x=a..b,
              partition=N,
              method='right',
              output=plot
            );
  RiemannSum( f(x),
              x=a..b,
              partition=N,
              method='midpoint',
              output=plot
            );

 

 

 

 

Download rsum.mw

 

of which only a couple of alternatives are shown in the attached.

If you have a problem with this then use the big green up-arrow in the Mapleprimes toolbar to upload the worksheet which causes the issue

  restart:
  with(plots):
  with(plottools):
  cols:=[red, green, blue]:
  radii:=[1,2,3]:
  display( [ seq
             ( implicitplot
               ( x^2+y^2=radii[j]^2,
                 x =-radii[j]..radii[j],
                 y=-radii[j]..radii[j],
                 color=cols[j]
               ),
               j=1..3
             )
           ]
         );
  display( [ seq
             ( circle
               ( [0,0],
                 radii[j],
                 color=cols[j]
               ),
               j=1..3
             )
           ]
         );

 

 

 

 

Download circles.mw

First 73 74 75 76 77 78 79 Last Page 75 of 207