tomleslie

13876 Reputation

20 Badges

15 years, 164 days

MaplePrimes Activity


These are answers submitted by tomleslie

that 'object length' in this context referes to the number of "machine-words" which is necessary to store each set entry. But I warn you I may be wrong becuase I'm not very familiar with Maple's internal data structures

Maple strings occupy 4 or more machine-words: the first three are for "housekeeping" purposes; the fourth and subsequent machine-words represent  the actual "characters" within a string. On a 64-bit machine, one can store eight string characters in a single (64-bit) machine word. Any more characters will require an additional machine-word.

The code

  a := {"CTC", "HBS", "HBSEVO", "LBS", "SBD", "SKR", "SKREVO", "VGS", "VGZ", "VGZEVO", "HBSPLATEEVO", "VGZHARDWOOD"}:
  dismantle(a);

will produce the output

SET(2)
   EXPSEQ(13)
      STRING(4): "CTC"
      STRING(4): "HBS"
      STRING(4): "HBSEVO"
      STRING(4): "LBS"
      STRING(4): "SBD"
      STRING(4): "SKR"
      STRING(4): "SKREVO"
      STRING(4): "VGS"
      STRING(4): "VGZ"
      STRING(4): "VGZEVO"
      STRING(5): "HBSPLATEEVO"
      STRING(5): "VGZHARDWOOD"

Note that all STRING(4) entries (which use four 64-bit words) are sorted in lexicographic order.

These precede the STRING(5) entries (which use five 64-bit words), which are also sorted lexicographically.

Thus, if the set contains only strings, the set order would be

  1. All 1..8-character strings, sorted lexicographically
  2. All 9..16-character strings, sorted lexicographically
  3. and so on

But as I warned earlier - I could be wrong!!

I tend to obey the following recommendation from the Maple help

Note:  This order could be changed in future versions of Maple, and/or objects could be represented in a different way in future versions. You should not assume that sets will be maintained in any particular order.

 

 

with some changes to my original code so that I can easily determine the number of iterations, (and a check using DIrectSearch) I have the code below

  restart:
  sys := { M*diff(x(t), t$2)=t-K*x(t), x(0)=0, D(x)(0)=0};
  evs := [[x(t)-5, halt]];
  sol := dsolve(sys, numeric, events=evs, parameters=[K, M]):
  TV := proc( p1, p2 )
              interface(warnlevel=0):
              if  type~({_passed}, numeric)[]
              then sol(parameters=[_passed]):
                   sol(10):
                   return sol(eventfired=[1])[];
              else return 'procname(_passed)'
              fi;
        end proc:
  ranges := K=0.8..1.2, M=0.8..1.2:
  cstr:= [K>=0.8, K<=1.2, M>=0.8, M<=1.2]:
  sol1:=  Optimization:-Maximize(TV(K, M), ranges, output=solutionmodule):
  sol1:-Results();
  sol2:=Optimization:-Maximize(TV(K, M), cstr, output=solutionmodule):
  sol2:-Results();
  sol3:=DirectSearch:-Search( TV, cstr, variables=[K,M],  maximize=true);

whihc produces the results

 

So all three methods give the same" result, although Maple's builtin Maximize() uses substantially fewer iterations. This may(?) be because default tolerances for a solution are different between Optimization:-Maximize() and  DirectSearch:-Search() - or maybe the seqarch algorithm is better!!

My (belated) code shown below

  restart:
  sys := { M*diff(x(t), t$2)=t-K*x(t), x(0)=0, D(x)(0)=0};
  evs := [[x(t)-5, halt]];
  sol := dsolve(sys, numeric, events=evs, parameters=[K, M]):
  TV := proc( p1, p2 )
              interface(warnlevel=0):
              if  type~({_passed}, numeric)[]
              then sol(parameters=[_passed]):
                   sol(10):
                   return sol(eventfired=[1])[];
              else return 'procname(_passed)'
              fi;
        end proc:

  ranges := K=0.8..1.2, M=0.8..1.2:
  cstr:= [K>=0.8, K<=1.2, M>=0.8, M<=1.2]:

  Optimization:-Maximize(TV(K, M), ranges);
  Optimization:-Maximize(TV(K, M), cstr)

 

  1. As a general rule, when using a Maple command  eg Optimization:-Maximize() ) which accepts a 'procedure' as an argument, I find it a "good idea" to ensure that this procedure argument returns something "sensible" when it is called with non-numeric arguments. Some Maple commands evaluate their arguments (including procedures), before values are assigned to the arguments of the embedded procedure. The Optimization:-Maximize() command does not do this, so the above code is "overkill", but it is still a good habit to adopt.
  2. If you decide to use constraints rather than ranges with the Optimization:-Maximize() , command, then these cannot be 'strict' inequalities - ie you need >=, <=, rather then >, >. See the second call in the above
  3. I'd put the 'warning suppression' inside the procedure - this means it will automatcally reset when the procedure exits

 

 

