Carl Love

Carl Love

28035 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

There is a bug in MaplePrimes such that it doesn't properly upload *.maple files. A workaround is to convert it to a *.zip file and upload that.

@pauldaas Here's an improvement that I should've mentioned earlier:

f:= unapply(piecewise(for i to n+1 do x <= a[i], y[i](x) od), x);

Like f:= x-> ..., this also creates an arrow expression procedure. The difference is that unapply​​​ builds the piecewise expression first (and only once), then turns it into a procedure. The f:= x-> ... form rebuilds the piecewise for each value of x.​​​​

@pauldaas Since you had the right idea about embedded for loops, I should show precisely where your syntax was wrong. But first, note that embedded for loops can only be used in 1D input (plaintext input). So, here's your code, line by line:

  1. f(x)=piecewise(

  2. x<a[1],y(x)[1],

  3. for i from 2 to n+1,

  4. a[i-1] <=  x  <=  a[i], y(x)[i];

  5. od:);

Line 1: To define a function (formally called a procedure or arrow expression), line 1 should be

f:= x-> piecewise(

Line 2:

  1. Because of what I say about line 4 below, it's not necessary to separate out the first branch as special. 
  2. An indexed function is y[1](x), not y(x)[1].

Line 3: 

  1. If line 2 is included (although it's not needed), then the embedded for loop (in its entirety) must be enclosed in parentheses.
  2. Replace the comma at the end with the word do.

Line 4:

  1. Chained inequalities such as a < b < c are not allowed in 1D input. If such is needed (although it's not needed in this case), you could use And(a < b, b < c).
  2. Although the And(...form inequality is allowed for the conditions in piecewise, it's not needed, and it's preferable not to use it. The reason is that the piecewise conditions are processed left to right. If condition k is being evaluated, then it's necessarily true that conditions 1 thru k-1 have already been determined to be false.
  3. The semicolon at the end is optional, and in the case of an embedded for loop, I think that it's undesirable (because the values returned to the sequence by the loop necessarily come from the last statement of the loop). 

Line 5:

  1. An embedded for loop is an expression, not a statement, so it's not allowed for there to be a colon or a semicolon immediately after od.
  2. However, the semicolon after the closing parenthesis is fine because it terminates the statement that began with f:=.

 

@vsnyder Yes, I should've said (and indeed, I was just editing my previous Reply to say it) that the penalty that I was referring to was additive, not multiplicative. So, if it cost an extra second, then that's approximately what it'll always cost. If one were loading LinearAlgebra to do a trivial-time operation (such as solving a linear system in hardware floats), then 1 second would be a huge penalty.

The primary reason that I don't use with is that I think that it reduces code readability. Instead I assign the package prefix to a short variable name (such as LA:= LinearAlgebra) and then just use that. 

@vsnyder You are correct that you don't want to be opening a new Maple session repeatedly, and I don't know how to help you with StartMaple. However, it's not "necessary" to load packages with with; and, indeed, doing so incurs a significant performance penalty (for the loading itself; no penalty for using the package's commands). Just use the so-called "long forms" of the command names, such as LinearAlgebra:-LinearSolve.

There was no confusion in what you wrote; however, to avoid possible confusion in the future: Things such as LinearAlgebra are called packages, not libraries. The distinction is important because Maple also has libraries, which are the level of "compiled" code containerization one level larger than packages.

@Zeineb The iteration count is not a meaningful stopping criterion for Newton's method, so why are you fixated on the sixth iteration in particular? The only reason to impose a limitation on the iteration count is to prevent infinite loops. The meaningful stopping criteria are any combination of

  1. relative: abs((x[n] - x[n-1])/x[n]) < tolerance
  2. absolute: abs(x[n] - x[n-1]) < tolerance
  3. residual (aka function value): abs(f(x[n])) < tolerance

(In particular, I like if crit_3 and (crit_1 or (abs(x[n]) < tolerance and crit_2)) then return x[n] fi.) The above could be done with a different value of tolerance used for each criterion.

Your particular equation has a unique real solution 19.75...; anything different than that is worthless as a solution.

@Pepini You can't directly contourplot a complex-valued function. But you could replace the eval in eval(f(z)) with any of absargumentReIm, etc.

And, your use of eval does nothing (neither good nor bad) since f(z) is already fully evaluated. In acer's code it was eval(f). That does something because the name of a procedure, f, is not fully evaluated.

I recall that this Question had several responses, including contributions from @acer and @Joe Riel. What happened to them?

An inverse Laplace transform can also be calculated directly by integration. This is a very straightforward and totally formulaic approach. However, the integral can be difficult. In this particular case, Maple has no trouble with it. In the code below, can be chosen to be any real number that's greater than the real parts of all the roots of the denominator of the transform. Naturally, since 0 is such a real number in this case, that's what I chose.

F:= s-> 1/(s^2+8*s+20):
fsolve(denom(F(s)), complex);
       -4.000000000 - 2.000000000 I, -4. + 2.000000000 I

r:= 0:
evalc(int(exp(s*t)*F(s), s= r-I*infinity..r+I*infinity)/2/Pi/I)
    assuming t>0;
                      1                   
                      - exp(-4 t) sin(2 t)
                      2                   

Another way of calculating this and other complex integrals is

evalc(add(residue~(exp(s*t)*F(s), s=~ [-4-2*I, -4+2*I])))

which produces the same result as the other methods.

@dharr You just posted 2 almost identical Answers. Please delete one of them.

@Pepini Yes, almost anywhere in Maple an entire "container" (list, set, array, table) of input values to a function can be placed syntactically as if it were a single input by using slight adjustments to the syntax that involve ~. This is called elementwise operation (see help page ?elementwise).

Suppose that f is any function of 2 real arguments producing a value in interval 0..1, and, as above, data is a list of 2-lists of real values. Then the color option could be

color= COLOR~(HUE, (f@op)~(data))

Or suppose that g is any function of a single complex argument producing a value in 0..1 and data is as above. Then the color option could be

color= COLOR~(HUE, (g@Complex@op)~(data))

In the above Answer, I effectively used g:= z-> .5 - argument(-z^2)/(2*Pi) without explicitly defining g. The .5 and 2*Pi are to rescale the output to interval 0..1.

​​​​​​

@agh314 The primary errors are the result of memory not being shared. Any variables that you've defined or structures that you've created (other than those in list) prior to calling Grid:-Map that might be needed by Query need to be sent to the remote processes by using Grid:-Set. I don't know DifferentialGeometry, so I don't know what a "defined frame" is, but I suppose that you do. Perhaps alg1 is a defined frame. So do

Grid:-Set(alg1) 

before Grid:-Map.

The error "invalid input: op expects 1 or 2 arguments, but received 0" is simply the result of there being no output to return due to the primary errors.

When you used Threads for this, are you sure that the results were correct? And did they truly run in parallel rather than locking each other out? What was the total CPU utilization (which you can check with Windows Task Manager or similar tools on other OSs)?

Since list is very small, you should use Grid:-Map[tasksize= 1](x-> ...)

If you do a numeric integration of an integrand that contains a symbolic variable (h in this case) other than the variable of integration, then what form of result are you hoping to get? I do not mean this as a rhetorical question; I literally want to know.

You should reduce the value of to 3 or 5, reduce Digits to 15, and run the code with the output-suppressing colons replaced by semicolons so that you can get some appreciation of the enormity of the expressions involved. And they'll be much larger still when M=50.

@Muhammad Usman Some response to my Answer would be appreciated.

@noecb2002 Thanks for the plaintext ODE. Using it, I have no trouble solving your IVP with standard dsolve options and no adjustment needed for the trunc (after I provided initial conditions that I made up). But I suspect that you may be trying to use one of the more complicated methods, perhaps lsode[backfull]. In order to have any chance of duplicating your error message, I need plaintext of your initial conditions AB and options dsolve_options. So please post the plaintext output of lprint([AB]) and lprint(eval([dsolve_options])).

First 122 123 124 125 126 127 128 Last Page 124 of 708