Carl Love

Carl Love

28070 Reputation

25 Badges

13 years, 40 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are replies submitted by Carl Love

@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 .

 

 

@Aysan

According to ?dsolve,rosenbrock, the default values for both relative and absolute tolerance (options relerr and abserr, respectively) are both 10^(-6). Where did you see 10^(-3)?

@Aysan 

Consider the following piecewise expression of three pieces:

f:= piecewise(
     t < 1,  #operand 1
     t,      #operand 2
     t < 2,  #operand 3
     t^2,    #operand 4
     t >= 2, #operand 5
     t^3     #operand 6
);

So, the Boolean conditions tend to be the odd-numbered operands, and the algebraic "pieces" tend to be the even-numbered operands.

@Kitonum I like this better than my solution with diff.

Since dsolve returns multiple solutions, the odetest call needs to be

odetest({sol}, ode);

Can an expression that contains a RootOf where the RootOf variable appears as a limit of integration of an undoable integral really be considered to be a "solution" of the ODE?

@Aysan 

Since eq1 is independent of x, the answer is just a constant multiple of the original answer, the constant being int(sin(Pi*x), x= 0..1), which is 2/Pi.

@smith_alpha 

As shown by Kitonum, my procedure does not work when the base variable appears in the exponent.

@Aysan 

f:= t-> piecewise(t < 10, 1-t, t):
ode:= diff(y(t),t$2) - y(t)^2 = f(t):
Sol:= dsolve({ode, y(0)=0, D(y)(0)=0}, numeric):
plots:-odeplot(Sol, [t, y(t)], t= 0..12);

@Kitonum 

Your code fails for many special cases, such as when the variable appears to power 1, when the variable appears multiple times in the expression, and when the variable does not appear in the expression.

@liushunyi To obtain just the sequence do

seq(coeff(p, x, k), k= degree(p,x)..0, -1);

or

PolynomialTools:-CoefficientList(p, x, termorder= reverse)[];

In general, if L is a list or set, then L[] is the corresponding sequence. The same thing can be achieved with op(L), but the operation is so common that that just clutters up the code.

@Mac Dude Indeed, I'd recommend that the OP use the interface command that you gave because "I don't want to click on 'properties' each time I execute my worksheet."

Please give us the commands that you are using to do the export.

@casperyc 

S:= map(x-> sprintf("%a", lhs(x)), v1):
S:= map(StringTools:-PadRight, S, max(length~(S))):
R:= rhs~(v1):
seq(
     printf("%s = %s %3.3f\n", S[k], `if`(R[k]<0, "-", "  "), abs(R[k])),
     k= 1..numelems(v1)
);

eta[p2]   =    0.260
eta[p3]   =    0.113
eta[p4]   = - 0.013
eta[p5]   =    0.215
eta[p6]   = - 0.189
eta[phi2] =    0.020
eta[phi3] =    0.063
eta[phi4] = - 0.014
eta[phi5] = - 0.414
eta[phi6] =    0.067
mu[p]     =    0.466
mu[phi]   = - 0.169
tau[p3]   =    0.000
tau[p4]   =    0.000
w[1]      =    0.023
w[2]      = - 0.447
w[3]      = - 0.110
w[4]      =    0.035
w[5]      =    0.445

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