Carl Love

Carl Love

28055 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

I wasn't aware of this phenomenon; it is indeed shocking. However, I've argued for years that the only robust method is to always use the package prefix inside procedures. The prefix may be abbreviated, but not safely eliminated:

    uses LA= LinearAlgebra;
    LA:-MatrixInverse(M)

Also, using LA:-MatrixInverse is robust, but using LinearAlgebra[MatrixInverse] (as is recommended on nearly every help page of a package command as the "long form") is not robust.

@abdgafartunde Sorry, I was in a hurry when I wrote "I can't conceive of using two loops." Upon further reflection, it is certainly conceivable, but it is not necessary. The inner loop, which does the updating, can be replaced with a single call to LinearAlgebra:-ForwardSubstitute.

Here's an outline: Let the original problem be solving for X in A.X = B. Let X0 be an inital guess of the solution. In the procedure's initialization, split A as L + U where L is lower triangular and U is strictly upper triangular. This can be done like this:

    L:= Matrix(
        A, 'shape'= 'triangular'['lower'], 'storage'= 'triangular'['lower'],
        'datatype'= 'hfloat'
    );
    U:= Matrix(
        A, 'shape'= 'triangular'['upper'], 'storage'= 'triangular'['upper', 'strict'],
        'datatype'= 'hfloat'
    );

Now the body of the outer (and only) loop can simply be the single line

        X:= LinearAlgebra:-ForwardSubstitute(L, B - U.X)

if your convergence criterion is based on the residual A.X - B. If the criterion is based on absolute error, then you can't overwrite X immediately, and you need one more line:

        X:= copy(X1);
        X1:= LinearAlgebra:-ForwardSubstitute(L, B - U.X)

@janhardo I think that this MaplePrimes thread is getting too long. It takes a long time to load, and scrolling to the latest update is difficult. Would you please ask the above as a new Question? Indeed, I think that topically it is indeed an independent Question, worthy of its own thread. Surely we shouldn't be expected to discuss every exercise in your whole textbook in this one thread.

@janhardo In a version of this Question that you've substantially altered, you had a problem and question regarding the circle command. The reason for your error is that circle is in the plottools package, not the plots package; so, if you call it as plottools:-circle, you wouldn't have the error.

@janhardo If a curve is specified parametrically by 

x= f(t), y= g(t), -infinity < t < infinity;

then its arclength between t1 and t2 is

Int(sqrt(diff(x,t)^2 + diff(y,t)^2), t= t1..t2).

You could think of that as a path or line integral (the precise distinction between those two is inconsistently defined---it varies among authors), but I think that it's better for now if you just think of it as the 1-D integral shown above. As a VectorCalculus integral, it would be

VectorCalculus:-PathInt(1, [x,y]= 'Path'(<f,g>, t= t1..t2)).

So, when finding the arclength with this method, the "integrand" is simply 1.

@abdgafartunde Try writing some pseudocode first. Check Wikipedia.

@miasene Some response indicating whether or not my Answer was useful to you would be appreciated.

Some response indicating whether or not my Answer was useful to you would be appreciated.

The type of analysis that I saw in the worksheet that you'd earlier attached (curvature, etc.) does require either Student:-VectorCalculus or plain VectorCalculus. I would advise against you working through this Folium of Descartes example if you do not understand the underlying calculus, which comes from third-semester or multivariable calculus.

@janhardo I don't know what you mean by "high-level commands" other than simply "any command that I haven't seen before" or perhaps "any command whose name contains punctuation marks". To me, they are low-level commands because they are built-in to the kernel rather than being defined in terms of other Maple commands (the vast majority of Maple commands).

Most of the prefix-form operators come from quoting the symbol of an infix operator, and are thus obvious; for example, a + b is equivalent to `+`(a, b). There are only 8 operators whose prefix forms are not so obvious:

`if` #conditional expression
`{}` #set constructor
`[]` #list constructor
`<,>` #matrix/vector constructor by rows
`<|>` #matrix/vector constructor by columns
`?[]` #indexing
`?()` #function application
`~` #elementwise (similar to map)

@naili You say "until here it works perfectly". Have you looked at the output?? The line H:= F(x, -1.8) is nonsense because it treats the expression F as if it were a function that could be applied to arguments. Consequently, the line ListeH:= ... is also nonsense. The definition of should be

H:= eval(F, y= -1.8);

@janhardo I think that you'll learn best by taking a symbolic example and deconstructing my commands. Please execute the following:

L:= [a, b, c]: 
f:= 'f': #i.e., f is just a symbol, to be used as a function
f~(L); #most-basic use of ~; similar to map(f, L)

`[]`(3, 7); #equivalent to [3, 7]
`[]`~([3], [7]);
`[]`~([a,b], [1,2]);
`[]`~(L, f~(L));

Using "functional-programming" syntax (such as mapzip, and ~) often requires that operators be used in "prefix operator-functional" form. `[]` is that form for the list-building operator [...]. All such forms are enclosed in back quotes: `...`

@ Here's my worksheet. The only things that are different from your worksheet are kernelopts(version)f:= (x,t)-> x - t, and the inclusion of k > 0 in the assuming clause.
 

restart

kernelopts(version);

`Maple 2020.0, X86 64 WINDOWS, Mar 4 2020, Build ID 1455132`

 

f:= (x,t)-> x-t:

eq := diff(u(x, t), t)-k*(diff(u(x, t), x, x)) = f(x, t)

diff(u(x, t), t)-k*(diff(diff(u(x, t), x), x)) = x-t

ic := u(x, 0) = 0

u(x, 0) = 0

"G(x,t):=1/(sqrt(4*Pi*k*t))exp(-(x^(2))/(4*k*t))"

proc (x, t) options operator, arrow, function_assign; exp(-(1/4)*x^2/(k*t))/sqrt(4*Pi*k*t) end proc

ans := u(x, t) = int(G(x-y, t-s)*f(y, s), y = -infinity .. infinity, s = 0 .. t)

u(x, t) = (1/2)*(int(piecewise(-csgn(1/(k*(-t+s))) = 1, -2*(-x+s)*Pi^(1/2)/(-1/(k*(-t+s)))^(1/2), infinity)/(Pi*k*(t-s))^(1/2), s = 0 .. t))

`assuming`([simplify(pdetest(ans, [eq, ic]))], [t > 0, k > 0])

[0, 0]

NULL


 

Download InhomoHeat.mw

@janhardo This is perhaps too "clever" to bring up at this point, but at least you can see some of the awesome power of Maple syntax. Acer's

map(p-> [p, f(p)], L)

is functionally equivalent to any of

`[]`~(L, f~(L))  #"clever"

or

[for p in L do [p, f(p)] od]  #very straightforward

or

[seq]([p, f(p)], p= L)  #in between

or

[D[], f]~(L);  #too clever

The explanation of the last one is that the "zeroeth-order derivative" of a "function"[*1] is itself, so the operator that "creates" that derivative is the just identity function. But Maple should provide a dedicated built-in identity function just for such functional-programming constructions. is not built-in to the kernel, and I think it'd be confusing to use a derivative operator anyway. And, I'm not sure that this functionality won't be changed in the future.[*1]

[*1] When D is used like this, it unintentionally ignores that its argument is not a really a function. 

@Preben Alsholm This bug has been fixed.

First 190 191 192 193 194 195 196 Last Page 192 of 709