Joe Riel

9530 Reputation

23 Badges

20 years, 29 days

MaplePrimes Activity


These are answers submitted by Joe Riel

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)};

You might be able to do

map(op@indets, vec[1], numeric);

however, that fails with `@`(1, {1}) because indets returns a set, so duplicates are removed.

A good solution may require more knowledge of structure of the input.   If all elements have the form `@`(integer, {float1,float2,...}) then you could simply do
 

[seq('op(1,e),op([2,..],e)', e in vec[1])];

A simpler method is to select the lines of code and then click the Format drop-down box and pick the Formatted tag.

Use the print function.  That puts the plot into the print stream, which actually does the plotting. Thus,

makeplot:= proc(p)
    plotsetup('ps'
              , 'plotoutput'=`p.eps`
              , 'plotoptions'=`portrait,noborder`
             );
    try
        print(plots:-display(p));
    finally
        plotsetup('default');
    end try;
end proc:

The try/finally statement ensures that plotsetup('default') is called even if an error occurs when plotting.

If the Matrices are square than you should consider using the inplace option (see LinearAlgebra,MatrixMultiply).

For nonsquare, numeric matrices the order in which they are multiplied [associated] can substantially affect the speed of the operation.  Precomputing the optimal grouping is then worthwhile.  I don't know whether Maple provides a procedure for doing so.

Change nprintf to sprintf.  That will return a string rather than a name.

The error you made is not inserting a catenation operator on both sides of the i.
Note that cat is preferred over ||.  You could also use nprintf:

for i to 20 do
    part := nprintf("cord@fan%d@part.part", i);
    GetDimensionValue(doc, part);
end do:

 

Are you using the old [deprecated] networks package or the new GraphTheory package? 

Robert's solution is nice.  Alternatively you could substitute values for E and S:

 max(subs([S=-infinity,E=-infinity],MM));

Substituting NULL would also work.

Note that your example reveals a minor Maple bug.

 max(MM);
Error, (in simpl/max) arguments must be of type algebraic

It should return

 max(S,E,2)

Curiously I ran into that a few weeks ago, but didn't get around to submitting an SCR. Will do so.

First 82 83 84 85 86 87 88 Last Page 84 of 114