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

@666 jvbasha You'll need to describe how the contour plot that you want is different from the contour plot that you show.

@acer Perhaps incorrect was the wrong term; I didn't mean syntactically. Perhaps logically incorrect or stylistically incorrect would be better. What I mean is that it was more-or-less merely a coincidence that it wasn't syntactically incorrect---even in 2020---the coincidence being that the procedure has no usesoptions, or description.

As you've pointed out, the "naked" semicolon terminates a NULL statement, and any statement marks the end of the procedure's header.

The reason that I bring it up is that I think that the OP and many other readers misunderstand both the semicolon and what exactly constitutes a statement.

@janhardo The problem of plotting the tread-riser pattern is complicated by these two issues:

  1. There is always one more x-value than there are y-values.
  2. It's not clear whether the "extra" x-value is the left extreme or right extreme; that somewhat depends on whether it's a left, right, or midpoint sum.

I thought about a simple way to handle those issues for a long time (about three hours while drifting in and out of sleep (I sleep with my computer with Maple open.)) before I posted my Answer. I think that you're struggling with these same two issues. My solution is to have lists rather than 2: EF, and X. Lists are like simplified arrays, and it's often better to use them when they'll do the job. is the x-values of the partition (including the left and right extremes of the interval). is the x-values where evaluations occur (either the left, middle, or right of each subinterval). is the y-values, and it's equivalent to applying f to all the values in E. The seq in my plot,

[seq]([[X[k],0], [X[k],F[k]], [X[k+1],F[k]], [X[k+1],0]][],

draws the left-side vertical, the top horizontal, and the right-side vertical for every rectangle. Although this duplicates the interior verticals, I thought that pedagogically that that was the right choice.

 

Is your Array 1-dimensional? Do its indices start at 1?

You have a one-variable function. I think of contours (aka level curves) as something one plots for two-variable functions. So what do you mean by "contour", and what do you mean by "a" contour?

@mmcdara The reason that your file will not load is that it has a special character in its filename.

@David Sycamore 

I'm glad that you got some use out of the Programming Guide. I hope that you continue to study it.

You wrote:

  •  I wrote a code to find ... k1, k2 for each prime up to a limit.

Please post your proc that finds both k1 and k2. (But I don't care about the one that just finds k1.)

  • I have also looked again at your code and seen that k1,k2 are not the same as K1 and K2.

It disturbs me that you write "k1,k2" (repeatedly) with no space after the comma. I wonder if that is somehow connected to your problems understanding.

  • [O]nly k1,k2 are given initial values.

Not all variables need to be initialized. A variable that counts something iteratively needs to be initialized to 0.

  • [T]he 'name' of the proc is k1k2 and that this is never used (called) again.

There's usually no reason to use a procedure's name within the procedure itself; sometimes, but only rarely, that is needed.

  • I dont know what K2[p] and K1[p] mean but they seem to be assigned (using :=) to the current values of k2 and k1....

Making a direct assignment to an indexed variable, such as A[...]:= ..., causes A to be a table (see ?table). In my procedure, K1 and K2 associate their respective values of (the prime) with the corresponding value or k1 or k2. A table is like a function defined on a finite set, where I mean function in the mathematical sense.

  • [T]he final values of k1,K2 are delivered but now there are no square brkts [ ] following them.

You mean K1 and K2. The procedure's output is the pair of tables K1 and K2 in their entirety. Square brackets would be used to select specific entries.

  • I tried to adapt your code to tell me the values k1,k2 in sequence format....

This doesn't require any modification to the procedure itself; rather, you do it after the procedure is called. Only do this with a small value such as 100 used for the number of primes, or else an overwhelming amount of information will be displayed:

(K1,K2):= k1k2(100):
entries(K1, pairs, indexorder);
  2 = 1, 5 = 2, 11 = 3, 17 = 4, 23 = 5, 29 = 6, 37 = 7, 41 = 8, 
  47 = 9, 53 = 10, 59 = 11, 61 = 12, 67 = 13, 71 = 14, 73 = 15, 
  79 = 16, 83 = 17, 89 = 18, 101 = 19, 107 = 20, 113 = 21, 
  127 = 22, 131 = 23, 137 = 24, 139 = 25, 149 = 26, 163 = 27, 
  167 = 28, 173 = 29, 179 = 30, 191 = 31, 197 = 32, 199 = 33, 
  223 = 34, 227 = 35, 229 = 36, 233 = 37, 239 = 38, 251 = 39, 
  257 = 40, 263 = 41, 269 = 42, 277 = 43, 281 = 44, 283 = 45, 
  293 = 46, 307 = 47, 311 = 48, 313 = 49, 317 = 50, 331 = 51, 
  347 = 52, 353 = 53, 359 = 54, 373 = 55, 379 = 56, 383 = 57, 
  389 = 58, 397 = 59, 401 = 60, 419 = 61, 431 = 62, 433 = 63, 
  443 = 64, 449 = 65, 457 = 66, 461 = 67, 463 = 68, 467 = 69, 
  479 = 70, 491 = 71, 499 = 72, 503 = 73, 509 = 74, 521 = 75, 
  541 = 76

#And likewise:
entries(K2, pairs, indexorder);

You quoted my procedure. At the end, you have

end proc
:
(K1,K2)

This leads me to believe that you mistakenly think that that (K1,K2) at the bottom are part of the procedure. They are not. The procedure ends at end proc.

 

@pik1432 

There are many ways to input a coefficient matrix using Maple's 1D input. I'd guess that there are more ways to do it than there are for inputting any other structure. In the way that I used, the rows are separated by semicolons, and the entries within each row are separated by commas. Adding line breaks and indentation is always syntactically valid, so this can be used to make the input itself look like a matrix. For example, the coefficient matrix above could be input as

C:= < 
    #xl12 xl13 xl23
      1,   1,  -1;
      1,  -1,   1;
     -1,   1,   1
>; 

As always in linear algebra, each matrix column represents the coefficients of a particular varable. 

In Matrix and Vector construction, the angle brackets ... are always used in a left and right matched pair, just like parentheses ... ), square brackets [ ... ], and curly braces ... }. Of course, these angle brackets are the same ASCII keyboard characters as the less-than and greater-than symbols.

