tomleslie

5194 Reputation

15 Badges

9 years, 245 days

MaplePrimes Activity


These are answers submitted by tomleslie

The answer in your picture is correct, although presented in a rather odd way. Read/execute the attached file for details

cubicSol.mw

The first thing you have to appreciate is that you don't need filler spaces - every formatted print statement in every programming language developed since the year dot allows you to specify a "field width". Given a fieldWidth of (say) 10, then applying it to the integer '1', will print nine leading spaces, followed by the value '1' - so forget "fillers"

The first thing you have to do is examine all of your data to find out the maximum "length" of any integer you have to print, and then set the fieldWidth to this value+1. After that you just need to figure out how much data, eg rows in a matrix or table, entries in a listlist whatever. The following works for data as a listlist, and could be easily modified for any other 2D data representation

  restart;
#
# Set up some toy data to be printed
#
   slf:= [ [  1, 100, 1000, 100000000],
             [ 99, 9999,  9,  9999],
             [ 23456, 12, 237, 9]
           ]:
#
# Based on the number of entries in an
# individual "row" of whatever data is
# supplied, construct an appropriate
# format string, allowing for the maximum
# length which might be required
#
   ff:= cat
          ( seq
            ( cat
              ( "%",
                 max
                 ( map
                   ( length~, slf )
                   )+1,
                  "d"
              ),
              j=1..numelems(slf[1])
           ),
          "\n"
        ):
#
# Now print all the data
#
   seq
   ( printf
      ( ff, slf[j][] ),
      j=1..numelems(slf)
    );

I don't really think that you problem is specific to Maple: if you define a table in, for example, MSWord then you will see the same issues: namely that alignment of "entries" within cells can only be done on a row or column basis, not on an individual cell basis. This becomes problematic when cells are merged - obvious example

If I merge several cells in a column, and then choose to set cell-content alignment across rows, which row determines the alignmennt with the merged cells??? Hint: it will generally be ether the top or bottom of the merged cells, and can depend on how you selected them!! As in "select the bottom cell, swipe up and merge", can result in different behaviour from "select the top cell, swipe down and merge"

On a purely pragmatic basis, I tend to set my row and column alignments to "center". This seems to avoid most issues

So far as I am aware, the print command produces output when it is executed. Consider the simple (if somewhat risky) test case of an infinite loop

for i from 1 by 1 do
     print(i):
end do:

This loop is infinite: so if you believe that the ouput of the print() statement will not be displayed until the loop is finished, you will see nothing.

On the other hand, if you see any output, then it is being produced as it is executed. Before you try this, make sure you find out where the big STOP button on the toolbar is, otherwise you will be sitting there for a very loonnnggggg time!

Attached worksheet shows three ways to do composition of permutations, including the one you have tried, using the deprecated group package. You really shouldn't be using this, so pick one of the first two options

permComp.mw

Perhaps you are making the assumption that the derivative order 'i' is a positive integer. Maple will not make this assumption - after all, you might want some kind of fractional derivative!!!

If you are happy with the assumption that the derivative order is a positive integer, then

restart;
F := Vector( [ p[1]*p[6]*(p[2]-x[1]-x[2])-p[3]*x[1],
                     p[4]*p[6]*(p[2]-x[1]-x[2])-p[5]*x[2]
                   ]
                 ):
timefull := [ x[1] = x[1](t),
                   x[2] = x[2](t)
                ]:
assume(i::posint);
Fdiffi := [ diff (subs(timefull, F[1]), t$i),
               diff( subs(timefull, F[2]), t$i)
           ];

should provide the answer you require. Although since you declare 'F' to be a vector and 'Fdiffi' will be returned as a list, this is a little "untidy". Slightly better might be

restart;
F := Vector( [ p[1]*p[6]*(p[2]-x[1]-x[2])-p[3]*x[1],
                     p[4]*p[6]*(p[2]-x[1]-x[2])-p[5]*x[2]
                  ]
                ):
timefull := [ x[1] = x[1](t),
                   x[2] = x[2](t)
                ]:
assume(i::posint);
Fdiffi:=map( diff, subs(timefull, F), t$i);

where 'Fdiffi' will also be a vector

Once upon a time the limit on the number of columns in an Excel file was 256: anything in the .xls file format was restricted to 256 columns

Somewhere around Excel2007 the number of allowed rows/columns in an Excel spreadsheet was greatly increased - I think it is now 16384 columns (provided you are using .xlx files)

However, for reasons I do not know, Maple still seem to be applying the restriction of 256-column output. Probably a good idea if one assumes "old" Excel installations and a bad idea for more modern ones.

The simplest workaround is to split your matrix in two, with 150 columns in each, then export these to two separate worksheets in the same Excel file. As an example, the following will work for a 300x300 matrix

