在Matlab的复杂平面上绘制匿名函数及其属性

时间:2018-07-25 22:53:00

标签: matlab

found this beautiful plot产生的东西与我想要达到的目标相似,但它是使用Mathematica产生的。我从来没有使用过Mathematica,所以不确定使用Matlab是否可以实现相同的目的。

enter image description here

在这里,我已经在Matlab中创建了一个类,其中包含尝试翻译上面链接中找到的Mathematica代码的尝试。如果要运行,只需将其保存到新的m文件中。全文中存在以评论形式出现的问题。

classdef xPlot
    properties
        info = 'Plots complex domain';
    end

    methods(Static)

        function [HSV] = createHSV(Z)
            R = real(Z);
            I = imag(Z);

            % The argument is just "atan2(I,R)" or "angle(Z)"
            % The result is in radians, ranging from -pi:pi (this is the
            % same as Mathematica)
            h = atan2(I,R)/(2*pi);

            % Not sure how to read the Mathematica syntax with the "sin" 
            % and "abs" arguments. Is it a product?
            s = abs(sin(2*pi*abs(Z)));
            b = sqrt(sqrt(abs(sin(2*pi*I)*sin(2*pi*R))));
            b2 = 0.5.*((1 - s) + b + sqrt((1 - s - b).^2 + 0.01));

            % I think we're trying to create a colormap, with each HSV
            % channel defined as follows?
            HSV(:,:,1) = h;
            HSV(:,:,2) = sqrt(s);
            HSV(:,:,3) = b2;

        end

        function [img,cmap] = createColorMap(Z,n)

            % Use HSV
            HSV = xPlot.createHSV(Z);

            % Resample
            % Not really sure what the point of resampling is? When I
            % define the domain, I just make it "n+1", as defined with the
            % user input. Why would I want to resample?

            % My interpretation of the Mathematica code is missing
            % something. We can't "imagesc" a matrix of complex values
            cmap = HSV;
            img = Z;
        end

        function domainFigure(fun,maxVal,n)

            % Domain
            x = linspace(-maxVal,maxVal,n+1);
            y = x;
            [xx,yy] = meshgrid(x,y);

            % Function
            switch fun
                case 'sin'
                    Z = sin(xx + 1i*yy);

                otherwise
                    disp('Function not an option')
            end

            % Create the image
            [img,cmap] = xPlot.createColorMap(Z,n);

            figure
            % Is it wrong to use "imagesc"? I think this imposes some
            % scaling argument, which might conflict with our intentions or
            % defining the scaling manually.
            imagesc(img);
            xlabel('RE');
            ylabel('IM');
            title(['Domain Colouring of "',fun,'"'])
            set(gca,'yaxis','normal')
            axis([-maxVal maxVal -maxVal maxVal])
        end

        function [status] = domainPlot(varargin)
            nArgs = length(varargin);

            % defaults
            if nArgs < 3
                varargin{3} = 500;
                if nArgs < 2
                    varargin{2} = pi;
                    if nArgs < 1
                        varargin{1} = ones(n);
                    end
                end
            end

            % Var name list
            fun = varargin{1};
            maxVal = varargin{2};
            n = varargin{3};

            % Create the figure
            xPlot.domainFigure(fun,maxVal,n);

            % Just a dummy output
            status = 1;
        end

    end
end

然后可以使用默认参数as

从命令行直接调用该类。
xPlot.domainPlot('sin')

我的目标是创建一些可以在复杂平面上可视化功能及其属性的东西。例如,main函数参数可以是匿名函数(而不是字符串),例如多项式,在这里我可以创建一个显示根和轮廓的图。 This is what I'm trying to create as I find the visuals beside their functions very informative

为了仅在复杂平面上获得视觉效果,上述类将字符串作为参数,该函数在内部进行了硬编码。我认为这是第一步,但同样,我也难以解释要在Matlab中使用的Mathematica代码。

0 个答案:

没有答案
相关问题