the following code

  with(DEtools):
  with(plots):
  with(plottools):
  initialset := { seq
                  ( seq
                    ( [x(0) = a, y(0) = b],
                      a = -2 .. 2
                    ),
                    b = -2 .. 2
                  )
                }:
  A := DEplot
       ( [ diff(x(t), t) = x(t)^2*y(t) - x(t)^2,
           diff(y(t), t) = x(t)*y(t)
         ],
         [x(t), y(t)],
         t = -3 .. 3,
         x = -8 .. 6,
         y = -5 .. 7,
         initialset,
         stepsize = 0.01,
         color = blue,
         linecolor = magenta,
         arrows = medium,
         axes = boxed,
         size = [1250, 1250]
       );
  P1 := display
        ( ellipse
          ( [0, 0],
            0.1,
            0.15,
            filled = true,
            color = black
          ),
          scaling=constrained
        );
  display([ A, P1] );

will produce the following three plots. The first of these is moderately informative, but I have no idea why the latter two are "interesting"

 

which I don't use often, because I don't use sections (much)

  1. Insert section
  2. Use CTRL+Del (or Edit->Delete Element) to remove the 'top-level' prompt after the section
  3. You should then find that using 'Enter' creates execution groups with the section
  4. Add one (blank) execution group at the end of the section and use CTRL+, (or the outdent button on the toolbar)

 

to that given by Kitonum.

The following code removes all terms containng the indexed 'variable' x[j], irrespective of degree.

It then removes all terms in the indexed 'parameter' xi[j] whose total degree is >3, so retains terms of degree 0..3. If you wish to retein only those whose degree is exactl 3, then change the highlighted '<=' to '='

  restart;
  V:= Vector[column]( 2, [3*x[1]^4*x[2]^2 + 7*x[1]^3*x[2]^3 + 6*x[1]^2*x[2]^4 + 7*xi[1]*xi[2]^5 + 65*xi[1]^3 + 76*xi[1]^2*xi[2] + 56*xi[1]^2*xi[3], 13*x[1]^6 - 7*x[1]^5*x[2] + 30*x[1]^4*x[2]^2 + 75*x[1]^3*x[2]^3 + 130*x[1]^2*x[2]^4 + 54*xi[1]*xi[2]^5 + 43*xi[2]^6 + xi[2]^2*xi[3] + 76*xi[2]^2*xi[4] + 43*xi[2]*xi[3]^2]); 
  varName:=`x`:
  deg:=3:
  f:= (p, v, d) -> select
                   ( j -> degree(j)<=d,
                     remove
                     ( has,
                       p,
                       indets
                       ( p,
                         specindex(v)
                       )
                     )
                   ):
  T:= f~(V, varName, deg);
  coeffs~(T);

 

Well, you do BnotB define the function u(t) in your original question, but I'm pretty sure you mean the Heaviside function (otherwise your wuextion doesn't make much sense. There are two ways to compute/plot the amplitude spectra of the functoions you require

1. Compute the fourier transforms of

                 exp(-2*t)*Heaviside(t)
               t*exp(-2*t)*Heaviside(t)
           t^2*exp(-2*t)*Heaviside(t)

    directly using inttrans:-fourier(), and plot the results

2. Compute the fourier transform of

                 exp(-2*t)*Heaviside(t)

   directly. By repeated differentiation of this result with respect to omega (the designated frequency variable)
   one can also generate the fourier transforms of

               t*exp(-2*t)*Heaviside(t)
           t^2*exp(-2*t)*Heaviside(t)

The code below shows both methods

  restart;
  with(inttrans):
#
# Compute the fourier transform of exp(-2*t)*u(t) with the
# assumption that the OP's function u(t) is actually the 
# Heaviside function (otherwise the OP's question doesn't
# make much sense?)
#
  T1:= fourier( exp(-2*t)*Heaviside(t),t, omega);

#
# Directly compute the fourier transforms of 
#
#   t*exp(-2*t)*u(t)
# t^2*exp(-2*t)*u(t)
#
# and, along with the transform of exp(-2*t)*u(t), plot the
# resulting amplitude spectra
#
  T2:= fourier(   t*exp(-2*t)*Heaviside(t),t, omega);
  T3:= fourier( t^2*exp(-2*t)*Heaviside(t),t, omega);
  plot( [abs(T1), abs(T2), abs(T3)],
        omega=0..10,
        color=[red, green, blue]
      );
#
# Compute the fourier transforms of
#
#   t*exp(-2*t)*u(t)
# t^2*exp(-2*t)*u(t)
# 
# by differentiation of the fourier transform of exp(-2*t)*u(t)
# and then plot the amplitude spectra of all three answers.
# Gives the same result as above - which is to be expected
#
  T4:= diff(T1,omega);
  T5:= diff(T2,omega);
  plot( [ abs(T1), abs(T4), abs(T5)],
        omega=0..10,
        color=[red, green, blue]
      );

