view plotConvergenceFit.m @ 577:e45c9b56d50d feature/grids

Add an Empty grid class The need turned up for the flexural code when we may or may not have a grid for the open water and want to plot that solution. In case there is no open water we need an empty grid to plot the empty gridfunction against to avoid errors.
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 07 Sep 2017 09:16:12 +0200
parents 0ef8965dd745
children
line wrap: on
line source

% Draws a line in a loglog plot with slope `slope` fitted to the data in `x`
% and `y`. `xlength` scales how much of the interval [x(1) x(end)] is coverd
% by the line. `offset` is a multiplicative offset to where the line is drawn
% relative to the data.
function hand = plotConvergenceFit(slope, x, y, xlength, offset)
    default_arg('xlength', 0.8)
    default_arg('offset', 1);

    % Optimise for log(y) = p*log(x) + q

    p = slope;

    logx = log(x);
    logy = log(y);

    N = length(logx);

    q = 1/N*sum(logy-p*logx);

    logxlength = xlength * abs(logx(end)-logx(1));
    logxends = (logx(1)+logx(end))/2 + [-logxlength/2, logxlength/2];

    xends = exp(logxends);
    yends = exp(q)*xends.^p;

    hand = line(xends, yends);
    hand.Color = Color.black;
    hand.LineStyle = '--';
    hand.LineWidth = 2;
end



% function hand = plotConvergenceFit(slope, pos, width)
%     x0 = pos(1);
%     y0 = pos(2);

%     x = [x0*10^-(width/2) x0*10^(width/2)];
%     y = x.^slope * x0^-slope * y0;

%     hand = line(x,y);
%     hand.Color = Color.black;
%     hand.LineStyle = '--';
%     hand.LineWidth = 2;
% end