tomleslie

5505 Reputation

17 Badges

9 years, 345 days

MaplePrimes Activity


These are answers submitted by tomleslie

I have tried the technique of mouse-selecting the desired 2-D output expression and using the context menu sequence

Copy Special -> Copy as MathML

then a simple CTRL-V (ie paste) in the target application. This sometimes works, and sometimes doesn't! Success or failure appears to depend on both the target application and the filename extension which I specify in the target application.

Since you do not specify your "target" application, I can't specify a command sequence which will definitely work with this approach.

On the other hand, if I add an execution group to your worksheet as shown in the attached, then it always(?) produces the output file testML.txt which looks OK to me (I'm not a mathML guru).

You willl have to change the target file name to something appropriate for your machine

restart:

n:= 2:

X:= Vector(n, symbol= x);

Vector(2, {(1) = x[1], (2) = x[2]})

(1)

W:= Matrix(3,2, symbol= w);

Matrix(3, 2, {(1, 1) = w[1, 1], (1, 2) = w[1, 2], (2, 1) = w[2, 1], (2, 2) = w[2, 2], (3, 1) = w[3, 1], (3, 2) = w[3, 2]})

(2)

V:= W.X;

Vector(3, {(1) = w[1, 1]*x[1]+w[1, 2]*x[2], (2) = w[2, 1]*x[1]+w[2, 2]*x[2], (3) = w[3, 1]*x[1]+w[3, 2]*x[2]})

(3)

answer:=seq(diff~(v,W), v= V);

answer := Matrix(3, 2, {(1, 1) = x[1], (1, 2) = x[2], (2, 1) = 0, (2, 2) = 0, (3, 1) = 0, (3, 2) = 0}), Matrix(3, 2, {(1, 1) = 0, (1, 2) = 0, (2, 1) = x[1], (2, 2) = x[2], (3, 1) = 0, (3, 2) = 0}), Matrix(3, 2, {(1, 1) = 0, (1, 2) = 0, (2, 1) = 0, (2, 2) = 0, (3, 1) = x[1], (3, 2) = x[2]})

(4)

fname:="C:/Users/TomLeslie/Desktop/testML.xml";
XMLTools:-PrintToFile(fname, MathML:-Export(X));
XMLTools:-PrintToFile(fname, MathML:-Export(W));
XMLTools:-PrintToFile(fname, MathML:-Export(V));
XMLTools:-PrintToFile(fname, MathML:-Export(answer[1]));
XMLTools:-PrintToFile(fname, MathML:-Export(answer[2]));
XMLTools:-PrintToFile(fname, MathML:-Export(answer[2]));
close(fname):

"C:/Users/TomLeslie/Desktop/testML.xml"

(5)

 

Download toMML.mw

is shown in the attached

  restart;
  with(plots):
  animate( implicitplot,
           [ x = -3*abs(sin(y)),
             x = -3 .. 3,
             y = 0 .. t,
             thickness = 5,
             size = [150, 150],
             axes = none,
             color = red
           ],
           t=0..6
         );

 

 

Download animimpl.mw

using complexplot3d() is shown in the attached.

Easy to change the options for 'grid', 'transparency', 'thickness', 'colorscheme', etc etc

I haven't bothered redefining sqrt(-1) - so the attached uses the default 'I'.

  restart;
  with(plots):
  with(plottools):
  Aplot:= (fn, p1)-> complexplot3d
                     ( fn,
                       z=-1-I..1+I,
                       if   p1='surface'
                       then style=surface,
                            transparency=0.8
                       else style=wireframe,
                            grid=[10,10],
                            thickness=4
                       fi,
                       colorscheme=[ "zcoloring",
                                     z->z
                                   ]
                     ):
  Bplot:= fn-> display
               ( [ Aplot(fn, 'surface'),
                   Aplot(fn, 'wireframe'),
                   reflect( Aplot(fn, 'surface'),
                            [ [0,0,0], [1,0,0], [0,1,0] ]
                          ),
                   reflect( Aplot(fn,'wireframe'),
                            [ [0,0,0], [1,0,0], [0,1,0] ]
                          )
                 ]
               ):
   Bplot( Re(sqrt(z)) );
   Bplot( sqrt(z) );

 

 

 

 

Download comploit.mw

otherwise the solution still contains an integration constant.

See the attached

  restart;
  ode:=diff(y(x),x,x)-y(x)=-4*sin(x)^3+9*sin(x);
#
# Solve the ode, subject to the bc
#
  ans:=dsolve([ode, y(0)=y(2*Pi)]);
#
# "Simplify" this solution.
#
# Note that another boundary conditon is necessary
# in order to evaluate the integration constant _C1
#
  ans:= op(1, ans)=simplify(add(op([2,1..2], ans)))+add(op([2,3..4], ans));

diff(diff(y(x), x), x)-y(x) = -4*sin(x)^3+9*sin(x)

 

y(x) = -exp(-x)*_C1*(exp(2*Pi)-1)/(exp(-2*Pi)-exp(2*Pi))+exp(x)*_C1*(exp(-2*Pi)-1)/(exp(-2*Pi)-exp(2*Pi))-(1/10)*sin(3*x)-3*sin(x)

 

y(x) = (exp(2*x)+exp(2*Pi))*_C1*exp(-x)/(exp(2*Pi)+1)-(1/10)*sin(3*x)-3*sin(x)

(1)

#
# Explicit solutions can be obtained if one sets
# y(0)=y(2*Pi)=some_numeric_value - as in (for
# example)
#
  ans2:=dsolve([ode, y(0)=0, y(2*Pi)=0]);
  ans2:=dsolve([ode, y(0)=1, y(2*Pi)=1]);
  ans2:=dsolve([ode, y(0)=2, y(2*Pi)=2]);

y(x) = -(1/10)*sin(3*x)-3*sin(x)

 

y(x) = -(exp(2*Pi)-1)*exp(-x)/(exp(-2*Pi)-exp(2*Pi))+exp(x)*(exp(-2*Pi)-1)/(exp(-2*Pi)-exp(2*Pi))-(1/10)*sin(3*x)-3*sin(x)

 

y(x) = -2*(exp(2*Pi)-1)*exp(-x)/(exp(-2*Pi)-exp(2*Pi))+2*exp(x)*(exp(-2*Pi)-1)/(exp(-2*Pi)-exp(2*Pi))-(1/10)*sin(3*x)-3*sin(x)

(2)

 


 

Download odeSol.mw

whhc is trying to plot a "surface". You are only getting a line because the way you are defining the "surface", it has zero width in one dimension. (Nothing depends on your plot variable 't')

To plot  curves in 3D, your best bet is probably to use spacecurve(). You can color these in a variety of ways, just by setting the HSV or RGB triple  ot be dependent on 'i' and 'j'.

One possibility is shown in the attached

  restart:
  with(plots):
  display
  ( seq
    ( seq
      ( spacecurve
        ( [i/sin(u), u, j],
          u = 0.00001 .. 3/2,
          color=ColorTools:-Color("HSV", [i*j/100, 0.5, 0.5]),
          thickness=5,
          view = [0 .. 10, 0 .. Pi/2, 0 .. 10]
        ),
        i=1..10
      ),
      j=1..10
    )
  );

 

 


 

Download hueplot.mw

  1. Your original setup of seven loops will execute 20000000 times
  2. The conditions for executing the solve() command ( ie a > c and igcd(a, b, c, d, t, m, n) = 1 and abs(b)+abs(d)-n <> 0 ) will be satisfied 853750 times (out of the possible 20000000)
  3. How long might it take for a single 'solve()' command to execute. Make the (rash?) assumption that it might be ~0.1 seconds, so that the total execution time for the 'solve()' operations will be 85375 seconds or about 23.7hours
  4. You have two choices
    1. Wait a long time
    2. Consider whether a different approach to the problem might be feasible

it usually helps if you put the parentheses in the correct places, as in the attached - which is what I assume you want

(I have changed the plot range from x=0..2 to x=0..0.2, just so the different curves can be displayed)

L := proc(N) N; end:
plot( [seq( L(min(5, max(-5, 5^(x*10) + 5^(x*k)))), k=0..10)], x=0..0.2);

 

 

Download seqPlot.mw

 

 

is shown in the attached

  restart;
  A:= Matrix(4, 8, [ [-1, 1-t, 0, 0, 0, 0, 0, 0],
                     [0, 0, 1, 1+t, 0, 0, 0, 0],
                     [0, 0, 0, 0, -1, 1-t, 0, 0],
                     [0, 0, 0, 0, 0, 0, 1, 1+t]
                   ]
             );
  B:= Matrix(4, 8, [ [-1, 1-t1, 0, 0, 0, 0, 0, 0],
                     [0, 0, 1, 1+t1, 0, 0, 0, 0],
                     [0, 0, 0, 0, -1, 1-t2, 0, 0],
                     [0, 0, 0, 0, 0, 0, 1, 1+t2]
                   ]
            );
#
# Define function which generates target matrix from
# supplied matrix
#
  genMat:= M-> Matrix( op(1, A),
                       (i,j)-> subs( t=cat(t, iquo(i-1, 2)+1),
                                     A[i,j]
                                   )
                     );
  C:=genMat(A);
#
# Check B=C
#
  LinearAlgebra:-Equal(B, C);

Matrix(4, 8, {(1, 1) = -1, (1, 2) = 1-t, (1, 3) = 0, (1, 4) = 0, (1, 5) = 0, (1, 6) = 0, (1, 7) = 0, (1, 8) = 0, (2, 1) = 0, (2, 2) = 0, (2, 3) = 1, (2, 4) = 1+t, (2, 5) = 0, (2, 6) = 0, (2, 7) = 0, (2, 8) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = 0, (3, 4) = 0, (3, 5) = -1, (3, 6) = 1-t, (3, 7) = 0, (3, 8) = 0, (4, 1) = 0, (4, 2) = 0, (4, 3) = 0, (4, 4) = 0, (4, 5) = 0, (4, 6) = 0, (4, 7) = 1, (4, 8) = 1+t})

 

Matrix(4, 8, {(1, 1) = -1, (1, 2) = 1-t1, (1, 3) = 0, (1, 4) = 0, (1, 5) = 0, (1, 6) = 0, (1, 7) = 0, (1, 8) = 0, (2, 1) = 0, (2, 2) = 0, (2, 3) = 1, (2, 4) = 1+t1, (2, 5) = 0, (2, 6) = 0, (2, 7) = 0, (2, 8) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = 0, (3, 4) = 0, (3, 5) = -1, (3, 6) = 1-t2, (3, 7) = 0, (3, 8) = 0, (4, 1) = 0, (4, 2) = 0, (4, 3) = 0, (4, 4) = 0, (4, 5) = 0, (4, 6) = 0, (4, 7) = 1, (4, 8) = 1+t2})

 

genMat := proc (M) options operator, arrow; Matrix(op(1, A), proc (i, j) options operator, arrow; subs(t = cat(t, iquo(i-1, 2)+1), A[i, j]) end proc) end proc

 

Matrix(%id = 18446744074221117918)

 

true

(1)

 

Download getMat.mw

In general, the Optimization:-Minimize() command will return a single local minimum.

Even if a global minimum exists, it is not guaranteed that Minimize() will find it, unless the function is convex. The command may return a (less-optimal) local minimum instead.

Where there are multiple equivalent local  minima, then the Minimze() command will return one of these, determined mainly by the value of the option 'initialpoint'. In general one will obtain the local minimum, "closest" to the initial point

One can find multiple local minima, simply by varying the initial point.

Try experimenting with the function sin(x+y), as in the code below. This has  minima whenever x+y=-Pi/2+2*n*Pi, for integer n

restart;
for i from -5 by 2 to 5 do
    for j from -5 by 2 to 5 do
        try
            res[i,j]:=Optimization:-Minimize( sin(x+y), initialpoint=[x=i, y=j])[2];
        catch "no improved point could be found":
        end try
    od;
od;
eval(res);


 

I can't see why these two expressions should *necessarily* give similar answers!

There is an interesting (possible typo?) in your first expression,where you have

h__2(h__1+h__2)

Should there be an arithmetic operator in here?

Maybe

h__2*(h__1+h__2)

to calculate "quartiles", each of which has a slightly different definition. Depending on data, they may (or may not!) give the same answers.

All methods are illustrated in the attached (which for some reason won't display inline on this site....use of dataframe???)

By default Maple uses method=7. I'm guessing that you would prefer to use method=4

Download quartiles.mw

is shown in the attached

  restart;
#
# Define function whihc builds required matrix
#
  doMat:= (n::integer)-> Matrix(n+1, n+1, (i,j)->`if`(j=i+1, i,0)):
#
# Examples of use
#
  M:=doMat(4);
  M:=doMat(8);

Matrix(5, 5, {(1, 1) = 0, (1, 2) = 1, (1, 3) = 0, (1, 4) = 0, (1, 5) = 0, (2, 1) = 0, (2, 2) = 0, (2, 3) = 2, (2, 4) = 0, (2, 5) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = 0, (3, 4) = 3, (3, 5) = 0, (4, 1) = 0, (4, 2) = 0, (4, 3) = 0, (4, 4) = 0, (4, 5) = 4, (5, 1) = 0, (5, 2) = 0, (5, 3) = 0, (5, 4) = 0, (5, 5) = 0})

 

Matrix(%id = 18446744074382795230)

(1)

 

Download makeMat.mw

is shown in the attached

  restart:
  x:= 12: y:= 46: s:= 0:
  L:= NULL:
  while 0 < y do
        if   type(y, odd)
        then s:= s + x:
             y:= y - 1:
        else x:= 2*x:
             y:= y/2:
        end if;
        L:= L,x,y,s;
  end do:
  L:= [L];

[24, 23, 0, 24, 22, 24, 48, 11, 24, 48, 10, 72, 96, 5, 72, 96, 4, 168, 192, 2, 168, 384, 1, 168, 384, 0, 552]

(1)

 

Download makeList.mw

You may want to read the help page for the 'table' constructor which states (my emphasis)

Tables have special evaluation rules (like procedures) so that if the name T has been assigned a table then T evaluates to T. The call op(T) yields the actual table structure;

You may want to consider the attached

restart;
#Define a table;
T := table(symmetric, [(1,1) = 1,(2,2)=1,(3,3)=1,(4,4)=1,(1,2)=1,(1,3)=1,(1,4)=1,(2,3)=1,(2,4)=1,(3,4)=1]);

table( [( 1, 2 ) = 1, ( 1, 3 ) = 1, ( 2, 2 ) = 1, ( 1, 1 ) = 1, ( 1, 4 ) = 1, ( 3, 4 ) = 1, ( 3, 3 ) = 1, ( 2, 4 ) = 1, ( 4, 4 ) = 1, ( 2, 3 ) = 1 ] )

(1)

type(T,'table');
type(T,'name');
type(T,'symbol');
type(eval(T),'table');

true

 

true

 

true

 

true

(2)

type(op(1,T), 'table');
type(op(1,T), 'name');
type(op(1,T), 'symbol');

true

 

false

 

false

(3)

 

Download aTable.mw

 

Firstly the method suggested by MacDude - the 'size' option will only work for 2D plots

Secondly you can achieve a 'similar' effect by setting defaults for the parameters in the procedure provided by Acer here

https://www.mapleprimes.com/questions/228539-Set-Size-Of-3D-Plot

As example to set the default size to [1000,500]

setPlotSize:=proc(P, sz::[posint,posint]:=[1000,500])
  op(0,P)(remove(type,[op(P)],'specfunc(ROOT)')[],
          ROOT(BOUNDS_X(0),BOUNDS_Y(0),
               BOUNDS_WIDTH(sz[1]),BOUNDS_HEIGHT(sz[2])));
end proc:

1 2 3 4 5 6 7 Last Page 1 of 121