Joe Riel

9660 Reputation

23 Badges

20 years, 11 days

MaplePrimes Activity


These are answers submitted by Joe Riel

If you don't need all the points at once, but instead are content to access them one at a time, you could use the combinat[cartprod] iterator constructor.  For example,

dims := [[1.2,3.2], [1.2, 2]]:
ints := map( dim -> [seq(ceil(dim[1])..dim[2])], dims):
T := combinat:-cartprod(ints):

while not T[finished] do lprint(T[nextvalue]()) end do;
[2, 2]
[3, 2]

See www.mapleprimes.com/book/cartesian-products-of-lists

Try the LargeExpressions package.  For example,

with(LargeExpressions):
subsindets(ex
           , `*`
           , Veil[K]
          );
     -2 K[1046] + 2 K[1048] + 2 K[1050] + 4 K[1052] + 2 K[1054]
     + 2 K[1055] + 2 K[1053] + 4 K[1051] + 2 K[1049] + 2 K[1047]
     - 2 K[302] + 2 K[289] - 2 K[44] + 4 K[471] + 2 K[183] + 2 K[96]
     - 4 K[555] - 2 K[229] - 2 K[106] - 4 K[539] + 2 K[36] + 4 K[497]
Unveil[K](K[1046]);
     (-2 K[700] + 2 K[722] - K[148] - K[532] - K[396] + K[203] + 2 K[684]
                                                      10
     - 2 K[747] + K[385] - K[221] + K[510] + K[142]) t

An example would clarify. Are these algebraic equations in which an initial guess value is used in an iterative process (or maybe a call to fsolve)?  Or are they differential equations with initial values?

Is the goal to solve the equation (or something more complicated) or to learn/demonstrate simple programming in Maple?  There are better ways than the brute force method you suggest.  You could, for example, use isolve here:

isolve(355*k = 200*n);  # modified to slightly increase interest
                           {k = 40 _Z1, n = 71 _Z1}

The symbol _Z1 stands for any integer, so the desired solution is n = 71.
 

Another way, if a bit more complicated, is to save it to a custom Maple archive so that it is accessible without having to add a read statement.  For example

myproc := proc(x) return x^2; end proc:
LibraryTools:-Save(myproc, "/home/joe/maple/lib/mylib.mla");
restart;
myproc(a);
                                a^2;

For that to work, the path "/home/joe/maple/lib" should be added to libname sequence.  That can be done by adding a line to the Maple initialization file, say

libname := "/home/joe/maple/lib", libname:

Look in ?worksheet,reference,initialization for description of the use and location of the user initialization file---you have to create it, it is not distributed with Maple.

It isn't clear what you are asking----vectors don't generally "take the values zero and one".  Zero maybe, but not one.  Do you mean components of vectors?  An example would clarify.

Here's a mildly interesting way; it requires Maple13,

A := Matrix([[1,3,a],[1,4,d],[1,1,b],[3,3,c],[3,4,a]]);

m := max(A[..,1]);
n := max(A[..,2]);

T := table(map(curry(op,[1,..])=rhs
               , convert(A[..,1..2], listlist) =~ convert(A[..,3],list)
              ));

B := Matrix(m,n,T);

If you don't have Maple13 you could assign T with

T := table(map(curry(op,[1,..])=rhs
               , Equate(convert(A[..,1..2], listlist), convert(A[..,3],list))
              ));

A simpler approach is to use a loop:

B := Matrix(m,n);
for i to LinearAlgebra:-RowDimension(A) do
    B[A[i,1],A[i,2]] := A[i,3];
end do:

If you could upload what you have done, it would be easier to comment. What sort of animation were you hoping to generate?

Given the odes, here is a simple example of an animation:

ode := { diff(phi(t),t,t) = -phi(t)
         , D(phi)(0) = 0
         , phi(0) = Pi/4
       }:

integ := dsolve(ode, numeric):

f := tt -> plots:-pointplot(eval([[sin,-cos](phi(t))], integ(tt))):

plots:-animate(f
               , [t]
               , t=0..10
               , frames=100
               , scaling=constrained
               , view=[-1..1,-1..1]
               , symbol=circle
              );

One way to catenate the integers is the following

catint := proc() parse(cat("",args)) end proc:

For the first example you could do

check := proc(A,B) evalb(catint(B,A) = A^B); end proc:
check(5,2);
                           true

Another option is to use Bits:-Split.  You'll need to reverse the list, it puts the lowest order bit first.  Thus

bin := ListTools:-Reverse(Bits:-Split(7, 'bits'=6));
                                         bin := [0,0,0,1,1,1]

 

What do you really want to do with the output?  That is, you can write the output to a file, which seems more useful than cutting/pasting.

fprintf("/tmp/bits.dat", "%a\n", bin): # write to file /tmp/bits.dat
fclose("/tmp/bits.dat");               # close the file

The numeric integrator being used (rkf45_dae) needs to differentiate the user-supplied functions, so you have to tell it how to do so. That means assigning appropriate procedures to the global variables `diff/Fx` and `diff/Fy`.  You can do that via

 `diff/Fx` := D(Fx);
 `diff/Fy` := D(Fy);

You could also try using a numeric integrator (selected via the 'method' option) that does not require differentiating the function. See ?dsolve/numeric for details. A bigger problem, however, is that there is no definition for the `αf` and `αr` variables.

Modify Fx so that it returns unevaluated when called with non-numeric arguments.  This can be done by inserting the statement

    if not [args]::list(numeric) then return 'Fx'(args); end if;
 as the first statement of Fx.   You also need to tell dsolve that Fx is a known function:

   integ := dsolve({ic, sys}, numeric, 'known'=Fx):

Alas, your initial conditions are not well-defined:


   Fx(0,0); 
                      Float(undefined)
The following initial conditions work (with above changes), but may not be what you want:
epsilon := 1e-6:
ic := x(0) = epsilon, y(0) = epsilon:
integ := dsolve({ic, sys}, numeric, 'known'=Fx):
plots:-odeplot(integ, [t,x(t)], 0..0.01);

You might want to use the RandomTools package to generate the lists of numbers:

n := 10: # I'm guessing n is number of element in list
L := RandomTools:-Generate(list(float(range=0..1,digits=10,method=uniform), n));
L := sort(L);

Rather than assigning to variables, it is easier to operate on each:

[seq(max(abs(i/n - L[i]), abs((i-1)/n-L[i])), i = 1..n)];

I'll let you figure out the loop...

Is q supposed to be unassigned? Also, there is a syntax error in the assignment to epsilon; note the term (mu/kappa)2.  Should that be (mu/kappa)^2?

A few comments.  You should consider using Matrix (rather than matrix, which is an old Maple data structure) and the LinearAlgebra:-Determinate.  Also, use add rather than sum to compute the summations; sum is intended for symbolic summation.

Rather than assigning 0 and 1 to ISM, use the boolean values false and true.

I don't see where the matrix C is assigned values.  Is that intentional?  Hmm. Yes, I think so.  In that case, either do not assign anything to C, or do C := Matrix(n,n, 'symbol = c').  Doing C := Matrix(n,n) won't work because it will be a square matrix of zeros.

A more efficient way to generate the equations is with nested seqs:

    eqns := {seq(seq(seq(`=`(add(A[i,j,k]*C[l,k],k=1..n),
                             add(C[p,i]*(add(C[r,j]*B[p,r,l],r=1..n))
                                 , p=1..n)
                            )
                         , l = 1..n)
                     , j = 1..n)
                 , i = 1..n)};
First 82 83 84 85 86 87 88 Last Page 84 of 114