and both methods produce the same output plot shown below

See the attached worksheet for more detail

fts.mw

 

 

 

 

 

 


 
 

 

  

The file test_19_marts.mw *appears* to be a pdf file, although it has the .mw extension.

I have simly changed the file extension here -> test_19_marts.pdf and you should be able to open this with your normal pdf reader.

As far as I am aware, there is no way to convert a pdf file back into "executable" Maple. So if you made this conversion "accidentally", I think you are stuck :-(

the code

  restart;
  v1 := < cos(alpha + beta),
          sin(alpha + beta),
          alpha + beta
        >;
  v2 := < cos(alpha)*cos(beta) - sin(alpha)*sin(beta),
          sin(alpha)*cos(beta) + cos(alpha)*sin(beta),
          alpha + beta
        >;
  LinearAlgebra:-Equal(v1, combine~(v2, trig));

which doesn't seem too difficult???

as in

restart;
s:=evalc~([solve(x^3+x^2-2*x-1, x)]);

which will produce

 

 

but you may not be alone! See the question at

https://www.mapleprimes.com/questions/231863-Problem-With-Animation-Toolbar-In-Aple-2021#comment278118

but you probably won't like the answer!

The integrand has multiple singularities in the range 0..1, ie its value is undefined. One can avoid these singularities by shifting the integration range to 2..infinity, in which case the value of the integral is -infinity.

Plotting the integrand is illuminating, see the code below

 

restart;
aa := (1/(8*(2*x - 1)) - 1/(4*(x - 1)) - x/4 + 1/(8*(2*x - 1)^2))*exp(-x/(1 - 2*x))*BesselI(0, sqrt(x/(1 - 2*x)));
int(aa, x=0..infinity);
int(aa, x=2..infinity);
plot( aa, x=0..10);
plot( aa, x=2..10);

The two int() statements produce 'undefined' and '-infinty' respectively, which seems reasonable if one examines the plots below

 

 

 

 

 

 

 

 

 

 

 

The Statistics:-Tally() command is deigned to do exactly what you want

The only issue with it is to convert its output to the precise form that you want.

The code below will generate the tablelyou want,  convert to matrix form and Export to Excel.

The only drawback is that the Maple command ExcelTools:-Export() has been broken since Maple 2018, Despite repeated SCR requests,the "powers-that-be" at Maple show no signs of fixing this. Hence the only "exprot" command in the following whiich will actually *work* is an export to 'csv' format with no mention of EXCEL at all - either explicitly or implied by file extension

  restart;
#
# Maple uses the symbol 'I' as the square root of -1
# One shouldn't use it for any other purpose, without
# redefining it
#
  local I:
  L:=[A,B,A,C,A,B,D,E,A,F,G,H,H,G,I,P,Q,W,A];
#
# Generate the frequency table, sort it into lexicographic
# order, and populate a Matrix
#
  M:= Matrix( ( x-> [lhs(x), rhs(x)] )~( sort(Statistics:-Tally(L))));
#
# location to export file - change to something appropriate
# for your installation
#
  fdir:="C:/Users/TomLeslie/Desktop/":
#
# Export as an xlsx file
# This won't work
#
  ExcelTools:-Export( M,
                      cat(fdir, "freqTab1.xlsx")
                    );
#
# This won't work either
#
  ExportMatrix( cat( fdir, "freqTab3.xls"),
                 M );
#
# But this one will
#
  ExportMatrix( cat( fdir, "freqTab2.csv"),
                M,
                target=csv
              );

 

 

the code below

  restart;
  with(GraphTheory):
  L:=[7$1..22,6];
#
# Generate numelems(L)-permutations of the list L
#
  P:=combinat:-permute(L, numelems(L)):
  IsGraphicSequence~(P);
#
# Generate a graph for each permutation
#
  G := SequenceGraph~(P):
#
# Draw a few of these graphs
#
  DrawGraph~(G[1]);
  DrawGraph~(G[7]);
  DrawGraph~(G[23]);

which will generate 23 graphs and draw the three graphs below

 

 

 

As far as I can tell this has nothing to do with rho=x[n]/h and everytthing to do with the fact that the firts three statements in your "for loop" ie

par1:=x[n]=t[0],x[n+1]=t[1],x[n+2]=t[2]:
	par2:=y[n]=iny:
	res:=eval(<vars>, fsolve(eval({e||(1..2)},[par1,par2]), {vars}));

generate a simple divide-by-zero condition.

Both e1 and e2 have x[0] as denominator in one term, and since n=0, t[0]== the first entry in par1 guarantees that x[0]=0. Diveiding-by-zero is never good.

A few more details in the attached

divByZero.mw

 

 

 

 

First 52 53 54 55 56 57 58 Last Page 54 of 207