tomleslie

13876 Reputation

20 Badges

15 years, 175 days

MaplePrimes Activity


These are answers submitted by tomleslie

First things first - is it possible to perform the conversion at all? I have to admit that my first thought was to convert the summand separately, using

simplify(convert( op([2,1],sol), trigh));

and this works - more or less instantly. (reconstructing the solution with this conversion is left as an exercise for the user)

On the general subject of interrupting an on-going calculation; my understanding (possibly wrong) is that you cannot interrupt a built-in command, so if Maple gets stuck in a "built-in" you are screwed.

I, (like everyone else here I suspect) have been in this situation more often than I care to admit. Should there be a way to stop the current calculation, irrespective of the type of command being executed? I'd agree with you, but I can appreciate that there may be a communication issue between the maple interface and the maple engine, which might make this difficult to achieve when the latter has gone berserk

 

 

The only ambiguity I see, is that it is not completely obvious whether i=1..m, j=1..n or i=1..n, j=1..m in the OP's original post. Obviously this makes a difference in the resulting matrix. However one of the options in the attached *ought* to cover the desired calculation

NULL

  restart;
  m:=2:
  n:=3:
#
# The quick way, write the matrix directly
#
# i runs from 1 to m, j runs from 1 to n
#
  M1:=Matrix(m,n, (i,j)-> expand(binomial(m,j)*binomial(n,i)*x^j*(1-x)^(m-i)*y^j*(1-y)^(n-j)));
#
# The quick way, write the matrix directly
#
# i runs from 1 to n, j runs from 1 to m
#
  M2:=Matrix(n,m, (i,j)-> expand(binomial(m,j)*binomial(n,i)*x^j*(1-x)^(m-i)*y^j*(1-y)^(n-j)));
#
# Or if , for some reason OP actually *wants* to use
# nested for loops, then one of the following should
# be OK
#
  M3:=Matrix(m,n):
  for i from 1 by 1 to m do
      for j from 1 by 1 to n do
          M3[i,j]:=expand(binomial(m,j)*binomial(n,i)*x^j*(1-x)^(m-i)*y^j*(1-y)^(n-j));
      od;
  od;
  M3;
  M4:=Matrix(n,m):
  for i from 1 by 1 to n do
      for j from 1 by 1 to m do
          M4[i,j]:=expand(binomial(m,j)*binomial(n,i)*x^j*(1-x)^(m-i)*y^j*(1-y)^(n-j));
      od;
  od;
  M4;

_rtable[18446744074354819070]

 

_rtable[18446744074359120470]

 

_rtable[18446744074359130942]

 

Matrix(%id = 18446744074359138654)

(1)

 

NULL

Download genMat.mw

more a misunderstanding.

Suggest you read the help page at ?copy, very carefully. Particularly the part

the statements s := table(); t := s; leave both names s and t evaluating to the same table structure.  Hence, unlike other Maple data structures, assignments made via one of the names affect the values associated with the other name as well.

Your worksheet uses tables - hence the above applies> Instead of using the statement

IntSectRoll := IntSect

if you actually want two completely distinct tables, you should use

IntSectRoll := copy(IntSect)

There are similar issues with Arrays and Matrices, which is why the commands ArrayTools:-Copy() and LinearAlgebra:-Copy() commands exist

Your are perfectly justified in asking why? (or even wtf!). The answer is historic. Once upon a time when the world was young and computers/software had very limited memory it was considered "bad practice" to inadvertently(?) create unnecessary duplicates of "large" data structures, because it eats memory, so the sequence

s:=a;
t:=s;

