Carl Love

Carl Love

28055 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

@Markiyan Hirnyk 

The MaplePrimes search is horrible. And Google does not properly index MaplePrimes: All searches point to the User's Answers page, which is worthless in my case because I have over 1800 Answers. So, I can't find my own Answer. So could you please post a link to it?

Note that I can easily use Google to find my Answers on StackOverflow, Yahoo groups, comp.soft-sys.math.maple, etc. This situation that MaplePrimes is not properly indexed by Google is deplorable. What a waste of valuble information!

@Andriy Yes, I believe it was added in Maple 18.

@Markiyan Hirnyk 

Yes, of course: Your x-values are not evenly spaced. Further hint: Represent that spacing by h.

@KimonoMyHouse After you Replied, I added information about your second error to my Answer above.

@Preben Alsholm

Here is the version with limit:

power:= (E::algebraic, t::name)->
     limit(simplify(expand(t*diff(expand(ln(E)), t))), t= infinity)
:

When used with symbolic exponents, this reveals some interesting limitations/bugs of limit:

power(t^a+t^2, t) assuming a>2;

                 a

That's fine. But...

power(t^a+t^2, t) assuming a<2;

                 limit((t^a*a+2*t^2)/(t^a+t^2), t = infinity)

And...

power(t^a+t^2, t) assuming a<2, a>0;

                 a

That's wrong. It should be 2.

@Preben Alsholm 

It works when the power of t is the same in all terms in the sum (unless you have a counterexample). The OP asked for the power of t, not the highest power of t. If the sum is of terms with different powers of t, then power returns an expression that depends on t that may have some significance that I haven't figured out yet. Perhaps I should take the limit as t -> infinity of this expression. That would give the highest power of t.

@Kitonum 

Your two procedures produce the same results, but the second is far more efficient. It can be made even more efficient and easier to read by using the structured type identical(t)^integer instead of `^` (see ?type,structure) and by using map2 to avoid calls to your anonymous arrow procedure s-> op(s)[2]. Like this:

power:= (E::algebraic, t::name)-> max(map2(op, 2, indets(E, identical(t)^integer))):

@Kitonum 

You need to at least specify the variable with respect to which the degree is being measured.

 

@acer 

Here's my timings of your code using 64-bit Maple 2015 on my best computer: An Intel i7-4710 @ 2.5 GHz x 8 cpus running Windows 8.1 64-bit. I don't have any older Maples on this computer for comparison:

                             [  NativeMaple = 18.112   ]
                             [                         ]
                             [     evalhf = 5.689      ]
                             [                         ]
                     Times = [    compiled = 0.151     ]
                             [                         ]
                             [   Convolution = 0.063   ]
                             [                         ]
                             [Compiled_parallel = 0.057]

@Markiyan Hirnyk 

listcontplot will not work directly with the data in the form that it's currently in. The z values would need to be formed into a GRID. This may involve ArrayInterpolation depending on how organized the x and y values are. If using listcontplot, the tickmark ranges for the x and y axes need to be explicitly constructed from the x and y data.

If a continuous gradation of colors is sufficient, and the surface is homeomorphic to a square, plots:-surfdata could be used with options style= surface, shading= zhue, orientation= [-90,0], axes= box. But the data will need to be "massaged" a little to get it into one of the forms accepted by surfdata.

There are many options and details to consider. It would be easier for me to show you how it's done than for me to describe all the options and details---many of which may not apply in your case. So please post your data (as plaintext or uploaded in a plaintext file).

One detail that I need for you to decide: Do you want a contour plot with black lines separating distinct colored regions? or simply colored lines on a white background? Or would you be satisfied with a continuous gradation of color and no lines?

Do you know the topology of the surface (not the whole theoretical surface, just the part represented by the data)? Is it homeomorphic to a square ([0,1]^2)? That would be the easiest situation to deal with.

@Alejandro Jakubi 

Inertizing exp can be combined with a print procedure for %exp so that the results look like this:

 

restart:

`print/%exp`:= ()-> 'exp'(args):         

 

term:= proc(lst::list(algebraic), k::integer)

local n:= nops(lst);     

     seq(lst[m+1]*%exp(-I * 2*Pi/n *(k*m)), m= 0..n-1)

end proc:

r:= term([1,2,3], 1);

%exp(0), 2*%exp(-((2/3)*I)*Pi), 3*%exp(-((4/3)*I)*Pi)

(1)

