Julia正常的DCT(fftw.jl)行为是吗?

发布于 2025-01-23 03:47:25 字数 846 浏览 3 评论 0原文

我正在尝试对Julia进行一些压缩感的练习,但是我意识到身份矩阵的离散余弦转换(使用FFTW.JL)看起来并不是其他编程语言(又称Mathematica和Matlab)的结果。

例如,在朱莉娅(Julia)中

using Plots, FFTW, LinearAlgebra
n = 100
Psi = dct(Matrix(1.0I,n,n))
heatmap(Psi)

会导致此矩阵(本质上是具有一定噪声的身份矩阵)

https://i.sstatic.net/kdyvh.png

imagesc(dct(eye(100,100),'Type',2))

“ alt = ” 。 a>

终于在Mathematica中

MatrixPlot[N[FourierDCTMatrix[100, 2]], PlotLegends -> Automatic]

返回此

”身份矩阵的Mathematica

为什么Julia的行为如此不同? 这是正常的吗?

I'm trying to do some exercises of Compressed Sensing on Julia, but i realize that the discrete cosine transformation (using FFTW.jl) of an identity matrix doesn't looks as the result of other programming languages (aka. Mathematica and Matlab).

For example in Julia

using Plots, FFTW, LinearAlgebra
n = 100
Psi = dct(Matrix(1.0I,n,n))
heatmap(Psi)

results in this matrix (which is essentially an identity matrix with some noise)

Julia's dct for an identity matrix

But in Matlab

imagesc(dct(eye(100,100),'Type',2))

this is the result (as expected)

Matlab dct type 2 of an identity matrix

Finally in Mathematica

MatrixPlot[N[FourierDCTMatrix[100, 2]], PlotLegends -> Automatic]

returns this

Mathematica dct of an identity matrix

Why Julia behaves so differently?
And is this normal?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你げ笑在眉眼 2025-01-30 03:47:25

MATLAB(和我猜Mathematica),对矩阵中的每一列进行DCT。当输入是二维时,FFTW执行二维DCT。 FFT也是如此。

如果需要列的转换,则可以指定尺寸:

Psi1 = dct(Matrix(1.0I,n,n), 1);  # along first dimension
heatmap(Psi1)

请注意,y轴的方向相对于MATLAB而言,绘制的方向是相反的。

(顺便说一句,您也可以写i(n)1.0i(n),而不是matrix(1.0i,n,n,n,n,n) )

这是将朱莉娅与其他一些语言区分开来的东西。它倾向于将矩阵视为矩阵,而不仅仅是载体的集合或一堆标量。例如,EXP(M)log(M)用于矩阵不操作元素,但会根据其线性代数定义来计算矩阵指数和矩阵对数。

Matlab (and I guess Mathematica), does dct of each column in your matrix. FFTW performs a 2-dimensional dct when the input is two-dimensional. The same happens for fft.

If you want column-wise transformation, you can specify the dimension:

Psi1 = dct(Matrix(1.0I,n,n), 1);  # along first dimension
heatmap(Psi1)

Notice that the direction of the y-axis is opposite for Plots.jl relative to Matlab.

(BTW, you can also just write I(n) or 1.0I(n) instead of Matrix(1.0I,n,n))

enter image description here

This is something that sets Julia apart from some other languages. It tends to treat matrices as matrices, and not as just a collection of vectors or a bunch of scalars. For example exp(M) and log(M) for matrices not operate elementwise, but will calculate the matrix exponential and matrix logarithm according to their linear algebra definitions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文