Carl Love

Carl Love

28055 Reputation

25 Badges

12 years, 359 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are replies submitted by Carl Love

@msurov 

I did not realize that you wanted to extract the constant term. It is also not clear whether it should come at the beginning or end of the list. The constant term can be extracted with tcoeff.

seq(coeff(eq,v), v= vars), tcoeff(eq);

GenerateMatrix also works well.

@taro 

algsubs generally cannot be used to substitute things that are algebraically equivalent. Consider the following two examples:

algsubs(x^2-1= (x+1)*(x-1), (x-1)*(x^2-1));

algsubs(x^2-1= (y+1)*(y-1), (x-1)*(x^2-1));

 

 

By the way, the code op(ex)[1] is not robust; it fails when ex has only one operand. You should use op(1, ex) instead.

 

@toandhsp In my code, PLk is the list of all pairs of tangents that aren't perpendicular. There is no pair that is repeated.

Please attach a worksheet containing the above code. You can attach a worksheet to a post by using the green up-arrow, whch is the last item on the second row of the toolbar in the MaplePrimes editor.

Please post a worksheet showing the error message. You can attach a worksheet to a post by using the green up-arrow, which is the last item on the second row of the toolbar in the MaplePrimes editor.

@cloz54 Here's how it works:

indets takes an expression and a type and returns a set of all subexpressions of the given type.

specfunc(anything, RootOf) is the type. It stands for "specific function". The anything means to look for functions named RootOf with arguments of type anything.

The [1] is to select the first RootOf in the set returned by indets, in case there is more than one.

op stands for "operands". When passed a function, op returns its argument(s).

 

@Markiyan Hirnyk 

Why not use DirectSearch:-DataFit?

@velimir74 

It's not boring at all. It's a very interesting question.

@emrantohidi 

I second what Preben just said. But from your wording it seems that you have written some Maple code already---code that perhaps needs to be made faster. So, you should definitely post that code when you ask a separate Question.

@Carl Love 

Also, I recommend using mul instead of product. The difference between mul and product is the same as that between add and sum: mul is for products of a definite and finite number of factors not using any symbolic simplification. If you use mul, then you can get rid of the unevaluation quotes on 'Q[j,i]' because mul has the same "special evaluation rules" as add and seq.

f:= unapply(
      [seq(mul(t[j]^Q[j,i], j= 1..RowDimension(Q)), i= 1..ColumnDimension(Q))]
    , seq(t[i], i= 1..RowDimension(Q))
);
 

@Kitonum 

The special names args, nargs, etc. work just as well in arrow procedures as in proc procedures.

f:= ()-> add(x^2, x= args):
f(1,2,3); 

    
14

@k20057 5 

Before understanding the code you need to understand the combinatorial concepts of (proper) compositions and weak compositions. If you don't, see this Wikipedia page.

The command combinat:-composition(n+k, k) returns a set of all proper compositions of n+k of length k, each composition being represented by a list. Each composition of n+k needs to be converted to a weak composition of n by subtracting 1 from each element (because what you want is a weak composition of 8). The expression C-~1 subtracts 1 from every element of C. (The ~ makes a binary operator apply to every element of its operands.) The command seq(C-~1, C= L) iterates that over every element of L. The square brackets around the seq command turn the result into a list, which is then called Compositions. So, this is a list of all weak compositions of n of length k.

The expression nops(Compositions) returns the number of elements of Compositions. Apparently you already know what rand(a..b) does because you used it in your original Question.

The line ()-> Compositions[Rand()] is the return value of the procedure. This return value is itself a procedure created with the -> operator. The () to the left of -> indicates that this procedure takes no arguments (or has no parameters). The Rand() generates a random integer in the appropriate range. The expression L[n] selects the nth member of list L.

@k20057 5 

Here it is.

RandomCompositions:= proc(n::posint, k::posint)

(* Generates a procedure which selects uniformly at random a k-tuple of nonnegative
integers that sums to n. Note that this has a memory requirement of
k*binomial(n+k-1, k-1).                                                                                                            *)

local
     C,
     Compositions:= [seq(C-~1, C= combinat:-composition(n+k, k))],
     Rand:= rand(1..nops(Compositions))
;
     ()-> Compositions[Rand()]
end proc:

R:= RandomCompositions(8,6):
R();

R();

 

 

 

@liushunyi You wrote:

In my opinion, data is just the file name of input and ofile is the file name of output. Could we remove the declarations data := "read-data-compute-charpoly.dat" and ofile := "read-data-compute-charpoly.poly"?

Joe intended that you would change the assignments to data and ofile to be the names of your actual files.

The error is caused by extra white space characters at the end of your input file. It can be corrected like this. The line

if line=0 or line="" or line[1]="#" then

should be changed to

if line = 0 or line::string and StringTools:-TrimRight(line) = "" or line[1] = "#" then

I did this, and the program ran without error, producing the correct output file.

 

@Aysan 

Referring to the same system of five equations under discussion in this Answer, you can set the relerr and abserr options like this:

Sol1:= dsolve({Sys1, ICs1},
     numeric, maxfun= 0,
     method= rosenbrock,
     abserr= 1e-10, relerr= 1e-6,
     range= 0..10
):

You should also set, globally,

Digits:=  15:

increasing it from its default value of 10. That's the "sweet spot" for simultaneous accuracy and speed.

Please read the help page ?dsolve,rosenbrock .

 

 

First 534 535 536 537 538 539 540 Last Page 536 of 709