Mercurial > repos > public > sbplib
changeset 442:e81325da6f8f feature/grids
Merge default into feature/grids
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 13 Mar 2017 14:44:31 +0100 |
parents | e1d11b6a68d8 (current diff) 0ef8965dd745 (diff) |
children | 3f236a83d8ad |
files | |
diffstat | 2 files changed, 46 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/convergenceTable.m Mon Mar 13 14:43:37 2017 +0100 +++ b/convergenceTable.m Mon Mar 13 14:44:31 2017 +0100 @@ -1,15 +1,15 @@ -function convergenceTable(methodName, T, orders, m, e, q, tableType) +function convergenceTable(caption, orders, m, e, q, tableType) default_arg('tableType','plaintext') switch tableType case {'plaintext','text','plain'} - plainTextTable(methodName, T, orders, m, e, q); + plainTextTable(caption, orders, m, e, q); case {'tex', 'latex'} - latexTable(methodName, T, orders, m, e, q); + latexTable(caption, orders, m, e, q); end end -function plainTextTable(methodName, T, orders, m, e, q) +function plainTextTable(caption, orders, m, e, q) eW = 0; @@ -23,7 +23,7 @@ mW = findFieldWidth('%d',m); orderHeaderWidth = eW + qW + 1; - fprintf('method: %s\nT: %d\n',methodName, T); + fprintf('%s\n',caption); % Print order headers fprintf(' %*s |',mW,'') @@ -69,7 +69,7 @@ end -function latexTable(methodName, T, orders, m, e, q) +function latexTable(caption, orders, m, e, q) nOrders = length(orders); @@ -85,7 +85,7 @@ footer = { '\end{tabular}' - '\caption{Error $l_2$, and convergence rate, $q$, for SBP operators of orders 4 and 6 at different grid densities $N$. PROBLEM DESCRIPTION.}' + ['\caption{' caption '}'] '\label{table:LABEL}' '\end{table}' };
--- a/plotConvergenceFit.m Mon Mar 13 14:43:37 2017 +0100 +++ b/plotConvergenceFit.m Mon Mar 13 14:44:31 2017 +0100 @@ -1,16 +1,45 @@ -% Draws a line in a loglog plot with slope `slope` and position `pos` -% and `width` orders of magnitude wide. -% ex: pos = [1e-1 1e-4] +% 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; -function hand = plotConvergenceFit(slope, pos, width) - x0 = pos(1); - y0 = pos(2); + logx = log(x); + logy = log(y); + + N = length(logx); + + q = 1/N*sum(logy-p*logx); - x = [x0*10^-(width/2) x0*10^(width/2)]; - y = x.^slope * x0^-slope * y0; + logxlength = xlength * abs(logx(end)-logx(1)); + logxends = (logx(1)+logx(end))/2 + [-logxlength/2, logxlength/2]; - hand = line(x,y); + xends = exp(logxends); + yends = exp(q)*xends.^p; + + hand = line(xends, yends); hand.Color = Color.black; hand.LineStyle = '--'; hand.LineWidth = 2; -end \ No newline at end of file +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 \ No newline at end of file