Carl Love

Carl Love

28025 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

@acer Thanks for spotting that. I meant

T:= unapply(x - f(x)/D(f)(x), x)

@emendes I don't believe that, unless someone whose knowledge I trust can explain on here (MaplePrimes) exactly why it's not threadsafe. Otherwise, it just seems to me like someone parroting a stock answer to you. Here's the complete code of index:

index:= E-> E[args[2..]]:

So, replace that with your own version:

Index:= E-> E[args[2..]]:

That doesn't use any commands that are not listed at ?threadsafe.

Please try my idea with Grid:-Wait().

 

@emendes 

There are two Questions here:

  • You have a computation A that is not threadsafe that is being done with Grid. It is running out of memory. It may be possible to address this Question with some simple tweaks such as numcpus or tasksize.
  • You have another computation, B, that is threadsafe, is being done with Threads, and is running out of memory. However, that computation would be running out of memory even if it were being run sequentially. So this Question has nothing to do with parallel processing. This Question cannot be addressed without fine hand-tuning of the code, which'll likely involve rolling off chunks of the data to .m files.

The fact that these two computations are being done as part of one overall program is irrelevant.

@emendes You already know that it is not threadsafe. If a computation is not threadsafe or is not being done on a single computer, then Threads can't be used.

@mmcdara The OP edited the Question while I was writing my Answer. After reading the revised Question, I realized that my Answer no longer applied, so I deleted it.

Assuming that an operation is threadsafe and being done on a single computer, I can't think of any good reason to use Grid rather than Threads.

That's a boundary value problem (BVP). Runge-Kutta methods cannot be directly applied. Why do you want to solve it with a particular method?

There's a difference between rkf45 (Runge-Kutta-Fehlberg 4th-5th-order method) and rk4 (Runge-Kutta 4th-order method).

I wrote an application for this (simulated flight of a flock of starlings) and posted it here several years ago. Hopefully someone else can find it. I'm not very good at using the search tools here. If it helps someone search, I used the Explore command. It was in an Answer.

@janhardo You wrote:

  • Interesting, because maybe you has used a instant formulae for the chordal segment, but that is not the case

Some formulae I memorize, some I look up in reference materials, and some I re-derive every time I need them. The chordal segment formula is one the I re-derive.

  • Highlight is the formulae, but what is so special on this formulae ?

The final area is expressed as C*R^2 where is a dimensionless constant (akin to Pi) that depends only on the ratio L/R rather than depending on them individually.

By the way, formulae is the plural for formula. The plural formulas is also acceptable.

 

@janhardo If we're talking about a ratio of sides of a triangle, then sin(theta) = A/B is the same as theta = arcsin(A/B). Since the goal was to get the angle, I used the latter. The final result for the area must include arc-functions---there's no mathematical way around that---but there's no need for it to include non-arc functions such as sin.

Regarding radians vs. degrees: Neither the problem's input (lengths and R) nor its output (an area) involve angles. So the appearance of constants related to angle measure in the final formula would be disconcerting. Consider the sector area formula: A__sector = theta/2*r^2. If theta were in degrees, that would need to be theta/360*Pi*r^2, which is more complicated. Using radians, we avoid having the formulas cluttered up with Pi and arbitrary numbers like 360. Also, Maple's arcsin will return radians.

@mmcdara I find unevaluation quotes very confusing, and I'm not sure of my explanation. I have a general idea of when they'll be needed, but I'm usually not sure whether it'll require one set or two. I once had a situation that required three sets. I just try them until something works. 

@emendes 

That the command index is threadsafe---although it's not listed at ?threadsafe---can be easily verified by reading its super-short code. There seem to be many such commands that are actually threadsafe although they're not listed. (I hope that I'm not missing some detail in ascertaining thread safety.)

I wonder if some extra time is needed for the Grid processes to "wrap things up": garbage collection and final shutdown. I'm just guessing here, but try this:

Grid:-Seq(your code);
t1:= time[real]());
Grid:-Wait();
t2:= time[real]());
print("Wait time:", t2-t1);
#My code from above:
T1:= table(sparse, L1=~[$1..nops(L1)]):
L1:= 'L1': #Optional; use if memory needs to be conserved.
Threads:-Map[2](index, T1, L2);

Then tell me whether the Threads:-Map worked and what value was printed for "Wait time". That's the time that it took Grid to wrap up after the return from Grid:-Seq.

@Carl Love As Acer's Answer shows, my Answer is wrong. I was thinking of the inscribed ellipse of maximal area. I'm demoting the Answer to a Reply.

@janhardo Here is a very basic derivation. I've only used 4 very basic geometry formulas, all pertaining to right triangles and circles:

  • sine of acute angle = (opposite side) / hypothenuse
  • area of circle = Pi * radius^2
  • Pythagorean formula: opposite^2 + adjacent^2 = hypothenuse^2
  • area of right triangle = opposite*adjacent/2


The area of the chordal segment for chord length L is twice the shaded area shown. Clearly it's equal to the area of the radial sector outlined in red minus the area of the right triangle below the shaded region. By using the triangle's top side (L/2) and hypothenuse (R), the central angle of the sector is
theta:= arcsin((L/2)/R);

Thus the area of the sector is 
A__sector:= theta/(2*Pi)*Pi*R^2;

The area of the triangle is
A__triangle:= (L/2)*(sqrt(4*R^2-L^2)/2)/2;

So the area of a chordal segment is
AreaChord:= unapply(2*(A__sector - A__triangle), (L,R));

The rest is pretty much the same as the previous worksheet. Once again, MaplePrimes wouldn't display my worksheet, so please download it. The highlight is this highly symmetric formula for the desired overlap area:

r:= L/R: sq:= sqrt(1 - (r/2)^2):
A:= R^2*(r^2*arcsin(sq) + arcsin(sq*r) - sq*r);

Download Circles.mw

If the ellipse is inscribed in the rectangle, then its axes are necessarily determined by the midpoints of the rectangle's sides. In other words, the four points of tangency will be the midpoints of the sides. This should be enough for you to produce the plot. If you're still stuck, let me know.

First 181 182 183 184 185 186 187 Last Page 183 of 708