【问题标题】:Discretizing a continuous mathematical equation离散连续数学方程
【发布时间】:2019-05-14 15:14:31
【问题描述】:

我想实现一个代码,对大小为 (bs x bs x bs) 的立方体内的信息进行洗牌,这样立方体 (x,y,z) 内的每个元素都唯一地映射到 (x_new, y_new,z )。但是代码不能正常工作。

所附图像是我尝试离散化和实现的代码的实际数学定义。原始数学方程适用于单位立方体,而我有一个维度为 bs 的立方体。有人可以看看我的代码并提示假定的错误吗?

n=bs;
NEWI=zeros(bs,bs,bs);
for row= 1:bs
    for col=1:bs 
        for height=1:bs
            if (     1<=row && row<=(n/2) && 1<=col && col<=(n/2) )
                x_new= 2*(row-1) + 1;
                y_new= 2*(col-1) + 1;
                 z=floor(0.25*(height-mod(height-1,2)))+1; 
             end
for 
for
for

Now this is just the first line implementation of the equation given in the figure. But as we see the coorepondence of points 
             (1,1,1) goes to (1,1,1)
              (1,1,2) goes to (1,1,1)
              (1,1,3) goes to  (1,1,1)
               (1,1,4) goes to (1,1,1)
which clearly is not a unique mapping, whereas the function claims of giving unique images for every (x,y,z). So my question is clearly there has to be some adjustments to discretize this map. Can somebody suggest

【问题讨论】:

  • 为什么你认为它错了?想解释一下你的方程和你分享的方程之间的区别吗?愿意提供minimal reproducible example 吗?
  • 我发现了一个问题,那就是您将 n/2 乘以 2:y_new= 2*(col-1-n/2)。这与说y_new = 2*col - 2 - n 相同,总是否定的。我想你的意思是y_new= 2*(col-1)-n/2x_new 也重复此错误。我也不确定您为什么在每个操作中都涉及 height 值的奇偶校验。
  • 为什么会是负数?我已经包含了条件:col>n/2, already
  • 方程在 x 和 y 方向上将信息传播了 2 倍,并沿 z 方向将其压缩了 4 倍。显然,这在离散世界中是行不通的。 z/4 在 4 种情况下有 3 种会导致亚像素位置。这就是为什么您有 4 个值映射到同一位置的原因。
  • 但是我正在阅读的文章说它映射点是唯一的。

标签: matlab math


【解决方案1】:

您的某些情况尚不清楚:

  • 如果行总是&gt;=1,为什么要检查1&lt;=row
  • 为什么要使用模数? (正如@Welbog 所指出的)
  • ...

但要回答您的问题,我建议您使用逻辑索引和meshgrid,这将使您的代码更具可读性。您将能够在一行中完成所有操作。

% size of your 3D cube
n = 5;
% With meshgrid we generate the 3D grid that we will use to create the logical index.
[x,y,z] = meshgrid(1:n,1:n,1:n);
% Create empty array
M = zeros(n,n,n);
%first condition
I      = x<(n/2) & y<(n/2);        %create a logical index according to the first condition
M(I)   = 2*x(I) + 2*y(I) + z(I)/4; %generate the associated value
%second condition
I      = ...

【讨论】:

  • 模数用于调整 matlabi.e 中的索引,避免零索引
  • 我不明白你使用meshgrid的回答
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-03-21
  • 2022-07-07
  • 2021-12-04
  • 2017-10-30
  • 1970-01-01
  • 1970-01-01
  • 2018-05-02
相关资源
最近更新 更多