Plot 2D function: do I need to pass all the values to the function?

I'm new with Octave and I need to plot this function:

% Computes the value of the Powell Sum benchmark function.
% SCORES = POWELLSUMFCN(X) computes the value of the Powell Sum function at 
% point X. POWELLSUMFCN accepts a matrix of size M-by-N and returns a vetor 
% SCORES of size M-by-1 in which each row contains the 
% function value for the corresponding row of X. 
% 
% Author: Mazhar Ansari Ardeh
% Please forward any comments or bug reports to mazhar.ansari.ardeh at
% Google's e-mail service or feel free to kindly modify the repository.
function scores = powellsumfcn(x)
    n = size(x, 2);
    absx = abs(x);

    scores = 0;
    for i = 1:n
        scores = scores + (absx(:, i) .^ (i + 1));
    end
end

I have copied from BenchmarkFcns.

I have no idea about how to plot it.

Do I need to pass all the possible values to the function plot it?

Topic plotting octave

Category Data Science


How about defining a plot function like:

function meshfcn(fcn, x, y)
    [X, Y] = meshgrid(x, y);
    Z = arrayfun(@(xx, yy)(fcn([xx, yy])), X, Y);
    mesh(X, Y, Z);

and then use it:

x = -2:0.1:2; % the range of 'x' values to plot. change to your needs
y = -2:0.1:2; % the range of 'y' values to plot. change to your needs
fcn = @powellsumfcn; % the function needs to be on the path
meshfcn(fcn, x, y)

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.