tomleslie

13876 Reputation

20 Badges

15 years, 163 days

MaplePrimes Activity


These are replies submitted by tomleslie

@okokoabraham 

to generate plots/data for multiple values of the parameter 'V'. However the *best* method to do this probably depends on what you subsequently want to do with the resulting data.

The attached pdeProb2.mw shows a basic approach - there are many other alternatives depending on your requirements

restart;
In := 5.75*10^(-12):            
M := 1000:
E := 10^12:
Vval := seq( j, j=0..1000, 100):
m := 2300:
K := 10^9:
A := E*In:
B := M*V^2:
C := 2*M*V^2:
F := M + m:
G := K:
tmax := 0.05:
xmin := 0:
L := 1:

pde := A*diff(w(x, t), x $ 4) + B*diff(w(x, t), x $ 2) + C*diff(w(x, t), x, t) + F*diff(w(x, t), t $ 2) + G*w(x, t);
bc := w(0, t) = 0, w(L, t) = 0, D[1, 1](w)(0, t) = 0, D[1, 1](w)(L, t) = 0:

ic := w(x, 0) = 0, D[2](w)(x,0)=1:

for k in Vval do
    pdsA[k] := pdsolve( eval(pde, V=k), {bc, ic}, numeric);
od:

getVals:= (V, space, time)-> rhs(pdsA[V]:-value( w(x,t))(space,time)[3]):
for k in Vval do
    Matrix(11, 11, (i,j)-> getVals( k, (i-1)/10, (j-1)/10));
    pdsA[k]:-plot3d( w(x,t), x=0..1, t=0..1);
od;

 

@P2prod 

To repeat my earlier response, with slight edits

  1. In Maple 2021, one cannot numerically solve the heat equation in 2 spatial dimensions because the pdsolve(..,numeric) command is restricted to two independent variables
  2. In Maple 2021, one can analytically solve the heat equation in 2 spatial dimensions, at least for "simple" boundary conditions, see the attached.
  3. In Maple 2015, I couldn't obtain an analytic solution (or at least it was still "evaluating" after 5 minutes or so
  4. The textbook Partial Differential Equations and Boundary Value Problems with Maple, by George Articolo, has a whole chapter devoted to solving the heat equation analytically "from first principles", in both 2D,  3D and various coordinate systems

@mclaine 

If your worksheet already contains an assignment to the name of the ScientificConstant you want to use. This will result in an error.

 restart;
  with(ScientificConstants):
  c:=2.0;
  myValueOfc:=GetValue(Constant(c));

will result in an error, because Constant(c) will evaluate to Constant(3) - and there is no constant with the name 2.0, in the library. Using uneval quotes prevents the name 'c' being evaluated, so the following will execute with no errors

restart; with(ScientificConstants):
c:=2.0;
myValueOfc:=GetValue(Constant('c'));

 

 

@lcz 

Well the attached will deal with the file GraphData.txt. A few points to note

  1. Each graph structure (including the first)  has to be preceded by a line containing any of the strings "GRAPH", "Graph" or "graph" - just because one needs some way of telling when a "new" graph is beinfg defined
  2. Blank lines are ignored.
  3. It shouldn't matter if the graph definitions have a different number of vertices - I haven't tested this, because all the structures in the supplied file have the same number (25)
  4. The final execution group isn't really necessary. It exists to supply details and drawings of each graph generated. Depending on what you intend to do with these graphs it may be superfluous
  5. Each of the graphs is stored as an entry in the table named 'G' - so for the file supplied, these are G[1], G[2], G[3] and G[4]. The associated adjacency matrix is stored in the table 'M'
  6. Again you will have to change the definition of 'fname' to an appropriate filepath/filename for your machine

mkGraph2.mw

  restart;
  with(StringTools):
  with(GraphTheory):
#
# Read data line by line: each line being read
# as a string.
#
  fname:="C:/Users/TomLeslie/Desktop/GraphData.txt":
  k:=0:
  i:=0:
  while true do
        line:= readline(fname);
        if   type(line, numeric)
        then
           #
           # End-of-file, so exit loop
           #
             break;
        elif
           #
           # Blank lines will be ignored
           #
             HasAlphaNumeric(line)
        then if   Search( ["GRAPH", "Graph", "graph"],
                          line
                        )[2]>0
             then
                #
                # Line contains some variation of the
                # string "graph", so start a "new graph"
                #
                  k:=0:
                  i:=i+1:
             else
                #
                # Otherwise add line to current "graph"
                # removve the colon character (if the 
                # line contains one!)
                  k:=k+1;
                  l[i, k]:= Remove( ":", line):
             fi:
        fi:
  od:
#
# Convert the table 'l' generated by the above to a table
# 'M' whose entries are the adjacency matrices of a graph
# and generate each graph
#
  for p from 1 by 1 to max( seq( j[1], j in[indices(l)])) do
    #
    # Dimensions of adjacency matrix
    #
      d:= max
          ( seq
            ( j[2],
              j in select
                   ( j -> evalb( j[1]=p ),
                     [indices(l)]
                   )
            )
          ):
    #
    # Initialise adjacency matrix
    #
      M[p]:= Matrix( d, d, fill=0):
    #
    # Populate each adjacency matrix
    #
      for q from 1 by 1 to d do
          for r in parse~( Split( l[p,q] ) )[2..-1] do
              M[p][q,r]:= 1;
          od:
      od:
    #
    # Create graph from adjacency matrix
    #
      G[p]:= Graph(M[p]):
  od:
