MATLAB v. Julia - why different results?

371 views
Skip to first unread message

Alexander Dubbs

unread,
May 29, 2014, 10:20:51 AM5/29/14
to julia...@googlegroups.com
I can't for the life of me figure out why these two functions return different things, the function is called smooth, and in MATLAB:

X = zeros(2,375);
X(1,:) = 1:375;
X(2,:) = 2:376;
Y = smooth(X,125,8)

Y =

   125
   126

and in Julia

X = zeros(2,375);
X[1,:] = 1:375;
X[2,:] = 2:376
Y = smooth(X,125,8)
2x1 Array{Float64,2}:
 127.0
 128.0

The functions are (MATLAB then Julia)

--------------------------------------------------------------------------------------------------------------------------------------------

function Xout = smooth(Xin,k,s)

Xout = zeros(size(Xin,1),1);

for z = -s:s

    Xout = Xout + Xin(:,k+z)*nchoosek(2*s,s+z);

end

Xout = Xout/2^(2*s);

--------------------------------------------------------------------------------------------------------------------------------------------

function smooth(Xin,k,s)

Xout = zeros(size(Xin,1),1)

for z = -s:s

Xout = Xout + Xin[:,k+z]*binomial(2*s,s+z)

end

Xout = Xout/2^(2*s)

return Xout

end

Jacob Quinn

unread,
May 29, 2014, 10:29:09 AM5/29/14
to julia...@googlegroups.com
Weird. I get the same output as Matlab.

In  [84]: function smooth(Xin,k,s)
    Xout = zeros(size(Xin,1),1)
    for z = -s:s
        Xout = Xout + Xin[:,k+z]*binomial(2*s,s+z)
    end
    Xout = Xout/2^(2*s)
    return Xout
end

Out [84]: smooth (generic function with 1 method)

In  [85]: X = zeros(2,375);
X[1,:] = 1:375;
X[2,:] = 2:376
Y = smooth(X,125,8)

Out [85]: 2x1 Array{Float64,2}:
 125.0
 126.0


What version of Julia are you on? (julia -e "versioninfo()")

-Jacob

Alexander Dubbs

unread,
May 29, 2014, 10:36:57 AM5/29/14
to julia...@googlegroups.com, quinn....@gmail.com
versioninfo()
Julia Version 0.2.1
Commit e44b593* (2014-02-11 06:30 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin12.5.0)
  WORD_SIZE: 64
  BLAS: libgfortblas
  LAPACK: liblapack
  LIBM: libopenlibm

Miguel Bazdresch

unread,
May 29, 2014, 11:08:21 AM5/29/14
to julia...@googlegroups.com
Weird indeed -- I have the same version and I get the same output as Matlab (125.0 and 126.0).

julia> versioninfo()

Julia Version 0.2.1
Commit e44b593* (2014-02-11 06:30 UTC)
Platform Info:
  System: Linux (x86_64-unknown-linux-gnu)
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY)
  LAPACK: libopenblas
  LIBM: libopenlibm

-- mb

Matt Bauman

unread,
May 29, 2014, 2:55:26 PM5/29/14
to julia...@googlegroups.com, quinn....@gmail.com
I cannot reproduce with an identical versioninfo() on a Core i5 M520.  Perhaps this is a CPU-specific kernel bug; what processor is this on?  You can get that information with versioninfo(true).

Alexander Dubbs

unread,
May 29, 2014, 3:17:54 PM5/29/14
to julia...@googlegroups.com, quinn....@gmail.com
I have an overnight run so I went home, I'll get you the info first
thing tomorrow.
Reply all
Reply to author
Forward
0 new messages