restart;
XLM:=LinearAlgebra[RandomMatrix] (300,300);
ExcelTools[Export](XLM[1..300, 1..150], "J:/Users/Tomleslie/myMaple/xlTest.xls", "A"):
ExcelTools[Export](XLM[1..300, 151..300], "J:/Users/Tomleslie/myMaple/xlTest.xls", "B"):

Obviously you will have to change the file path/name to something appropriate for your system. However the result will be an Excel workbook with two worksheets 'A' and 'B'. If you really want these in a single workhseet, then you can perform a simply cut/paste operation within Excel (assuming you Excel is post 2007-ish!)

In the absence of a return statement, procedures will return the output of the last evaluated statement - so in your exaample, you will get the value of solve05(ll):

On the other hand if you use an explict return statement, as in

LTTS:=proc(ff)
           local ll,r,r1,r2,r3;
           ll:=rhs(ff)-lhs(ff);
           return solve01(ll),
                     solve02(ll),
                     solve03(ll),
                     solve04(ll),
                     solve05(ll):
          end:

this will return the values solve01(ll), solve02(ll), solve03(ll), solve04(ll), solve05(ll), as a sequence

Try reading the help page for proc() which states quite clearly

The value of a procedure invocation is the value of the last statement executed, or the value specified in a return statement.

According to the manual

The packages() calling sequence returns a list of the packages bound using the with command. The packages are listed in the order that they were bound.

You need to tell maple that the function q1(t) has units of Coulombs, and similarly diff(q1(t), t) has units of coulombs/sec (or amperes if you prefer). The following executes

restart:
R := 500*Unit(ohm);
C := .5*Unit(microfarad);
V := 20*Unit(volt);
ode := R*diff(q1(t), t)*Unit(coulomb)/Unit(second)+q1(t)*Unit(coulomb)/C = V;
dsolve(ode);

but the result for q1(t) is displayed without units :-(

I've tried a few variations of the above, same outcome

I obviously misunderstood - still you could use

   restart;
   convert(taylor(y(x+h), h=0, 4), polynom);
   convert(%,diff);

where the last line is only necessary if you don't happen to like D-operator format

I think that the fundamental issue is with the value of numpoints - you are "subsampling" the ode solution for plotting purposes - which makes the plot *look* really weird: I (rather arbitrarliy) set numpoints=10*tmax, in an attempt to ensure that I always got the same number of point on each cycle, regardless of the number of cycles performed: this seemd to make things *appear* more sensible.

I thought that using dsolve/odeplot might give simpler control over numeric errors compared with DETools/DEPlot - this doesn't *seem* to be true. Both give approximately the same answers up to tmax=2000 (with numpoints=10*tmax), although I do have to explicitly remove the maxfun limit in the dsolve() command.

From around tmax~800, one can start to see error issues, although both solution methods still show the solution in the limit cycle

I tried it all the way up to tmax=2000 and the solution stays within the limit cycle.

See attached

nonLinOsc.mw

Don't have Mathematica so can't really check, but as far as I can tell

  1. Maple imports .mma, but does not export it
  2. Mathematica does not import or export .mw(s)
  3. So only option would seem to be: pick a format both support - eg mathML(?). Maple exports it and Mathematica imports it. I suspect that success/failure of this approach depends on the "complexity" of the info to be exported/imported

From maple MathML:-Export

appears to work (no messgaes/complaints) for both of the expressions you quote.

Like I said earlier, I can't check whether Mathematica's mathML import, will import/convert correctly

The attached runs in about 0.25secs on my machine and produces plausible-looking plots

DEprob.mw

 

I think there may be a few problems with the code you posted

  1. if you want 3.14159... you have to use Pi everywhere, not pi
  2. there seems to be a missing operator in the expression

#funzione desiderata
Yd(q) := arctan(tan(q),(1 - b*tan(q)/2/p));
arctan(tan(q), 1 - 0.3055555556 tan(q))      <--  6 tan ?????

If I use Pi for pi throughout, and replace the above snippet with

#funzione desiderata
Yd(q) := arctan(tan(q),(1 - b*tan(q)/2/p));
arctan(tan(q), 1 - 0.3055555556 * tan(q))

Then NLPsolve still returns the error message

Error, (in Optimization:-NLPSolve) abs is not differentiable at non-real arguments

:-(

However

DirectSearch[Search](rms, [z = -0.4..0,
                                         alpha0 = 0..Pi/3,
                                         alpha1 = Pi/2..5*Pi/4,
                                         l1 = 0.3..1,
                                         l2 = 0.001..0.3,
                                         l3 = 0.01..0.3
                                      ]
                              )

returns

1.20098330185160, [alpha0 = 9.10801161719342*10^(-8), alpha1 = 1.57079638010262, l1 = .496239599198213, l2 = .260891601089832, l3 = 0.100000115197816e-1, z = -0.841913363553979e-2], 84]

First 100 101 102 103 104 105 106 Last Page 102 of 115