#
# Details and diagram of each graph produced
#
  for j from 1 by 1 to numelems(G) do;
      G[j];
      DrawGraph(G[j]);
  od;

 

 

 

 

@Zeineb 

HFloat(undefined) means thatyou are trying to store "something" whihc can't be represented as a "hardware float". Probably the most common reason for this is that you have divide-by-zero error somewhere. Without the code whihc produced this error, further diagnosis is impossible.

Maple has many ways of entering matrices - use whichever one is most convenient

@Zeineb 

Nothing to stop you defining an Array() within each procedure using Array(1..imax, 1..3), populating it with the appropriate information within the relevant for loops - ie

A[i,1]:=
A[i,2]:=
A[i,3]:=

then returning the Array().

It is not clear to me what your worksheet is intended to do - but wouldn't it be easier to use the Eigenvectors() or Eigenvalues commands from the LinearAlgebra() package?

@Zeineb 

The max[index]() functionaliity was introduced in Maple 2015 If you are using an earlier version ( ie Maple 18 or earlier), then you will have to use your original maxind() procedure. Just replace all occurrences of max[index]() in my first post with maxind().

The attached uses your original maxind() approach and  "runs" in Maple 18.

PWWcorr2.mw

It still produces the error you trap , ie "Zero eigenvalue found", for the few procedure input parameter values which I have tried

because the OP's original question referred to an amplitude=1, half-wave rectified sinewave, for which my original answer was (I believe) completely correct.

I fixed the problems raised by CarlLove about multiple use of the name 'A', as well as tidyng up various function definitions where necessary. Since the OP has "edited" the original question, and changed the worksheet (s)he uploaded - my original answer now looks like the ravings of a demented lunatic.

I really do wish that this site would implement a policy whereby once a question has been "answered" (or even "replied"), then no-one (not even the OP) can change the original question.

I do not feel inclined to revise/post a new worksheet - the OP doesn't deserve it. Below is an image of the (currently!) required "answer". Since the OP will (probably?) change the question again, this too will undoubtedly become invalid

@Anthrazit 

control the sort order in a set.

You can sort a list in 'lexorder', as in

restart;
a := {"CTC", "HBS", "HBSEVO", "LBS", "SBD", "SKR", "SKREVO", "VGS", "VGZ", "VGZEVO", "HBSPLATEEVO", "VGZHARDWOOD"};
sort(convert(a, list), lexorder);

which will produce
 a := {"CTC", "HBS", "HBSEVO", "LBS", "SBD", "SKR", "SKREVO", "VGS", "VGZ", "VGZEVO", "HBSPLATEEVO", "VGZHARDWOOD"}
 ["CTC", "HBS", "HBSEVO", "HBSPLATEEVO", "LBS", "SBD", "SKR", "SKREVO", "VGS", "VGZ", "VGZEVO", "VGZHARDWOOD"]

 

 

@nm 

This doesn't happen in 2019.2, but does happen in 2020.2 and 2021.0.

Can't find anything in the "What's New", Typesetting or UserInterface sectons of the 2020.2 release which would indicate that this change was deliberate/documented

@Scot Gould 

is that any reasonably complicated worksheet is a combination of "mathematics" and "coding".

This thread started with a query about the 'seq()' command - ever seen the equivalent of a 'seq()' function in a mathematics textbook?

So the fundamental question is - in a Maple worksheet, are you writing "code" or "mathematics"?

My own view is that neither 2D nor 1D input completely addresses this basic dichotomy. The choice betwen the two methods can boil down to something as "trivial" as the "size" of the calculation. Assume a calculation of 1000 "steps". Do you want these "steps" in one continuous splurge, or do you want them organised in procedures (and maybe modiules)?? The former is a "mathematical" approach: and will look like a chapter out of a textbook, but will be a nightmare to debug/maintain. The latter is "coding" approach: won't look anyhing like a mathematics textbook, but will be easier to construct/debug/maintain.

So I would accept the the statement that for "small" calculations, 2D-input within Maple is adequate. For "large" problems involving mulltiple procedures (and/or modules), it is a nightmare. For any reasonably-sized problem I will write most of the Maple code in an external (programmer's) editor, as multiple mpl files, which makes 1D input  mandatory. Since the latter (1D input) is my default, I pretty much never use 2D-input unless I'm solving problems on this site.

On the subject oif Matlab: I'm never convinced that comparing/contrasting tools such as Maple/Matlab is ever profitable. Each has advantages, disadvantages and prejudiced "fanboys"

In my lifetime (now retired) , I have written way more Matlab code than Maple code. Now that I have no need to comply with "industry-standard" requirements, I find that I write more Maple code than Matlab (even although my Matlab 2021a release is still configured to use Maple 2021 as its symbolic toolbox!)

@Preben Alsholm 

It still may be an OS problem - see the question here

https://www.mapleprimes.com/questions/231881-Drawing-Toolbar-Missing-Maple-2021

@Preben Alsholm 

Myt objective was to produce eactly the animation you have shown - but I failed completely because I could never make an animation toolbar appear

@lcz 

what your point is here.

With a slight modification to my original code, I can show that of the 23 generated graphs, only 3 are really distinct. All of the othere are isomorphic, to one of these three.

See the code

  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):
  ISOs:=[ListTools:-Categorize( IsIsomorphic, G)]:
  numelems(ISOs);

@Jtroy2 

there is no real point in using an array of time values. The current time can be obtained just by multiplying the loop index by the (presumably know) fixed timestep

First 36 37 38 39 40 41 42 Last Page 38 of 207