tomleslie

13876 Reputation

20 Badges

15 years, 181 days

MaplePrimes Activity


These are replies submitted by tomleslie

@Markiyan Hirnyk 

  1. The help page you supply refers to Matlab's symbolic toolbox (ie the one now based on MuPad).
  2. As far as I know the Matlab translator within Maple only "works" (and maybe not every time?!) on basic "core" Matlab. No Matlab toolboxes are supported (ie translated)

@vv 

eval() is irrelevant.


Only the format of the file matters
Saving to Maple internal format (aka '.m' extension) retains the "link" between two quantities.
Saving in any other format does not
I had always assumed that this was a known, deliberate, "feature"

See the attached

  restart;
  A:= Matrix(2, 2, [ [a, b],
                     [c, d]
                   ]
             ):
  B:= A:
  B[1,1]:= x:
  A, B, addressof(A)-addressof(B);

  fname1:= "C:/Users/TomLeslie/Desktop/test1.m":
  fname2:= "C:/Users/TomLeslie/Desktop/test2.m":
  fname3:= "C:/Users/TomLeslie/Desktop/test3":

  save A, B, fname1; # save in Maple internal format
  save B, A, fname2; # save in Maple internal format (different order)
  save A, B, fname3; # save in Maple language format (aka 'mpl')
#
# Unassign variables then load from Maple
# internal format
#
  A,B:= 'A', 'B':
  read fname1:
  B[1,1]:= y:
  A, B, addressof(A)-addressof(B);
#
# Unassign variables then load from Maple
# internal format
#
  A,B:= 'A','B':
  read fname2:
  B[1,1]:= y:
  A, B, addressof(A)-addressof(B);
#
# Unassign variables and load from Maple
# language format
#
  A,B:= 'A','B':
  read fname3:
  B[1,1]:= y:
  A, B, addressof(A)-addressof(B);

Matrix(2, 2, {(1, 1) = x, (1, 2) = b, (2, 1) = c, (2, 2) = d}), Matrix(2, 2, {(1, 1) = x, (1, 2) = b, (2, 1) = c, (2, 2) = d}), 0

 

Matrix(2, 2, {(1, 1) = y, (1, 2) = b, (2, 1) = c, (2, 2) = d}), Matrix(2, 2, {(1, 1) = y, (1, 2) = b, (2, 1) = c, (2, 2) = d}), 0

 

Matrix(2, 2, {(1, 1) = y, (1, 2) = b, (2, 1) = c, (2, 2) = d}), Matrix(2, 2, {(1, 1) = y, (1, 2) = b, (2, 1) = c, (2, 2) = d}), 0

 

Matrix(%id = 18446744074368008310), Matrix(%id = 18446744074368008430), -120

(1)

 

 


 

Download link.mw

@Daniel Skoog 

How to plot one column against another?? In your example Dataframe, use dataplot() to put 'SepalLength' on the x-axis and 'PetalWidth' on the y-axis. I tried al sorts of tricks to achieve this and failed miserably. Can it be done?

I tried all sorts of tricks and eventually I gave up and converted the DataFrame to a matrix, where requiring one column as x-values and another column as y-values is trivial. Dataframes seem to be 'hardwired' so that columns can only be plotted against the 'zeroth' column, aka the row index.

First reference ot add() I can find is from Maple 9 updates, where it states

The following example runs in 160 seconds on Maple 8 but only in 6 seconds on Maple 9.
Examples
add(1/k^2, k=1..100000):

So add() existed in Maple 8, which is circa 2002 - but (like Carl), I'm pretty sure sure it is *much* earlier: I just can't find out *exactly* when

@mkotecha 

That is

If the user supplies ranges for the variables, then (random) Uniform Sampling of these ranges is performed, to generate (by default) 30 possible initial values. (You can change this value with the option 'number'.) The routine Search() is called with each of these start values, to obtain a 'local' optimum. The best of these 'local optima' is retained as the 'global optimum'

@Carl Love
I'd be a little careful with this recommendation. See the attached

restart;

