tomleslie

13876 Reputation

20 Badges

15 years, 168 days

MaplePrimes Activity


These are answers submitted by tomleslie

  1. Either use' evalc()', so that Maple is forced to evaluate expressions with the assumption that al unknown names are real
  2. Or, use the 'assume()' facility to explicitly declare certain variables as 'real'

Both methods are shown in the attached

#
# Use 'evalc()' to ensure that all expressions
# evaluate with the 'assumption' that any anknown
# names are real
#
  restart:
  alias(conj=conjugate);

  d := a*x+b*y-c = 0;
  z := x+I*y;
  evalc(z+conj(z));
  evalc(z-conj(z));

  d := evalc((1/2)*a*(z+conj(z))+b*(z-conj(z))/(2*I)-c);

  is(d = (1/2)*evalc(z*(a-I*b)+conj(z)*(a+I*b)-2*c));

  varpi:= a+I*b;
  is(d = (1/2)*evalc(z*conj(varpi)+conj(z)*varpi-2*c));

conj

 

a*x+b*y-c = 0

 

x+I*y

 

2*x

 

(2*I)*y

 

a*x+b*y-c

 

true

 

a+I*b

 

true

(1)

#
# Use assumptions to specify certain names are
# real
#
  restart:
  alias(conj=conjugate):
  assume(a::real, b::real, x::real, y::real):
  interface(showassumed=0);

  d:= a*x+b*y-c = 0;
  z:= x+I*y;
  z+conj(z);
  z-conj(z);

  d:= (1/2)*a*(z+conj(z))+b*(z-conj(z))/(2*I)-c;

  is(d = (1/2)*(z*(a-I*b)+conj(z)*(a+I*b)-2*c));

  varpi:= a+I*b;
  is(d = (1/2)*(z*conj(varpi)+conj(z)*varpi-2*c));

1

 

a*x+b*y-c = 0

 

x+I*y

 

2*x

 

(2*I)*y

 

a*x+b*y-c

 

true

 

a+I*b

 

true

(2)

 

Download cplex.mw

For a finite number of terms it is generally a better idea to use add() rather than sum() - particularly if there is absolutely no prospect that the call to sum() wii return a "closed form" expression.

In principle, if sum() cannot find a "closed-form" solution, the it should default to add() - but there seems to be a difference: see the attached.

So I don;t think this is actually a 0^0 issue

  restart;
  f:=x->exp(x);
  p:=n->(x->sum( a[j]*x^j, j=0..n));
  p2:=p(2);
  bed:={p2(0)=f(0), D(p2)(0)=D(f)(0), (D@@2)(p2)(0)=(D@@2)(f)(0)}

proc (x) options operator, arrow; exp(x) end proc

 

proc (n) options operator, arrow; proc (x) options operator, arrow; sum(a[j]*x^j, j = 0 .. n) end proc end proc

 

proc (x) options operator, arrow; sum(a[j]*x^j, j = 0 .. 2) end proc

 

{0 = 1, a[1] = 1, 2*a[2] = 1}

(1)

  restart;
  f:=x->exp(x);
  p:=n->(x->add( a[j]*x^j, j=0..n));
  p2:=p(2);
  bed:={p2(0)=f(0), D(p2)(0)=D(f)(0), (D@@2)(p2)(0)=(D@@2)(f)(0)}

proc (x) options operator, arrow; exp(x) end proc

 

proc (n) options operator, arrow; proc (x) local j; options operator, arrow; add(a[j]*x^j, j = 0 .. n) end proc end proc

 

proc (x) local j; options operator, arrow; add(a[j]*x^j, j = 0 .. 2) end proc

 

{a[0] = 1, a[1] = 1, 2*a[2] = 1}

(2)

  

 

Download sumadd.mw

"inflection points are where the gradient of the function is zero - that's the first derivative, not the second as given by Kitonum.

The attached worksheet plots

  1. the function fprime_expr
  2. the "roots" of the function fprime_expr, ie the points at which fprime_expr=0
  3. the "inflection points" of the function fprime_expr, ie the points at which diff(fprime_expr, x)=0

  restart:
  with(plots):
  fprime_expr:=x^sin(x)*(cos(x)*ln(x)+sin(x)/x):
  getRoots:=proc( g::procedure)
                  local x__old:=0,
                        x__new:=[],
                        rt:
                  while true do
                        rt:= RootFinding:-NextZero(g, x__old):
                        if   rt <10
                        then x__new:=[x__new[], rt];
                             x__old:=x__new[-1];
                        else break;
                        fi;
                  od:
                  return x__new
            end proc:       

#
# Plot the curve given by fprime_expr
#
  p1:= plot(fprime_expr, x=0..10):
#
# Plot the "roots" of the function fprime_expr
# ie the points where fprime_expr=0
#
  p2:= pointplot( [ seq( [j, eval(fprime_expr, x=j)],
                        j in getRoots( unapply(fprime_expr,x))
                      )
                  ],
                  symbol=solidcircle,
                  symbolsize=20,
                  color=red
                ):

