Carl Love

Carl Love

28055 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

@mzaman 

Here's an example using evallhf. There is a time savings of more than a factor of two, but I had hoped for even more.


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]):

#ImageTools:-View(zimage);
st:= time():

new1zumage:= ImageTools:-Convolution(zimage,kerneld):
T0:= time()-st;

#ImageTools:-View(new1zumage);

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

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

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

subimage:= Matrix(kernell, kernell, datatype= float[8]):

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
          subimage:= aa(i-k..i+k,j-k..j+k)*~kerneld;
          newaa[i,j]:= add(add(subimage[m,n], m= 1..kernell), n= 1..kernell)
     end do
end do;
T1:= time()-st;

Convolve:= proc(aa, newaa, kerneld, subimage, k, R, C)
local i, j, m, n, `k+1`:= k+1, `C-k-1`:= C-`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`;
               for m to kernell do
                    for n to kernell do
                         subimage[m,n]:= aa[`i-k-1`+m, `j-k-1`+n] * kerneld[m,n]
                    end do
               end do;
               newaa[i,j]:= add(add(subimage[m,n], m= 1..kernell), n= 1..kernell)
          end do
     end do
end proc:

st:= time():
evalhf(Convolve(aa, newaa, kerneld, subimage, k, R, C)):
T2:= time()-st;
                          

0.78e-1

 

18.000

 

8.719

(1)

 


Download evalhf_example.mw

Edit: Code corrected as per Acer's Reply.

@tomleslie 

If you simply apply the simplify command to the equation being solved, then the solve will also work in the default environment.

And it would be nice if solve returned an expression with units. The commsnd solve is not one of the ones overloaded by the with command the loads the environment.

@reinhardsiegfried 

Observe:

N:= 3:
for i from 1 to 2 do
     f[i]:= t-> a[0][i]+Sum(a[j][i]*t, j= 1..N)
end do:

i:= junk:
f[1](1);

So, if you use ->, the i is evaluated at the time of invocation, not the time of definition; if you use unapply, i is evaluated at the time of definition.

 

@nMaple The direction, color, and intensity of the light can be programatically controlled with the light option (see ?plot3d,options). However, there's no easy way to read the numbers generated by User context-menu setting. You'll have to use trial and error to get the right numbers for the light option.

@jdam 

From the expression B+2*y, we can deduce that y has the same units as B, which are 'm'. Since y is the variable solved for, we can deduce that the expression returned by solve should have units 'm'.

In your posted code, you use the following technique:

f:= dsolve(...); #Symbolic dsolve, not numeric
f(x=3);

This is nonsense to Maple, but unfortunately it does not complain about it. If you want to evaluate the solution at x=3, use

eval(f, x= 3);

@mehdi jafari The OP is not using e as the familiar constant but rather as a substitute for the epsilon that is used in the paper. One problem (caused by 2D input) is that it is being interpretted as a function rather than as a coefficient. 

What is the significance of a base-dimension unit (like meters) raised to a fractional power like 1/6?

If you remove the units, you'll get an answer immediately from solve

@gdoug I see what you mean. Here's a corrected version.

HeadToTail:= proc(L::list(Vector(2)))
local L0:= [<0,0>, L[..-2][]]; print(L0, L -~ L0);
     plots:-arrow(zip(`[]`, L0, L -~ L0), args[2..]);
end proc:

Please let me know how that works for you.

 

 

@Markiyan Hirnyk 

parse will work for the example list that I showed, but I don't know if the OP's actual list contains all strings that simple. I chose not to use parse because the OP's list might contain something like "a b".

@tomleslie I think that your criticism is too harsh:

  1. The OP did upload a worksheet using the big green arrow. The amount of clipping on the right is browser dependent and the OP has no control over that. Note that there is a horizontal scroll bar so that you can read the right sides of the three lines (in Google Chrome) that got clipped.
  2. No one has to retype anything or do any cutting and pasting whatsoever because the OP included a link to the uploaded worksheet.
  3. I for one have no trouble understanding what the OP is asking. Your interpretation is in fact correct.

I will accept Kitonum's implied answer to my question above. You're asking for a cheap way to do it. By cheap, do you mean fast? Faster than fsolve? Do you have a large number of points that you want to project onto a specific curve? If so, a Newton iteration could be constructed to do it for that curve. The iteration can be automatically constructed and optimized for each given curve.

@Kitonum I'm guessing that the phenomenon that I described is an anomaly of Maple 16 (and maybe 17 and 15).


restart:

kernelopts(version);

`Maple 16.02, X86 64 WINDOWS, Nov 18 2012, Build ID 788210`

(1)

X:= [seq(i^3, i= 1..5000000)]:

st:= time():
`+`(X[]);
time()-st;

156250062500006250000000000

 

.624

(2)

restart:

X:= [seq(i^3, i= 1..5000000)]:

st:= time():
add(x, x= X);
time()-st;

156250062500006250000000000

 

1.060

(3)


Download plus_vs_add.mw

I've been able the duplicate the above on different computers. But in Maple 2015, I get that add is faster than `+`.

 

What does the projection of a point onto a curve mean? Can you give me a formula or reference for it?

@Alejandro Jakubi I wonder if add(U) is equivalent to `+`(U[]). Of course they produce the same result. But I think that `+`(U[]) is faster than add(u, u= U). That is, when the list of summands already exists (and only when it already exists) the prefix `+` form is faster than the older form of add.

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