在 MATLAB 中绘制迭代定义的函数

Plotting iteratively defined function in MATLAB

我不是 MATLAB 专业人士,因此我需要一些帮助来生成迭代定义函数 f 的 3D 图:R^2- 0 -> R 定义如下(在伪代码中),用于 [-1, 1]

对于每个 I = 1,2,3A = (0.5,0.5)

function  f(v in R^2-0)
{
    a=b=0;     (a,b in R)        
    for (i=0; i<I; i=i+1)
    {
        v = |v| / ||v||^2 - A;
        a = a + | ||v||-b |;
        b = ||v||;
    }
    return a;
}

(|v|表示分量向量绝对值)

(如果你愿意,你可以在我关于数学交换的问题中查看函数生成的分形:

https://math.stackexchange.com/questions/1457733/a-question-about-a-fractal-like-iteratively-defined-function )

执行此操作的 MATLAB 代码将不胜感激。

非常感谢。

将此保存为您的主程序:

clear
clc
close all

% I = 1;
% A = [ 0.5 0.5 ];

I = 10;
A = [ 0.5 0.5 0.5 ];

xmin = -1;
xmax = 1;

ymin = -1;
ymax = 1;

nx = 101;
ny = 101;

dx = (xmax - xmin) / (nx - 1);
dy = (ymax - ymin) / (ny - 1);

x = xmin: dx: xmax;
y = ymin: dy: ymax;

for ix = 1: nx
    for iy = 1: ny
        if (length(A) == 2)
            z(iy, ix) = f([x(ix) y(iy)], A, I);
        elseif (length(A) == 3)
            z(iy, ix) = f([x(ix) y(iy) 0], A, I);
        end
    end
end

pcolor(x, y, z)
shading interp

然后把这个函数保存在和主程序一样的目录下f.m:

function result = f(v, A, I)

a = 0;
b = 0;

for i = 1: I
    v = abs(v) / dot(v, v) - A;
    a = a + abs(norm(v) - b);
    b = norm(v);
end
result = a;

end