would result in two entirely independent entities, 's' and 't' if the original argument 'a' was something small, like a scalar. But if 'a' were something 'big', like a table/array/matrix/whatever, then only one entity would exist, 't' would point to 's' which points to 'a'. This "feature" goes by many names, such as pass-by-reference/pass-by-value. It is not specific to Maple: it occurs in many programming languages (see, for example, the page https://en.wikipedia.org/wiki/Evaluation_strategy).

 

The required arguments are

  1. a string (or symbol which evaluates to a string) identifying the file path/name where you want the matrix to be stored
  2. the name of the matrix to be saved

Optional arguments include the format in which you want the matrix to be saved

See the help at ?ExportMatrix

In order to "plot" anything, you have to be able to compute numerical values: for example, given a (numerical) x-coordinate and a (numerical) y-coordinate, there has to be a way of computing a (numerical) z-coordinate. So let's consider the issues about producing these numerical quantities.

I'm going to deal with your second formulation (in maple3.mw) first - just because it is simpler to describe

  1. in the worksheet maple3.mw, a simple examination of the order/degree of the pdes indicates that  that you need 8 boundary/initial conditions in order to eliminate all the arbitrary constants. Maple represents these arbitrary constants as { _C2, _C3, _C4, _C5, _C6, _C7, _C8,  _c[1]}. You need one boundary/initial condition in order to eliminate each arbitrary constant
  2. Having come up with a sufficient number of consistent boundary/initial conditions, you will also need to supply a numerical value for the parameter 'm' before numerical values for r(tau, R) and t(tau, R) can be obtained, allowing you to generate plots

The situation in your first formulation (maple2.mw) is similar but worse

  1. You have two equations in your pde system, but three dependent variables - the functions f(), T() and rho(). To have any hope of solution the number of pdes should be at least as great as the number of dependent variables
  2. A similar problem to that described above occurs with initial/boundary conditions.. From the order/degree of the pdes, this time you need ten initial/boundary conditions in order to generate numerical solutions (and hence plots) - as well as a numerical value for the parameter 'm'

indices( ), with the 'indexorder' option

Default sort is the same as for sort(). You can supply your own sort function, whose syntax is the same as that used by the sort() command

You define eq1 as

G1=G2;

You then set this quantity to be zero, in the solve() command - in other words, you have G1=G2=0 - which is not meaningful

If I "guess" what is intended, then

restart:
G1:=a*x^3 + b*x^2;
G2:=c*(x-1)^3 +d*(x-1)^2;
eq1:=subs(x=u, G1=G2);
eq2:=subs(x=u, diff(G2,x)-diff(G1,x));
eq3:=subs(x=u, diff(G2,x$2)-diff(G1,x$2));
eq4:=subs(x=u, diff(G2,x$3)-diff(G1,x$3));
sol:=solve({eq1, eq2=0, eq3=0, eq4=1},{a,b,c,d});

wiill provide an answer

To force Maple to use more significant digits,  set

Digits:=36; # for example NB "Digits", not "digits"

in your worksheet

If you still have problems, then please upload worksheet using the big green up-arrow in the mapleprimes toolbar. "Pictures" of your problem are pretty much useless.

As a general rule square brackets( ie '[]') are used to identify indexable quantities. Overuse in simple names such as bc[1], bc[2] etc isn't wrong, but the practice should probably be avoided.

Your fundamental problem seems to be some sort of "collision" between using diff_table notation and D() operator notation in the definition of ic[2]. I fixed this in the "simplest" way possible - more elegant solutions may exist

Even with these fixes, Maple cannot find a symbolic solution, but a numerical solution is possible. See the attached

  restart;
  with(PDEtools):
  U := diff_table(u(x, t));
  pde := U[t, t] = U[x, x]+5*sin(3*x);
#
# Changed definition of ic2. Seems to be some 'problem'
# combining diff_table notation with D() notation,
# so I just applied the "obvious" workround. There may
# (probably should) be a more elegant way, but I couldn't
# figure it out (I don't generally use diff_table
# notation)
#
  bc1 := eval(U[], x = 0) = 0; bc2 := eval(U[], x = Pi) = 0;
  ic1 := eval(U[], t = 0) = 0; ic2 := convert(eval( U[t], t=0),D) = 1;
  sys := [pde, bc1, bc2, ic1, ic2];
#
# pdsolve() does not produce an analytic solution!
# so the following returns NULL
#
  pds1:=pdsolve(sys);
#
# But a numerical solution is possible!
#
# Displayed plot is just for illustrative purposes,
# all sorts of other output is available - see the
# pdsolve/numeric help page
#
  pds2:=pdsolve( sys[1], sys[2..5], numeric);
  pds2:-plot3d( x=0..1, t=0..1);

table( [(  ) = u(x, t) ] )

 

diff(diff(u(x, t), t), t) = diff(diff(u(x, t), x), x)+5*sin(3*x)

 

u(0, t) = 0

 

u(Pi, t) = 0

 

u(x, 0) = 0

 

(D[2](u))(x, 0) = 1

 

[diff(diff(u(x, t), t), t) = diff(diff(u(x, t), x), x)+5*sin(3*x), u(0, t) = 0, u(Pi, t) = 0, u(x, 0) = 0, (D[2](u))(x, 0) = 1]

 

 

_m711457152

 

 

 

Download pdeProb.mw

Your original worksheet worked for me: I couldn't find anything "obviously wrong" - but

  1. The autosave was set for a very short interval, and for reasons I couldn't detect, the actual saving process was taking much longer than I would expect for a file this small, containing a relatively small amount of code+data.
  2. I converted everything to 1-D input - this involved changing a couple of pretty weird variable names: don't know if this was a problem, but there seemed no reason to have such complicated variable names - and I don't trust 2-D input, when it it is generating such weird names
  3. I reset the autosave interval to 10mins

The attached works for me in

Maple18
Maple2015
Maple2016
Maple2017

running on 64-bit Windows7

fixTemperature.mw

You can construct the letters 'E' and 'F' from three rectangles (and the use of the plottools:-translate() function)

Having constructed the basic letters (and their combination if desired), use the plottools:- translate() and plottools:-rotate() functions, to produce animations - as in the following

  restart:
  with(plottools):
  with(plots):
  frames:= 48:
  base:= 9: height:= 12: mid:= 5.5: wid:= 1:
#
# Define three rectangles - all one needs
# to construct the letters 'E' and 'F'
#
  r1:= rectangle( [0, height], [wid, 0] ):
  r2:= rectangle( [wid, wid], [base-wid, 0]):
  r3:= rectangle( [wid, height/2+wid/2], [mid-wid, height/2-wid/2]):
#
# Now construct the letters E, F and the combination EF
#
  p_opts:= scaling=constrained, color=grey, style=patchnogrid, axes=none:
  letE:= display( [r1, r2, r3, translate(r2, 0, height-wid)], p_opts);
  letF:= display( [r1, r3,     translate(r2, 0, height-wid)], p_opts);
  letEF:= display([letE, translate(letF, base+wid/2,0)]);

#
# Define a simple animator function - does "there and back"
# translation
#
  anim1:= x -> display
               ( seq
                 ( `if`
                   ( j<frames/2,
                     translate( x, j/12,0),
                     translate( x, (frames-j)/12, 0)
                   ),
                   j=0..frames
                 ),
                 insequence=true
               ):
#
# Produce animations for all three of the above plots
#
  anim1(letE);
  anim1(letF);
  anim1(letEF);

#
# Define another simple animator function - does "there and back"
# rotation
#
  anim2:= x -> display
               ( seq
                 ( `if`
                   ( j<frames/2,
                     rotate( x, (j/12)*(Pi/8), [0, 0]),
                     rotate( x, ((frames-j)/12)*Pi/8, [0, 0])
                   ),
                   j=0..frames
                 ),
                 insequence=true
               ):
#
# Produce animations for all three of the above plots
#
  anim2(letE);
  anim2(letF);
  anim2(letEF);

 

Download letters.mws

When I run the worksheet you supplied, the final fsolve() command retunrs

{a[0, 0] = 0.3863430880e-1, a[0, 1] = -2.899266914*10^(-44), a[0, 2] = -3.827500189*10^(-35), a[1, 0] = 0.2468405811e-1, a[1, 1] = -4.469190462*10^(-44), a[1, 2] = -1.104904133*10^(-34), a[2, 0] = -0.1395025069e-1, a[2, 1] = -1.485818811*10^(-25), a[2, 2] = 1.531000076*10^(-25), b[0, 0] = -0.1364652488e-1, b[0, 1] = 7.070382741*10^(-44), b[0, 2] = -3.966059847*10^(-35), b[1, 0] = 0.1137991784e-1, b[1, 1] = -1.868521551*10^(-43), b[1, 2] = -1.144902859*10^(-34), b[2, 0] = 0.2502644272e-1, b[2, 1] = 1.635538373*10^(-25), b[2, 2] = 1.586423938*10^(-25)}

So what is not working?

I suppose it might be a version issue: the above was obtained running 64-bit Maple 2017.2 on Win 7. If you do not obtain this answer, then please specify what Maple version you are running on what OS

There are several reasons why the ImportMatrix(), and other higher level import commands fail.

  1. The first four lines are more or less usless header
  2. The entries in the first column are difficult to parse because of the mixture of numbers, text and '-' signs
  3. There are "missing" entries in the body of the data. These seem to be represented with the symbol '-', and have to be treated specially. Some sort of placeholder has to go in the output matrix.

In order to achieve all of the above one has to use a slightly lower-level "import" process - so I decided to use readline(). The following returns a matrix where

  1. then number of header lines to be skipped is set by the variable 'skiplines'. I have set this to 4.
  2. entries in the first column are left as strings.
  3. Missing entries in the body of the data are replaced by whatever is assigned to the variable 'void'. I have set this to be the string "miss" in the following. You could change this assignment to 0.0 aor anything else

In order to use the following you will have to change the assignment to the variable 'loc' to match where the datafile is stored on your machine

restart;
#
# OPs datafile seems to contain some "missing"
# entries, represented by the character '-'.
# Have to put some kind of placeholder in the
# output Matrix whenever this occurs. I have
# chosen to use the string "miss", but one
# could use 0 (or anything else) just by
# changing the following assignment
#
  void:="miss":
#
# In the test file the first 4 lines are
# header, arrange to skip these by setting
#
  skiplines:=4:
#
# Since amount of data is unknown, put it in
# a table, becuase this is easy to extend, and
# can be simply converted to a matris later
#
  t:=table():
#
# File location. OP will have to change path
# to something relevant for his/her machine
#
  loc:="C:/Users/TomLeslie/Desktop/-Validierung-Stahl-OIII-.txt":
#
# Following loop reads and parses data
#
  for k from 1 do
      line:= readline( loc );
      if   line=0
      then break;
      else if   k>skiplines
           then p:= StringTools:-Split(line);
                t[k-skiplines, 1..numelems(p)]:= p[1],
                                                 seq( `if`
                                                      ( j="-",
                                                        void,
                                                        parse(j)
                                                      ),
                                                      j in p[2..-1]
                                                    );
           fi;
      fi;
  od:
#
# Convert table to matrix - make sure not to
# forget 'indexorder' option. The [1,1] entry
# is "scrap" so set it to NULL (could set it
# to anything else!)
#
  M:=convert([entries(t, indexorder)],Matrix):
  M[1,1]:=NULL:
  M;

 

 

 

Download dataImport.mw

 

it is a pretty weird thing to have to do - and I think that one should fix the the source of the problem, ie where you say " because maple cannot import these expression correctly",

In what form is the original data? - textfile, csv, Excel whatever, because Maple can import all of these successfully (as well as a few other formats). This stage could be probably(?) be fixed if you uploaded the original data file here, so that I could see what is causing the problem.

If for any reason you don't want to do this, then some variation on the following "toy" example, could probably be made to work

M:= Matrix(2,2,[[1.0,a],[b,1.0]]);
M2:= Matrix( op([1,1],M), op([1,2],M), (i,j)->`if`(M[i,j]=1.0, i+j+sin(x), M[i,j]));

This is (more or less) the same as that given by Rouben earlier.

The only real difference is that I have written it in such a way that it works for n=1,2,3,.... by changing a single parameter. I have tried this for n=1,2..7 without problems, although by the time n=7, the execution time is starting to climb (about 3minutes on my machine). I didn't have the patience to try this for even higher order systems. The use of matrix constructor functions everywnere means that a lot less typing is necessary.

#
# Initialise and set up the order of the system.
# Pretty quick up to n=4 and I tried it up to
# n=7 where it took about 3mins. I didn't try it
# for higher-order systems, because I'm impatient
# but I can't think of any reason why it would
# fail
#
  restart;
  n:=4:
#
# Define all matrices/vectors for the system in a
# way which only needs the adjustment of a single
# parameter (n, above) in order to work correctly
#
  M:= Matrix
      ( n,
        n,
        shape=identity
      )
      +
      alpha*Matrix
            ( n,
              n,
              (i,j)->sin(i*Pi*nu*t/l)*sin(j*Pi*nu*t/l)
            ):
  C:= 2*alpha*Matrix
              ( n,
                n,
                (i,j)->(j*Pi*nu/l)*sin(i*Pi*nu*t/l)*cos(j*Pi*nu*t/l)
              ):
  K:= Matrix
      ( n,
        n,
        (i,j)-> `if`( i=j,
                      (j*Pi/l)^4*E*J/(rho*A)+(j*Pi/l)^2*N/(rho*A),
                      0
                    )
      )
      -
      alpha*Matrix
            ( n,
              n,
              (i,j)->(j*Pi*nu/l)^2*sin(i*Pi*nu*t/l)*sin(j*Pi*nu*t/l)
            ):
  VV:= Vector[column]
       ( n,
         j->V[j](t)
       ):
  PP:= P/(rho*A)
       *
       Vector[column]
       ( n,
         j->sin(j*Pi*nu*t/l)
       ):
#
# Generate the matrix form of the system
#
  sys1:= M.diff~(VV, t$2)+C.diff~(VV, t)+K.VV=PP:
#
# Convert the above to a list of equations
#
  sys2:= Equate( lhs(sys1), rhs(sys1) ):
#
# Set the values of all parameters equal to 1.
#
# Set all initial conditions equal to zero, ie
#
# V[k](0)=0 and D(V[k])(0)=0 for all values of
# k from 1 to n
#
# Almost certainly invalid and values should
# probably be set individually by hand
#
  params:=( indets(sys1, name)
            minus
            {Pi,t}
          )=~1:
  ics:= [ Equate
          ( eval(VV,t=0),
            Vector[column]
            ( n,
              fill=0
            )
          )[],
          Equate
          ( convert(eval(diff~(VV,t),t=0),D),
            Vector[column]
            ( n,
              fill=0
            )
          )[]
        ]:
#
# Solve the system numerically, and plot all
# independent variables. The maxfun limit is
# disabled, becuase it started to kick in
# around n=6
#
  sol:=dsolve( [ eval(sys2, params)[],
                 ics[]
               ],
               numeric,
               maxfun=0
             ):
   plots:-odeplot
          ( sol,
            [seq( [t, j], j in VV)],
            t=0..10,
            axes=none
          );
        

 

 

Download matODE.mw

First 141 142 143 144 145 146 147 Last Page 143 of 207