Joe Riel

9530 Reputation

23 Badges

20 years, 28 days

MaplePrimes Activity


These are answers submitted by Joe Riel

I haven't used Window for several years, so no longer remember.  In Linux there is an X11 resource file for the classic worksheet, one of the settings controls the background color.  The distributed file is located in the maple/X11_defaults directory.

What's the difficulty?  Do you know three different norms for a given vector?  And how to select them?  The Maple help page ?VectorNorm describes the available options.

Alas, there is no way to change the background color of the worksheet.  Strangely, one can change the background color of the help pages.  In the maplerc file, modify the HelpBGColor field (the three numbers are the byte values of the RGB strength).

with(LinearAlgebra):
RowOperation(A, [3,1], 3);

Your first set of nested loops do nothing (other than reassign m and n.  You probably want something like

for n to 3 do
   for m to 3 do
       f := (Q1,Q2) -> m*Q1 + n*Q2;
       A[n,m] := Powell(f);
   end do:
end do:

You can also do this with

A := Matrix(3,3, (i,j) -> Powell((Q1,Q2) -> j*Q1+i*Q2));

 

Here is a modest improvement to the solution I posted. Rather than reinitializing each time, it clears the event.

deq := { diff(y(t),t,t)+sin(t)*diff(y(t),t)+y(t)^2-5*y(t)=0 }:
ic := { D(y)(0)=0,y(0)=1 }:
dsys := deq union ic:
integ := dsolve(dsys
                , 'numeric'
                , 'events'=[NULL
                            , [[y(t)-4=0, diff(y(t),t) > 0], 'halt']
                           ]
               );
Tf := 10:
_Env_in_maplet := true:

data := table():
cnt := 0;
do
    result := map(rhs,integ(Tf));
    if integ('eventstop') <> 0 then
        integ('eventclear');
        cnt := cnt+1;
        data[cnt] := result;
    end if;
    if Tf <= result[1] then break; end if;
end do:

data := rtable(1..cnt, data);

Why is it taking so long?  Regardless, to write to a file you might want to use the FileTools[Text][WriteLine] command.  You do something like the following (I haven't actually run this code, just typed it up):

fd := FileTools:-Text:-Open("data.mpl"):
# Use a try command so that if an error occurs you still close the file and retain some data.
try
  for i to 1000 do
       # create string to save (use sprintf to format data)
       line := sprintf(...);
       FileTools:-Text:-WriteLine(fd, line);
  end do:
finally FileTools:-Text:-Close(fd):
end try;

 

Here is one solution.  I'm not confident that this will work on Maple 12.01, which I don't have immediately at hand. I'm using a development version and the event mechanism has changed a bit, so if this doesn't work, let me know. Because there isn't a way, I believe, to assign to an Array in the integrator event cycle, I force a halt each time the condition is met, save the results, reinitialize, and continue integrating until reaching the end.

deq := { diff(y(t),t,t)+sin(t)*diff(y(t),t)+y(t)^2-5*y(t)=0 }:
ic := { D(y)(0)=0, y(0)=1 }:
dsys := deq union ic:
integ := dsolve(dsys
                , numeric
                , events=[NULL
                          , [[y(t)-4=0, diff(y(t),t) > 0], halt]
                         ]
               );
Tf := 10:
_Env_in_maplet := true: # trick to quiet the warnings

data := table():
cnt := 0;
do
    result := map(rhs,integ(Tf));
    if integ('eventstop') <> 0 then
        # The halt was caused by the event (not by reaching Tf), so 
        # save the returned value in the data table.
        cnt := cnt+1;
        data[cnt] := result;
    end if;
    # The independent variable (time) is always first in result.
    # Exit loop if we've reached the end, otherwise reinitialize, using
    # result.  Without reinitializing, the integrator halts immediately
    # because the halt condition is fulfilled.
    if Tf <= result[1] then break; end if;
    integ('initial' = result);
end do:
# Convert table to rtable.
data := rtable(1..cnt, data);
f := 4/Pi*sum((sin(2*n-1)*x)/(2*n-1),n=1..infinity);
combine(f,ln);
                                        x


 

You might try issuing the Maple command

interface(labeling=false);

I'm not sure how to do that in the Maple toolbox for Matlab.

f := (x,y) -> `if`(x=0 and y=0, 0, x*y/(x^2+y^2));
 

While assign does what you asked, as you progress with Maple you may find that using it is not always the best.  The problem is that by assigning values to the symbols x, y, and z, you can no longer easily access the original equations.   For that reason I generally use eval to to assign an element of a solution to is own symbol.  So, given

sol := {x=1, y=2}:

I would do

xn := eval(x, sol);
                       xn := 1


 

You might prequalify your numbers to speed things up.  A palindrome with an even number of digits is congruent to 0 mod 11.  Testing for that is very fast compared to the fixed cost of converting to a string, so if numbers in the range you are interested have an even number of digits, you can quickly eliminate 91% of them.

Note that list is not a Maple command; list(30) just returns an unevaluated function.  After assigning that to l, the term l[3], for example, causes Maple to generate a tableref (an implicit table reference).  When you then assign a value to that, Maple allocates a hash table.  You can see this by doing

d := dummy(3):
dismantle(d);
FUNCTION(3)
   NAME(5): dummy
   EXPSEQ(2)
      INTPOS(2): 3
d[3] := Pi:
dismantle(eval(d));
TABLE(4)
   EXPSEQ(1)
   NAME(5): false #[protected]
   HASHTAB(257)
      ......
      HASH(7)
         INTPOS(2): 3
         INTPOS(2): 3
         ....
      ..........................................................................................................
      ..........................................................................................................
      .....................................

It is generally not a good idea to assign directly to elements of a list using index notation.  While that is possible, it is slow and also limited; it won't work for a list with more than 100 elements.

You might specify what you expect.   Do you mean triangulate a polygon?  For example, given the convex quadrilateral ABCD would you want to get ABC and CDA?

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