#
# Plot the "inflection points" of the function fprime_expr
# ie the points where diff( fprime_expr, x) = 0
#
  p3:= pointplot( [ seq( [j, eval(fprime_expr, x=j)],
                         j in getRoots( unapply(diff(fprime_expr,x),x))
                       )
                  ],
                  symbol=solidcircle,
                  symbolsize=20,
                  color=blue
                ):
  display([p1,p2, p3]);

 

 


 

Download rootInf.mw

 

 to produce a simple animation!

I mean what is wrong with the attached??

  plots:-animate(plot, [[3*t, 4*t^2+1, t=0..tau]], tau=0..Pi);

 

 


 

Download animplt.mw

 

you have supplied a listlist, rather than an Array (or rtable, matrix etc)

Check the type of the argument using whattype or post the complete worksheet here using the big green up-arrow in the Mapleprimes toolbar.

See the "tpy" examples in the attached

  restart;
  A:=Array([[0, 4], [1, 3], [2, 2]]);
  whattype(A);
  ArrayTools:-Reverse(A);

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

 

Array

 

Array(%id = 18446744074372661366)

(1)

  B:=[[0, 4], [1, 3], [2, 2]];
  whattype(B);
  ArrayTools:-Reverse(B);

[[0, 4], [1, 3], [2, 2]]

 

list

 

Error, invalid input: ArrayTools:-Reverse expects its 1st argument, A, to be of type rtable, but received [[0, 4], [1, 3], [2, 2]]

 

 


 

Download arrlist.mw

I just created a simple plot in Maple using

plot(x^2, x=-2..2);

then right-click  on the plot followed by Export->SVG to a specifiied filename: then loaded the generated file into GIMP ( yes I know its old-fashioned, but it is my "goto" for reading/rendering all sort of graphics). The plot appears successfully within GIMP (although its "background" is a bit "interesting" )

So when you say that the "generated SVG is "broken" -

  1. what exactly do you mean?
  2. You can't write the SVG file? You get an error message? Some other problem during the "write" process
  3. You can't read the generated SVG file? Using what? Maybe you can post the the precise process by which you created the SVG file, how you tried to read/render it, and the SVG file itself. I can check the last of these with a few graphics programs  to determine whether or not it is "readable"

See the attached

  restart:
  P:= 12: M:= 6: q:= 2: BC:= 2: Q:= q*BC: CN:= (1/2)*BC:
  NB:= CN: AK:= 1: KC:= AK*evalf(cot((1/6)*Pi)): KN:= KC+CN: BK:= NB+KN:
  eq1:= x1 = (P*evalf(cos((1/6)*Pi))-Q*sin((1/6)*Pi))/sin((1/6)*Pi):
  eq2:= x2 = AK*P+BK*x1+KN*Q+M:
  sol:= solve( {eq1, eq2},
               {x1, x2}
             );
  B:= eval
       ( Vector
         ( 2,
           [ (P*evalf(cos((1/6)*Pi))-Q*sin((1/6)*Pi))/sin((1/6)*Pi),
              AK*P+BK*x1+KN*Q+M
           ]
         ),
         sol
       );
  A:= Matrix( 2, 2,
               [ [1, 0],
                 [0, 1]
               ]
            );
  C:= 1/A;
  x:= C.B;

sol := {x1 = 16.78460970, x2 = 91.56921942}

 

Vector(2, {(1) = 16.78460970, (2) = 91.56921942})

 

Matrix(2, 2, {(1, 1) = 1, (1, 2) = 0, (2, 1) = 0, (2, 2) = 1})

 

Matrix(2, 2, {(1, 1) = 1, (1, 2) = 0, (2, 1) = 0, (2, 2) = 1})

 

Vector[column](%id = 18446744074403721814)

(1)

 


 

Download assn.mw

there are some syntax problems in your original code, and at least one logical error. The attached fixes these - although it is still a "complicated" way to perform fsolve(x^-2).

Anyhow, for what it is worth - check out the attached

restart

E := 1.0*10^(-5); S := 1.0*10^(-5); f := proc (x) options operator, arrow; x^2-2 end proc; a := 1; b := 2

while `or`(b-a >= S, `and`(abs(f(a)) >= E, abs(f(b)) >= E)) do if f(x[a])-f(x[b]) = 0 then printf("Method  fail\n"); break end if; c := b-f(b)*(b-a)/(f(b)-f(a)); if abs(f(c)) < E then break elif f(a)*f(c) < 0 then b := c else a := c end if end do

4/3

 

7/5

 

24/17

 

41/29

 

140/99

 

239/169

 

816/577

(1)

evalf(c); evalf(abs(f(c)))

1.414211438

 

0.6007286839e-5

(2)

 


 

Download rtFind.mw

is given in the attached.

  restart:
  with(LinearAlgebra):
#
# OP should change fpath to whatever is appropriate
# for his/her machine
#
  fpath:="C:/Users/TomLeslie/Desktop/":
  B:=Matrix(2,2, [[6+7*I, 8+5*I],[I,5]]);

