Carl Love

Carl Love

28035 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

@Josolumoh 

I have some ways to help you, but the function B that you propose as your pmf (or ProbabilityFunction) doesn't sum to 1 for any finite b. Rather, it looks like the limit of its sum is 1 as b approaches infinity, as shown in this plot:

B:= (r,d)-> b-> x-> 
   binomial(x+r-1, x)
   / (1+d*x)
   * (b/2/(1 + d*x + b/2))^r
   * ((1+d*x)/(1+d*x+b/2))^x
;
plot(b-> evalf(Sum(B(3,2.5)(b)(x), x= 0..infinity)), 0..40);

Once you correct this pmf, I'll be happy to help you generate samples.

It's difficult to help you because I can only see your output, not the input that you used to generate it.

There are several easy ways in Maple to map an indexing operation over a set or list of indices.

@Christopher2222 An easier way is to just use Statistics:-Fit instead of Statistics:-LinearFit:

Statistics:-Fit(3*x+a, pts1, pts2, x);

Note that x must be the independent variable and a the unknown parameter. Thus x must be the last argument, not a.

@acer Thank you, and thank you for teaching me about Tabulate. I do really like the way that the default prettyprinting for rtables (which is obviously inherited by DataFrames) sets the column widths and row heights. I don't relish the idea of needing to set the weights. Is there a way (perhaps something in Typesetting) to access the widths that would be used for an rtable? or just the width of an ordinary algebraic expression? Then those could be used (perhaps with some scaling) to set the weights.

It isn't only the lambda that isn't typeset.

@Carl Love Second hint (for "by hand" computation, assisted by Maple): As upsilon --> infinity (either positive or negative), the simple rational function inside the square root, (upsilon - 4)/upsilon, approaches 1. So, just replace it thus:

f:= ...your original expression...:
assume(t > 0);
f1:= simplify(subs(epsilon= 1/upsilon, f));
f2:= simplify(subs((upsilon-4)/upsilon= 1, f1);

@bsoudmand I get manifestly real expressions (with Re and Im resolved). My guess is that you have an earlier version of Maple such that evalc won't automatically "map over" my fancily labelled expressions. Try this:

simplify(evalc~([Re,Im](Ec))) assuming positive;

Kitonum's Answer shows that evalc is not necessary in this case (a rational function is an easy case). However, in general I think it will be necessary.

@acer I was wrong. I was misled by some spurious timings that I can't reproduce.

Instead of cot~(...), you could use map[evalhf, inplace](cot, ...). It would be much faster, but your point is still valid.

@emendes I just posted, as a separate Answer, a cycle detector that works over the exact algebraic numbers.

@emendes Okay, here's an efficient equivalent to Mathematica's NestList:

NestList:= proc(f, x, n::nonnegint)
local R:= rtable(0..n, [x]), k;
   for k to n do R[k]:= f(R[k-1]) od:
   [seq(R)]
end proc:

I also just posted (two Replies above) some alternatives that don't use for but require Maple 2018+ for the embedded assignment.

@emendes It is difficult (although not impossible) to effectively use seq for a recursive evaluation, i.e., for creatiing a sequence whose terms are computed from previous terms. Why don't you want to use for?

Here's a very easy (and very inefficient) code that does it using seq:

f:= y-> 4*y*(1-y):
x0:= (5-sqrt(5))/8:
seq((f@@p)(x0), p= 1..9);

In Maple 2018, that can be improved with embedded assignment:

f:= y-> 4*y*(1-y):
x:= (5-sqrt(5))/8:
seq((x:= f(x)), p= 1..9);

Or, noting that p is now irrelevant, seq can be replaced with $:

f:= y-> 4*y*(1-y):
x:= (5-sqrt(5))/8:
'(x:= f(x))' $ 9;

Syntax note: An embedded assignment always requires its own parentheses, even if they seem redundant or there's no possibility of ambiguity.

@vv That works in this case, which is a simple polynomial. If you step it up even one notch, to a rational function, and use a high value of p, I suspect that you'd quickly either consume all your memory or cause a kernel failure.

Or, f could be purely numeric, for example, based on a dsolve(..., numeric) result.

Regarding unary :-: I thought that Acer wasn't as clear as possible about this point, so I'm rephrasing it. When any symbol is prefixed with :-  with no left operand for the :-, it refers to the global instance of that symbol, not to any module or package member or procedure local or top-level local that may otherwise have the same name.

Regarding with: I strongly recommend losing the habit of using it. For me, there are only two acceptable cases for using it:

  1. When using Maple as a "desktop calculator" for work that will not be saved.
  2. When using an older package (such as Tolerances) that rebinds operator symbols such as `+`. Newer packages can (and should) provide the same functionality by using objects and overloading the operators.

A desire to use "the short-form name" is not an acceptable reason to me. It sickens me whenever I see that mentioned in a help page. Using short-form names leads to hard-to-read code because when using multiple packages, the reader can't easily tell which package (if any) the name comes from.

@Preben Alsholm It's probably worth noting that the average of the two is the well-known Trapezoid Rule, in this case applied to potentially unevenly spaced ordinates.

@Carl Love Acer has noted a bug with *~ when used with Tolerances: It uses the global * rather than the overloaded one. While my solutions above are still correct for this example, in light of this bug, the following will be safer:

subsindets(Z, {:-`*`, :-`+`}, e-> `if`(e:::-`*`, `*`, `+`)(e));

First 284 285 286 287 288 289 290 Last Page 286 of 708