#
# The expression gcd(x,y) will return 1,
# for obvious reasons explained in the
# help pages.
#
# Equally obviously, one can 'return' the
# expression unevaluated, by enclosing it
# in unevaluation quotes,
#
# Both are illustrated in the following
#
  a:= gcd(x, y);
  b:= 'gcd(x, y)';
  eval(b);

1

 

gcd(x, y)

 

1

(1)

#
# Now you might be able to control the output
# display by using a command from the
# Typesetting() package. Although my personal
# view is that undocumented commands are often
# undocumented for a reason.
#
# The output might 'look' the way you want, but
# can you ever evaluate/parse/convert it to
# anything meaningful? Does this matter?
#
  c:= Typesetting:-mn(gcd)(x,y);
  eval(c);

(Typesetting:-mn(gcd))(x, y)

 

Parse:-ConvertTo1D, "invalid input %1", (Typesetting:-mn(gcd))(x, y)

(2)

 

Download gcdTypeset.mw

With the definition

y(x-0.8)=21.70160211*(x-.8)^2-35.93499295*x+47.74799436

then for any supplied value of the argument 'x', 'y(x-0.8)' will return exactly one value. The graph attached to your original question has multiple values of 'y(x-0.8)' for a single supplied argument.

What am I missing????

@mkotecha 

If you provide no ranges for the variables and no initial point - how would you expect an 'initial point' to be selected?

By magic?? Guesswork?? The DirectSearch:-GlobalOptima() command guesses, which is probably why the help for this command states

It is recommended that you try different initial point set with each problem or repeat search several times to verify that the solution is indeed an global extremum.

So far as I can tell from the output of the command

showstat(GlobalOptima);

if absolutely no information about the values/ranges of input variables is given, then all input variables are assigned to 0.009 (I said 0.9 in my original post - this was an error on my part). I draw your attention to lines 87-88 of the output from showstat(GlobalOptima), which states

87   if initialpoints = NULL and pointrange = NULL then
88       s1 := [seq(.009,i = 1 .. n)];

The variables set in 's1' are then used as an 'initial point' in the first call to DirectSearch:-Search() at line 91 (of the output from showstat(DirectSearch))

#########################################################################

When you state

"Also, the bounds of the variables are not between 0 and 1 for all the variables."

I have no idea what you are getting at. Nothing in my original response made any assumption about the range of the variables. The DirectSearch:-GlobalOptima() also makes no assumptions about the the variable ranges. So what exactly is your point??

@isifesai 

The attached will produce one of the plots you want. The other plot command refers to 'exact solution'. Since none of 'exact', 'solution' or 'exact solution' are mentioned anywhere in your original worksheet, I have no idea what you intend to be plotted by this command!

restart; with(student)

n := 2

2

(1)

v := sum(u[i]*p^i, i = 0 .. 2)

p^2*u[2]+p*u[1]+u[0]

(2)

f := proc (x) options operator, arrow; exp(x)+(1/2)*x*(exp(2*x)-1) end proc

proc (x) options operator, arrow; exp(x)+(1/2)*x*(exp(2*x)-1) end proc

(3)

"k(x,t):=x;"

proc (x, t) options operator, arrow, function_assign; x end proc

(4)

F := proc (u) options operator, arrow; u^2 end proc

proc (u) options operator, arrow; u^2 end proc

(5)

u[0] := f(t)

exp(t)+(1/2)*t*(exp(2*t)-1)

(6)

for i to 2 do u[i] := expand(subs(x = t, int(coeff(p*k(x, t)*F(v), p^i), t = 0 .. x))) end do

s := value(sum(u[k], k = 0 .. 2))

