6523 Reputation

17 Badges

10 years, 138 days

MaplePrimes Activity

These are answers submitted by tomleslie

I used a similar(ish) approach to that given by acer, namely

M:=Import("C:/Users/TomLeslie/Desktop/foo.txt", format="CSV", output=Matrix);

However I hit a problem when trying to parse the embedded strings to some kind of Maple expression with the function

f:=x->`if`( type(x, string),

For the example you give, this works for the first seven entries of the Matrix M, with


However this parsing fails on the 8-th entry, because "\frac{x^3}{3}" does not parse to a meaningful Maple expression - not sure how you are going to deal with this :-(

Just because it always helps to have different answers for the same problem.

# Initialize, and load linear algebra package
# Define a function which returns 'true' when
# the product of the eigenvalues of the supplied
# matrix is equal to the determinant of the
# supplied matrix and false otherwise
   f:= M -> `if`( simplify
                        ( mul
                          ( Eigenvalues(M)[] )
# Generate 8 random 3x3 matrices and apply
# the above test - should get 8 'true'
# answers
   seq( f(RandomMatrix(3,3)),



From the equations and variable whihc you list, the best you end up with is four equations in nine unknowns - Good luck with that!

See the attached for further justification


Since your dat i obviously 3-dimensional and you are insistent on 2D plots, it would be helpful if you specified which 2 dimensions (out of the three available) you want to plot

The attached contains a 3D plot, and several (but not all possibilities) of 2D plots.

Maybe(?) something in here answers your question

When I execute your worksheet the solve() command returns

pe := 2.030837315, 6.701747572

on my default,  64-bit Maple 2016.2 on 64-bit Windows7.

If you are not seeing two answers then I can only assume it is a version/OS issue. Whihc version, build, OS are you running?

You also might want to consider the CriticalPoints() command, as in

Student[Calculus1]:-CriticalPoints( f11(p)-q(p), p);

which also returns

[2.030837315, 6.701747572]

Just to confuse things further, when I use 64-bit Maple 2015.2 on 64-bit Win7, I get identical answers for the above two cases - ie always two solutions

one of which is

f:=(x,y)->piecewise( x^2+y^2<=4,
plot3d( f, -5..5, -5..5);


As in

SurfaceOfRevolution(x^2, x=0..10, output=plot, axis=vertical);

You can construct many variations on this theme - see the help at ?SurfaceOfRevolution


Since yu want to use GramSchmidt() which, as the help states, takes a list of vectors: it is trivial to return a list of row/column vectors from a matris by using the Row()/Column() commands.

It is also unclear whether you want the output from the GramSchmidt() command as a list of vectors or a matrix. The following should cover most possibilities

M := Matrix([[1,2],[3,4]]):
GramSchmidt( [Row(M, 1..2)], normalized=true);
GramSchmidt( [Column(M, 1..2)], normalized=true);
<GramSchmidt( [Row(M, 1..2)], normalized=true)[]>;
Matrix(GramSchmidt( [Column(M, 1..2)], normalized=true));


solve() *seems* to work better with equalities than inequalities. So utilise this.

rts:=select(type, [solve(eqn)], realcons);

will return two real values.

Now for large (absolute) values of 'x', your equation is dominated by the quadratic term - hence its value will be negative. This information, tells you that the value of 'eqn' is positive only between the two values of 'rts'.


One could use the 'CurveFitting" package - as in

# Specify data
   xdata:= [21.2, 24.7, 20.8, 20.8, 20.3]:
   ydata:= [16.6, 19.7, 16.4, 16.8, 16.9]:
# fit above data to a straight line using
# CurveFitting package
   fit:= CurveFitting:-LeastSquares
                                   ( xdata,
# Produce plot from the supplied points
   p1:=  plots:-pointplot( xdata,
# Produce plot of the straight-line fit generated
# above
   p2:=  plot( fit,
# Display both input points and fitted line. Fit
# is pretty rubbish

The above produces the same results as the solution posted by Carl

In both solutions, the fit might be considered as pretty cr*p

Yorr original matrix Mn__11 (by default) has datatype=anything

In your final matrix, you specify datatype=float[8]. You appear to believe that (by magic?) Maple will convert datatype=anything to datatype=float[8]

So consider the possibility that in your first matrix, you populate it with 'strings' - perfectly fine because you have datatype=anything. Then in your second matrix, you are using an initialiser, which is a bunch of strings,  but you specify that entries are of datatype-float[8]. Now exactly what would you expect to happen????

I could force the behaviour you appear to want with

  Mm__11 := Matrix
                     ( 7,
                       [  [  -a*b*I__0,               0,              0, -a*b*I__1,              0, 0, 0 ],
                          [               0,  -a*b*I__0,              0,               0, -a*b*I__1, 0, 0 ],
                          [               0,                0, -a*b*I__0,              0,               0, 0, 0 ],
                          [  -a*b*I__1,               0,               0, -a*b*I__2,              0, 0, 0 ],
                          [               0,  -a*b*I__1,               0,              0, -a*b*I__2, 0, 0 ],
                          [               0,               0,                0,              0,               0, 0, 0 ],
                          [               0,               0,                0,              0,               0, 0, 0 ]
# With the above definition, note that the stored
# datatype is "anything"
   op([3,1], Mm__11);
# Now assign values
   I__0:= 0.102033222998e-2:
   I__1:= .80922342232909:
   a:= .2223212330091:
   b:= .293939202032292:
    I__2:= 1:
# Define a new matrix, but since the original matrix
# ie Mm__11 has datatype "anything", it cannot be
# used as initialiser for a matrix with datatype
# float[8], unless an explicit type conversion is
# performed, as in the following
   M__11 := Matrix
                    ( convert~(Mm__11, float[8]),
                       datatype = float[8]

but this definition seems way too complicated - since I could achieve the same result with

  I__0:= 0.102033222998e-2:
  I__1:= .80922342232909:
  a:= .2223212330091:
  b:= .293939202032292:
  I__2:= 1:
  M := Matrix
           ( 7,
             [  [  -a*b*I__0,              0,              0, -a*b*I__1,              0, 0, 0 ],
                [               0, -a*b*I__0,              0,              0, -a*b*I__1, 0, 0 ],
                [              0,               0, -a*b*I__0,              0,              0, 0, 0 ],
                [ -a*b*I__1,               0,              0, -a*b*I__2,              0, 0, 0 ],
                [              0, -a*b*I__1,               0,              0, -a*b*I__2, 0, 0 ],
                [              0,              0,               0,              0,              0, 0, 0 ],
                [              0,              0,               0,              0,              0, 0, 0 ]

Am I missing something?


Well it is not generally recommended to do this, but


will suppress all warnings. See the help at ?interface

(and remember to turn them back  on again as soon as convenient!)

but maybe not the best?

The following works for me: Change the file path/name to something appropriate for you

fid:=fopen("D:/Users/TomLeslie/myMaple/testdata.txt", READ):
line := readline(fid):
while line <>0 do
           L:= remove
                 ( type,
                   StringTools:-Split( line, " "),
          A(k):=[ StringTools:-Join( L[1..-3] ),
M:= Matrix(k-1,3, (i,j) -> A[i][j] );


Truly global optimisation for arbitrary functions is never guaranteed to be correct - unless there has been some major breakthrough in optimization theory which I haven't heard about.

Global optimization of convex functions is relatively trivial - but global optimization of non-convex functions.........?

Local optimization of non-convex functions is also trivial - but global......?

I suggest that you either stick with the commands in Maple's Optimization package (inbuilt and thus free), or download/install the DirectSearch package (again free) from the Maple Application Centre. The latter seems to have a few more in-built heuristics for checking global optimality

I'm using UK english setup, so it is actually quite difficult for me the even enter accented  characters. However if one just considers the letter 'e' with an acute accent.

Maple seems to return the 'length' of this character as 2. I suspect that the reason for this is that if one checks the 'byte' representation of this character using

convert("é", bytes);

This returns the two-byte list

[195, 169]

If I convert this to hexadecimal, with

map(convert, [195, 169], hex) I get [C3, A9]

Now checking the (Unicode) UTF-8 encoding scheme, one finds that the two-byte sequence [C3, A9] corresponds to UTF Code Point U+00E9 which is identified as " LATIN SMALL LETTER E WITH ACUTE "

So I can only conclude that Maple is using Uniicode, and in UTF-8, any character not in the 'old' 7-bit ASCII, is encoded as a multibyte sequence - and Maple's 'length' command is just counting the number of bytes!

First 97 98 99 100 101 102 103 Last Page 99 of 135