Matrix(2, 2, {(1, 1) = 6+7*I, (1, 2) = 8+5*I, (2, 1) = I, (2, 2) = 5})

(1)

  B.B;

Matrix(2, 2, {(1, 1) = -18+92*I, (1, 2) = 53+111*I, (2, 1) = -7+11*I, (2, 2) = 20+8*I})

(2)

  ExportMatrix( cat(fpath, "test.txt"), B);

16

(3)

  A:=parse~(ImportMatrix(cat(fpath, "test.txt"), datatype=string));

Matrix(2, 2, {(1, 1) = 6+7*I, (1, 2) = 8+5*I, (2, 1) = I, (2, 2) = 5})

(4)

A.A

Matrix(2, 2, {(1, 1) = -18+92*I, (1, 2) = 53+111*I, (2, 1) = -7+11*I, (2, 2) = 20+8*I})

(5)

 


 

Download impMat.mw

 

" Maple formerly accepted " - which version? when?

Because in the command

rule1 := forall(string(y), TD(y) = D(y)):

the function string() will do absolutley nothing other than return unevaluated (unless you have define a function/procedure called 'string' which you are not sharing with us).

Now you might(?) be referring to the Maple function String() (note the capitalisation) - but I can't reaaly see any way the output of this command would work with  a 'forall()' construct either:. The command 'String()' will pretty much convert anything it is given into a single string which sort of defeats the purpose of the forall() command - which expects its first argument to be a 'name' or list of names, not a single string.

And don't even get me started on the second argument (aka predicate) provided to the forall() command: again you  might want to consider providing whatever the function/procedure TD() actually is, as well as the contents of the name 'y'. The D(y) part of this predicate is possibly(?) OK provided that it is an expression containing a single unknown

 

The read() command will 'read' either

  1. Maple internal format files (assuming the file extension is '.m') or
  2. Maple language format (assuming the file extension is '.mpl' - which is more-or-less a plain text fomet), or
  3. If the file extension is anything else, will try to make a "good guess" on what you want

The simplest way to solve your problem is if you upload the file to be read using the big green up-arrow in the Mapleprimes toolbar.

Then someone here will fihgure out how best to read it.

Maple now has two "modes" (Worksheet and Document) and two "input methods" (1D input and 2D input) - so overall you have four choices of "user interface".

Two of these are commonly(?) used - namely

Document Mode +2D-Input
Worksheet Mode+1D-input

Each of these two possibilities have pluses and minuses, (and you can start a small war on this site by claiming that one is "better" than the other)

Maple functionality is essentially unaffected by which "mode" and which "input format" you select. The only things which change are the appearance of your worksheets,and some details about how you enter Maple commands.

If you used Maple "years ago" then you were probably(?) using Worksheet Mode +1D-input. Nothing to stop you setting this up as your current default. (This is how I use generally use Maple). You can set this using menu entries

Tools-->Options->Display->Input Display: - make sure this is set to "Maple Notation" rather than "2D Math Notation"

Tools->Options->Interface->Default interface for new worksheets: - make sure this is set to "Worksheet" rather than "Document"

Then use "Apply globally" on the bottom of the Tools->Options pop-up

 

For reasons which escape me, the pdsolve() command syntax for solving pdes analytically and numerically is slightly different. (I personally keep being caught out by this, and it is really annoying!).

The syntax for analytic solutions is that the pdes+bcs/ics are given as a single set/list as in

pdsolve( [PDEs, BCs/ICs], ...some options)

whereas the syntax for solving pdes numerically is that the pdes ans ics are given as two separate sets/lists as in

pdsolve( [PDEs], [BCs/ICs], numeric ...some options)

Note that the syntax for ODEs is "consistent", because for analytic problems, it is

dsolve( [ODEs, BCs/ICs], ...some options)

and for numeric solutions, it is

dsolve( [ODEs, BCs/ICs], numeric ...some options)

So the pdsove/numeric case is a bit of an "oddity".

However, even if you get the syntax correct, the Maple limitation described by rlopez kicks in - but at least you will get the somewhat "more informative" error message

Error, (in pdsolve/numeric) unable to handle elliptic PDEs

 

See the attached

restart;
with(GraphTheory):
graphsof4 := NonIsomorphicGraphs(4, output = graphs, outputform = graph):
DrawGraph(graphsof4[1]);
ChromaticNumber(UnderlyingGraph(graphsof4[1]));

 

1

(1)

restart;
with(GraphTheory):
g1:=Graph(4):
DrawGraph(g1);
ChromaticNumber(g1);

 

1

(2)

 


 

Download grph1.mw

A quick check for 'mm' files shows that there are at least three possible types of files which commonly use this extension - which one are you referring to?

As far as I know, none of these can be opened using Maple

Filetypes wihch are supported by Maple can be seen by typing ?formats at the command prompt

 

First 75 76 77 78 79 80 81 Last Page 77 of 207