(1/2)*t*(exp(2*t)-1)+exp(t)+(396536351/311040000)*t-(1/72)*t^7+(1/6)*exp(t)*t^5+(1/3)*exp(t)*t^4-2*exp(t)*t^3-(1/6)*(exp(t))^2*t^4+(11/120)*(exp(t))^5*t^4-(5/64)*(exp(t))^4*t^5+(1/24)*(exp(t))^2*t^6-(11/18)*(exp(t))^3*t^4-(7/576)*(exp(t))^6*t^4+(17/2304)*(exp(t))^6*t^3+(1/96)*(exp(t))^6*t^5-(17/6912)*(exp(t))^6*t^2-(323/3600)*(exp(t))^5*t^3+(19/128)*(exp(t))^4*t^4+(17/41472)*(exp(t))^6*t+(2809/72000)*(exp(t))^5*t^2+(1/48)*(exp(t))^2*t^5-(2809/360000)*(exp(t))^5*t+(31/27)*(exp(t))^3*t^3+(1753/3456)*t^4+(263/576)*exp(t)*t^2-(263/576)*exp(t)*t+(161/768)*(exp(t))^4*t^3-(739/4608)*(exp(t))^4*t^2+(739/18432)*(exp(t))^4*t-(59/324)*(exp(t))^3*t^2-(4201/2304)*(exp(t))^2*t^3+(59/972)*(exp(t))^3*t+(6505/2304)*(exp(t))^2*t^2-(4201/4608)*(exp(t))^2*t

(7)

"U(x):=collect(s, x);"

proc (x) options operator, arrow, function_assign; collect(s, x) end proc

(8)

with*plots

p1 := plot(exact*solution, t = 0 .. 5, style = point)

Warning, expecting only range variable t in expression exact*solution to be plotted but found names [exact, solution]

 

p2 := plot(U(t), t = 0 .. 5, style = line)

 

plots[display](p1, p2)

 

NULL

Download primes2.mw

 

 

@elisha10 

which I think(?) contains the information you require

restart;

#
# Set up numerical values for all problem parameters
#
  params:=[       k=.5,         tau=.95,      mu=0.1e-1,
                 pi=116.1, vartheta=0.8e-2,  phi=0.25e-2,
            epsilon=0.2e-2,     rho=0.5e-1, beta=0.115e-1,
                chi=0.598e-2,     q=.5,      eta=.2,
              delta=.1,       alpha=0.57e-1,   p=.2,
            Upsilon=1.2
          ]:

#
# Define main function
#
  R:= k*tau*(rho*(Upsilon*(mu+alpha+eta)+chi)+(1-rho)*(Upsilon*(1-q)*eta+mu+beta+chi))
      *
      (pi*(-mu*p+mu+phi)/(mu*(vartheta+mu+phi))+epsilon*pi*(mu*p+vartheta)
      /
      (mu*(vartheta+mu+phi)))/((mu+beta+chi)*(mu+alpha+eta)-chi*eta*(1-q));

k*tau*(rho*(Upsilon*(mu+alpha+eta)+chi)+(1-rho)*(Upsilon*(1-q)*eta+mu+beta+chi))*(pi*(-mu*p+mu+phi)/(mu*(vartheta+mu+phi))+epsilon*pi*(mu*p+vartheta)/(mu*(vartheta+mu+phi)))/((mu+beta+chi)*(mu+alpha+eta)-chi*eta*(1-q))

(1)

#
# Compute "all" derivatives and evaluate numerically.
#
# For the purposes of this calculation "all"
# derivatives, means the derivatives with respect to
# every variable returned by indets(R, name)
#
# Output a list of two element lists where each of
# the latter is
#
# [ varName,
#   eval( diff( R, varName), params )
# ]
#
# [ seq( [j, eval( diff( R, j), params )],j in indets(R, name))];

#
# Compute all "sensitivities" (where the sensitivity
# is as defined in Rouben Rostamian response to the
# OP's earlier post) and evaluate numerically.
#
# For the purposes of this calculation "all" sensitivities
# means the sensitivity with respect to every variable
# returned by indets(R, name)
#
# Output a list of two element lists where each of
# the latter is
#
# [ varName,
#   eval( varName*diff( R, varName)/R, params )
# ]
#
  seq( [j, eval( j*diff( R, j)/R, params )],j in indets(R, name));