value([r])[];

1, -1-I*3^(1/2), -3/2+((3/2)*I)*3^(1/2)

(2)

 

 

Download Inert_exp.mw

@acer 

Thanks Acer! I already realized, anticipated, and implemented most of what you wrote. Also, I made a compiled version, which gives a factor-of-14 improvement over evalhf. I arranged the code so that the exact same procedure could be compiled and evalhfed.


restart:

 

k:= 3:

filelocation:= "C:/Users/Carl/Desktop/MapleLeaves.jpg":
#I tested this on a mid-size picture: 800 x 533, 154 kB

zimage:= ImageTools:-Read(filelocation):

zwidth:= ImageTools:-Width(zimage):

zHeight:= ImageTools:-Height(zimage):

kernell:= 2*k+1:

kerneld:= Matrix(
     kernell, kernell, fill= 1/kernell^2, datatype= float[8], order= C_order
):

#ImageTools:-View(zimage);

st:= time():

new1zumage:= ImageTools:-Convolution(zimage,kerneld):
Time[Convolution]:= time()-st:

#ImageTools:-View(new1zumage);

aa:= zimage(1..,1..,1):

bb:= zimage(1..,1..,2):

cc:= zimage(1..,1..,3):

newaa:= copy(aa):
R:= LinearAlgebra:-RowDimension(aa):
C:= LinearAlgebra:-ColumnDimension(aa):


st:= time():

for i from k+1 to R-k-1 do
     for j from k+1 to C-k-1 do
          newaa[i,j]:= add(x, x= aa(i-k..i+k,j-k..j+k)*~kerneld)
     end do
end do;
Time[NativeMaple]:= time()-st:


Convolve:= proc(
     aa::Array(datatype= float[8], order= C_order),
     newaa::Array(datatype= float[8], order= C_order),
     kerneld::Array(datatype= float[8], order= C_order),
     k::posint, R::posint, C::posint
)
local
     i, j, m, n,
    `k+1`:= k+1, `C-k-1`:= C-`k+1`,`R-k-1`:= R-`k+1`, kernell:= 2*k+1,
    `i-k-1`, `j-k-1`
;     
     for i from `k+1` to `R-k-1` do
          `i-k-1`:= i-`k+1`;
          for j from `k+1` to `C-k-1` do
               `j-k-1`:= j-`k+1`;
               newaa[i,j]:=
                    add(
                         add(
                              aa[`i-k-1`+n, `j-k-1`+m] * kerneld[n,m],
                              m= 1..kernell
                         ),
                         n= 1..kernell
                    )
          end do  
     end do
end proc:


st:= time():
evalhf(Convolve(aa, newaa, kerneld, k, R, C)):
Time[evalhf]:= time()-st:
                          

Convolve_C:= Compiler:-Compile(Convolve):

Warning, the following variable name replacements were made: C-k-1 -> cg, R-k-1 -> cg1, i-k-1 -> cg3, j-k-1 -> cg5, k+1 -> cg7

 


st:= time():
Convolve_C(aa, newaa, kerneld, k, R, C):
Time[compiled]:= time()-st:

Times = Vector(op(eval(Time)));

Times = (Vector(4, {(1) = Convolution = 0.78e-1, (2) = NativeMaple = 14.141, (3) = compiled = .391, (4) = evalhf = 5.938}))

(1)

 


Download Compiled_example.mw

@acer 

Yes, your correction is what I intended. I will correct the code above.

Do you have any idea why I am not getting the factor-of-25 performance improvement that I usually get from evalhf? Is it because the elementwise multiplication in the original is already optimized?

Can I improve caching by changing the order of some matrices?

@rollermonkey 

You must've entered with(Plots), not with(plots). Capitalization matters. That Maple returns withPlots when you enter withPlots is just its response to meaningless but syntactically correct input, just as if you had entered foo.

Yes, I believe that one can now get a space curve with the plot3d command in the manner that you show, but, as far as I can tell, this is undocumented.

I was a beta tester for Maple 2015, and I've been using it for three months. So I can assure you that := (with no space between the : and the =) is valid syntax. Foo=Bar is also valid syntax, but it does not assign the value of Foo. I think that you may have a bad install. I recommend installing the whole program again.

I can also assure you that ending/separating statements with semicolons or colons is valid syntax. You may omit a final one in each execution group, but it's certainly still valid to include.

First 500 501 502 503 504 505 506 Last Page 502 of 709