Carl Love

Carl Love

28100 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

@necron 

G5O and g5 are syntactically different. The former is a procedure of two arguments, t and x; the latter is an expression in t and x. Using the expression G5O(t,x) with symbolic t or x will expand it to an expression again (numerically equivalent to g5) and negate the optimization. We need two more layers of procedural nesting (one for t, one for x) to effectively use G5O for numeric integration so that it'll not be called with symbolic arguments. So, use this for E2:

E2:= t-> evalf(Int(x-> G5O(t,x), 0..100, epsilon= 1e-4)):

You can keep your plot command the same. The 50-point plot will take about two minutes, (which is actually about a factor-of-70 improvement over your original). I don't know if it makes a difference, but I had Digits (not digits) set to 15 for the above. So, if it doesn't work, set 

Digits:= 15:

and try again.

 

@Markiyan Hirnyk 

That works too. I tend to write code closer to the kernel, and I'd forgotten about the writedata command, which is simply a Maple-coded command which makes several calls to fprintf with its arcane format codes (see showstat(writedata, 26), for example). I also personally loathe making a conversion to the old-style matrices.

But, certainly, it's an easier command to remember, and I'd recommend it to the OP.

(Note also that ExportMatrix is a high-level command which (through a chain of procedures and modules several layers deep) simply makes a call to fprintf using the newer { } format codes described on the help page that I mentioned.)

@Markiyan Hirnyk 

What I have given is a standard command for the plaintext output of matrices. It's used (as fprintf(...)), for example, when you want to send matrix output to a textfile and maintain a columnar format. See ?rtable_printf. The cryptic notation originated in the C language I believe, and it's implemented in Maple's kernel.

Your usage of "intersect" is a bit confusing. The given graph doesn't intersect the coordinate axes at all. Do you mean "What x value on the graph corresponds to y = 1.5?" and "What y value on the graph corresponds to x = 3000?"? 

There are three options:

  1. Do you want to ask those questions with repect to the piecewise-linear curve that is precisely defined by your data? This can be done straightforward.
  2. Do you want to interpolate the data with a smooth curve that passes exactly through the data points? The most common choice for such a curve is a cubic spline. Once you make the choice of degree, the computation is straightforward.
  3. Do you want to fit a parametrized model curve to the points, choosing parameters such that the curve doesn't necessarily go through the points but such that the residuals are minimized by some measure? This is called regression. It's by no means straightforward, but it's the most common choice.

@Boby 

I am not familiar with your solution technique, and I am skeptical about your purpose in using it. Why don't you just use standard numerical techniques for IVPs? They work fine on this problem.

@Axel Vogt You wrote:

 I understand that the user is responsible to provide an according sequence of points ... it 'only' connects the points given in the list according to its ordering - yes?

Yes, exactly. It's GIGO (Garbage In --> Garbage Out).

@JonMcLoone You wrote:

Perhaps my presence here is unwelcome, so I shall not comment on the subjective arguments that it contains.

 Your presence here is most welcome, and I look forward to your future comments.

Such a problem makes no sense to me without limits of integration. We need them to eliminate t from the equations.

@Axel Vogt No, it's not at all clear, unless you mean that it's clear visually for this particular example. Such an analysis goes far beyond the scope of what was asked, and isn't necessary for most of the computational applications for which one would use the parametrization of a piecewise-linear curve.

@Christopher2222 You wrote:

the only way I think Mathematica could fix that image the way they show is if Mathematica itself blurred the image in the first place. 

At first I was inclined to agree totally with you; however, having now read the entire help page (including all 21 examples), I believe that there's something very powerful about this Mathematica command, and that Maple should strive for something similar. While the specific example of the Moon-landing photo may be the result of what you suggest, the license plate example seems genuine. 