[Upsilon, .8311970593], [alpha, -.2105630804], [beta, -.3857788046], [chi, -.1099584247], [epsilon, 0.1901140685e-2], [eta, 0.7870103093e-1], [k, 1], [mu, -1.099369098], [p, -.1897338403], [phi, .1156913660], [pi, 1.000000000], [q, -.8175188560], [rho, 0.5718395397e-1], [tau, 1], [vartheta, -.3887229899]

(2)

#
# Pick one of the variables, define lower
# and upper limits for this variable, along
# with a step size
#
  symb:=beta:
  lsymb:= 0.1:
  usymb:= 0.2:
  tsymb:= 0.01:
#
# Compute the "sensitivity" of all parameters
# for all values of the above selected symbol
#
  params:= [ seq
             ( `if`( lhs(j)=symb,
                     NULL,
                     j
                   ),
              j in params
             )
           ]:
  sens:= [ seq
           ( [ j, [ seq
                    ( [ zz,
                        eval
                        ( j*diff( R, j)/R,
                          [params[], symb=zz]
                        )
                      ],
                      zz = lsymb..usymb, tsymb
                    )
                  ]
             ],
             j in indets(params)
           )
         ]:
#
# Produce all the relevant plots
#
  getPlot:= sym -> seq
                   ( `if`
                     ( j[1]=sym,
                       plots:-pointplot
                              ( j[2],
                                style=line,
                                title=j[1],
                                titlefont=[times, bold, 20],
                                labels=['beta', 'sens'],
                                labelfont=[times, bold, 16],
                                axes=boxed
                              ),
                       NULL
                     ),
                     j in sens
                   ):
  for j in indets(R, name) do
      getPlot(j);
  od;

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Download sens2.mw

There isn't really enough information here to determine exactly what you want.

As a general guide, read the help pages for DynamicSystems(). This has commands which will allow you to define your system using a variety of formats (ODES, pole-zero, state-space matrices, etc). It also contains commands for inspecting, characterising and simulating the system

@Markiyan Hirnyk 

In the attached I have performed the same calculation as vv but in a less 'sophisticated' way. The process is as follows

  1. Use the first of the original equations to eliminate x3 from the second and third equations
  2. Reorganise the resulting two equations to two expressions, which we can be tested for value. In other words, given 'a=b', organise this as 'a-b=0', and retain the expression a-b
  3. Evaluate these two expressions for ranges of the arguments x1 and x2, if the result is [0,0], then retian the value of [x1,x2] as a valid point
  4. Plot all the valid points [x1,x2] satisfying the two expressions
  5. If desired, use all the valid points [x1, x2] and the first of the originl equations to compute the associated value of x3, and plot all the valid triples

The only problem I have with this calculation was vv's assertion that "It is easy to obtain  60 < x1 < 85,  50 < x2 < 70".  I haven't been able to convince myself of this, which is probably down to my stupidity. However some restriction on the values of x1 and x2 is necessary, in order to make step 3 of the process above feasible, so I have used it without question.

The attached uses no clever plotting (or any other) commands, just a couple of 'seq()' commands to cycle through possible values for x1, x2. Over the ranges 60 < x1 < 85,  50 < x2 < 70 it appears to give the same answers - althoug I would like to know how these ranges were obtained!!

  restart;
#
# Derive 'simplified' pair of expressions
# from OP's  original input
#
  eqns1:={ 4*x1+7*x2+6*x3 = 186,
          floor((1/2)*x1)+floor((1/5)*x2)+floor((1/3)*x3) = 18,
          floor((1/5)*x1)+floor((1/2)*x2)+floor((1/4)*x3) = 21
         }:
#
# Eliminate x3 from the second and third equations
#
  eqns2:=[ subs( isolate( eqns1[1], x3), eqns1[2]),
           subs( isolate( eqns1[1], x3), eqns1[3])
         ]:
#
# Shift rhs to lhs, to get two expressions
# (which one can test for as zero-valued
#
  eqns3:=[ lhs(eqns2[1])-rhs(eqns2[1]),
           lhs(eqns2[2])-rhs(eqns2[2])
         ]:
#
# Define a function to evaluate the above
# pair of expressions for any supplied arguments
# (We will be looking for the case where both
# expressions return zero
#
  f:=(p,q) -> eval( eqns3, [x1=p, x2=q]):
#
# Specify the limits for x1 and z2
#
  x1lim:=[60, 85]:
  x2lim:=[50, 70]:
#
# For the ranges of values for x1 and x2 defined
# above, evaluate the pair of expressions. If both
# are zero, then retain the argument pair, otherwise
# discard

  ans1:=[ seq
          ( seq
            ( `if`( f(i,j)=[0,0],
                    [i,j],
                    NULL
                  ),
              i = x1lim[1]..x1lim[2], (x1lim[2]-x1lim[1])/501
            ),
            j = x2lim[1]..x2lim[2], (x2lim[2]-x2lim[1])/501
          )
        ]:
#
# Plot all the points for which the solution
# is valid
#
  plots:-pointplot( ans1,
                    view=[ x1lim[1]..x1lim[2],
                           x2lim[1]..x2lim[2]
                         ],
                    labels=[x1, x2],
                    labelfont=[times, bold, 16]
                  );
#
# Use the results derived above and the first
# equation in the original set to get the value
# of x3, for each pair of values x1, x2 in ans1
# and plot the triple in 3d
#
  ans2:=[ seq( [ ans1[j][1],
                 ans1[j][2],
                 rhs
                 ( isolate
                   ( eval
                     ( eqns1[1],
                       [ x1=ans1[j][1],
                         x2=ans1[j][2]
                       ]
                     ),
                     x3
                   )
                 )
               ],
               j=1..numelems(ans1)
             )
        ]:
  plots:-pointplot3d( ans2,
                      view=[ x1lim[1]..x1lim[2],
                             x2lim[1]..x2lim[2],
                             min(seq(ans2[j][3], j=1..numelems(ans2)))..max(seq(ans2[j][3], j=1..numelems(ans2)))
                           ],
                      color=black,
                      labels=[x1, x2, x3],
                      labelfont=[times, bold, 16]
                    );

 

 

 

Download floorPlots.mw

Maple can solve the OP's PDE symbolically using

restart;
pde:=diff(u(x,t),t)+epsilon*u(x,t)*diff(u(x,t),x)+mu*diff(u(x,t),x$3)=0;
pdsolve(pde);

Solution is given with three arbitrary constants. From the orders of the differential terms (ie one in 't' and three in 'x') I was expecting(?) four constants, but I'll let that pass for now. However, in order to obtain an explicit solution, at least three (maybe four?) boundary/initial conditions are required.

OP presents a (more or less) random function of the independent variables 'x' and 't', labelled as an 'initial' condition  although since it can be evaluated for all 'x', all 't', this is neither a 'boundary' nor an 'initial' condition, so is a bit useless

I am completely unfamiliar with the 'Adomian Decomposition Method', but I'm pretty sure that no one has yet come up with a way of solving a PDE with combined-order four, without four boundary/initial conditions - so this exercise is doomed to failure

 

The file you uploaded contains only NULL characters - nothing can be recovered from this.

Depending exactly on how the corruption occurred, there is a (small) chance that a backup of the original file, produced by Maple's 'autosave' process, may still exist. Try

File -> Recent Documents -> Restore Backup

If that still doesn't produce anything, then just doublecheck whether you have a file called 2.G_anden_aflevering.bak. created by Maple's autosave process. (If it exists, this file will probably be in the same directory as the corrupted file 2.G_anden_aflevering.mw)

@acer 

If you really believe that the evalf/simplify thing is significant (which in this case I don't), it is trivial to make this happen only once, as in

restart;
with(ScientificConstants):
En:=unapply( -simplify(evalf(Constant(c, units)*Constant(h, units)*Constant(R[infinity], units)))/n^2,n);
En(1);
En(4);

 

First 84 85 86 87 88 89 90 Last Page 86 of 207