column vector is specified in angle brackets with commas separating the entries. In the case above, I could've used

X:= <
    X1,
    X2,
    X3
>;
xl:= < 
    xl12,
    xl13,
    xl23
>;

row vector uses as the separator, for example R:= < 3 | 5 | 7 >. (The code in my Answer above didn't use any row vectors.)

A Matrix or Vector can be multiplied or divided by a scalar coefficient using the familiar and operators; so C/2 divides every entry of my above by 2.

The command LinearAlgebra:-LinearSolve(A, b) solves the matrix equation Ax = b for column vector x(It can also be used if b is a matrix.) 

The elementwise operator can be appended to another operator, such as =~, to indicate that an operation is to be applied to the elements rather than to the vectors as a whole. Scalar multiplication is automatically elementwise, but C/2 could also be written C/~2 if you want.

So, given the input above, your solution can be found as 

xl =~ LinearAlgebra:-LinearSolve(C/2, X)
          

@abdgafartunde Have you been able to turn any of this information into a procedure?

@miasene Please post a worksheet showing the "no results." Did you use the procedure Perm for the intial constructions, exactly like I had?

@Carl Love One benefit of a two-loop method is that the inner loop can accumulate the norm of the change in the X vector without needing to copy the vector. The smallness of that norm is a better convergence criterion than the residual (A.X - B). 

Thus, the body of the outer loop could be:

err:= 0; 
for i to n do 
    (X[i], t):= ((B[i] - add(A[i,j]*X[j], j= N minus {i}))/A[i,i], X[i]); 
    err:= err + abs(X[i] - t) #1-norm 
od

where N = {$1..n}.

Addendum: I delight is seeing how much a code can be compressed (still maintaining readable spacing and indentation) by using Maple 2019 or later syntax (although I think that you're using Maple 2017). Doing this, the entire procedure can be made

GaussSeidel:= proc(
    A::Matrix(square), B::Vector, X0::Vector,
    abstol::positive:= 10.^(2-Digits), maxiters::posint:= 99
)
local X:= Vector(X0, datatype= hfloat), n:= numelems(X), i, k;
    for k to maxiters do until
        abstol > 
        add(abs((X[i] - (X[i]+= (B[i] - A[i].X)/A[i,i]))), i= 1..n)
    ;
    if k > maxiters then error "did not converge" else X fi
end proc
:

The add could be parallelized to Threads:-Add if abs(...is replaced by CopySign(..., 1).

@janhardo Okay, I can read it now. Thanks. Now you pick which of those 9 curves that you want to start with and enter it into a Maple worksheet. Also enter the "other" curve that you're supposed to find intersection with. And please don't clutter up the worksheet with book pages.

@janhardo The book pages in your worksheet are too small for me to read (due to Maple not properly supporting my QuadHD screen---zooming doesn't increase the size of graphics). Please transcribe the problem that you want to work on and its instructions.

@Thomas Richard Do you know if it's possible to turn off the clickability of error messages? I hate accidentally clicking them.

@tomleslie I'm not recommending it as a workaround. I'm recommending it as the only truly correct and robust way---even if the phenomenon is deemed a bug and fixed.

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