Please post questions in the Questions section rather than the Posts section. (I've already moved this one.)

What is the variable with respect to which the integration is to be performed? What do you mean by "solve this for t"? Do you mean that t is the variable of integration? Can you make some assumptions about the parameters? real? positive?

9009134: Please don't post a new thread (a new Question) that is simply a reformulation of your own existing Question. It will be deleted. You can edit your original Question, or post a Reply to it. Either of these will put the Question back at the top of the Active Conversations stack, which has the essentially the same effect as posting a new Question without making people angry with you.

Markiyan: I do appreciate your spotting of duplicates. You have quite a talent for it. Instead of posting a Reply to the duplicate, please delete the duplicate and post a Reply to the original. Posting a Reply to the duplicate makes it more difficult for someone else to delete it. Failing to delete the duplicate increases the chance that someone will inadvertently post a legitimate Answer to it, at which point I'd feel that it's unethical to delete it (there being no way that I know of to move the legitimate Answer over to the original Question).

@Rouben Rostamian  

Please post your short and well-organized worksheets inline.

I generalized your procedure to an arbitrary number of dimensions. Often making such a generalization also shows one how to simplify.


restart:

Input: A list of n-dimensional points, where each point is a list of n real numbers. The list of points is regarded as defining a piecewise-linear curve.

 

Output: A sequence of always two items (regardless of dimension). The second is the total arclength T of the curve. The first is a procedure F(t) which returns a list of n real numbers that represents a point on the curve if t is between 0 and T.

 

#Parametrize a Piecewise-Linear Curve by Arclength in any number of Dimensions.
PPLCAnD:= proc(P::listlist(realcons))
local
     t, k, n:= nops(P),
     dist:= (u,v)-> sqrt(`+`(((u-~v)^~2)[])),
     L:= ListTools:-PartialSums([0, seq(dist(P[k+1],P[k]), k= 1..n-1)])
;
     unapply(
          piecewise(
               seq('t <= L[k+1], P[k]+~(t-L[k])/(L[k+1]-L[k])*~(P[k+1]-P[k])', k= 1..n-1)
          ), t
     ), L[-1]
end proc:

     

LL:= [[1.1, 2.04], [1.97, 4.04], [2.96, 2.97], [4.5, 6.4], [5.08, 7.21], [1.1, 4.04], [1.1, 2.04]]:

(F,T):= PPLCAnD(LL):

F(T/2);

[4.69962396245103, 6.67878518894023]

plot([F(t)[1], F(t)[2], t= 0..T], color="Green", thickness=4);

LLL:= [[1.1, 2.04, 0], [1.97, 4.04, 1], [2.96, 2.97, 2], [4.5, 6.4, 3], [5.08, 7.21, 4], [1.1, 4.04, 5], [1.1, 2.04, 0]]:

(F,T):= PPLCAnD(LLL):

F(T/2);

[4.65732005921038, 6.87334286123041, 4.10620099014815]

plots:-spacecurve([F(t)[1], F(t)[2], F(t)[3]], t= 0..T);

 


Download Piecewise_Linear_by_Arclength.mw

@Rouben Rostamian  Your Reply just reminded me of another way:

c:= a[i],b[i]:
seq(c, i= 1..3);

However---warning---an indirect reference to seq's (or add's or mul's) index variable through a local variable (as in a procedure) won't work without a forced eval. This applies to both the example that you gave in your Reply and the one that I gave immediately above. Here's an example:

This doesn't work:

proc() local c:= (a[i],b[i]); seq(c, i= 1..3) end();

It needs to be changed to this:

proc() local c:= (a[i],b[i]); seq(eval(c), i= 1..3) end();

This phenomenon is due to an unfortuitous combination of local variable's single-level evaluation (which I've discussed extensively in recent posts) and seq's, add's, and mul's special evaluation rules.

Regarding $: Yes, seq and $ are analogous to add and sum, respectively, in their semantic differences.

The text does say that the command is being used (in this example) to "restore a blurred image," which implies that the blurred image was created from some original higher-quality image.

To make the post be about Maple, ask whether the same can be done with Maple. We have the ImageTools:-Convolution command. 

First 462 463 464 465 466 467 468 Last Page 464 of 709