Mercurial > repos > public > sbplib
comparison plotConvergenceFit.m @ 440:0ef8965dd745
Improve inteface and functionality of plotConvergence()
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 13 Mar 2017 14:40:14 +0100 |
parents | 4fcc4448682f |
children |
comparison
equal
deleted
inserted
replaced
439:2663be328d9a | 440:0ef8965dd745 |
---|---|
1 % Draws a line in a loglog plot with slope `slope` and position `pos` | 1 % Draws a line in a loglog plot with slope `slope` fitted to the data in `x` |
2 % and `width` orders of magnitude wide. | 2 % and `y`. `xlength` scales how much of the interval [x(1) x(end)] is coverd |
3 % ex: pos = [1e-1 1e-4] | 3 % by the line. `offset` is a multiplicative offset to where the line is drawn |
4 % relative to the data. | |
5 function hand = plotConvergenceFit(slope, x, y, xlength, offset) | |
6 default_arg('xlength', 0.8) | |
7 default_arg('offset', 1); | |
4 | 8 |
5 function hand = plotConvergenceFit(slope, pos, width) | 9 % Optimise for log(y) = p*log(x) + q |
6 x0 = pos(1); | |
7 y0 = pos(2); | |
8 | 10 |
9 x = [x0*10^-(width/2) x0*10^(width/2)]; | 11 p = slope; |
10 y = x.^slope * x0^-slope * y0; | |
11 | 12 |
12 hand = line(x,y); | 13 logx = log(x); |
14 logy = log(y); | |
15 | |
16 N = length(logx); | |
17 | |
18 q = 1/N*sum(logy-p*logx); | |
19 | |
20 logxlength = xlength * abs(logx(end)-logx(1)); | |
21 logxends = (logx(1)+logx(end))/2 + [-logxlength/2, logxlength/2]; | |
22 | |
23 xends = exp(logxends); | |
24 yends = exp(q)*xends.^p; | |
25 | |
26 hand = line(xends, yends); | |
13 hand.Color = Color.black; | 27 hand.Color = Color.black; |
14 hand.LineStyle = '--'; | 28 hand.LineStyle = '--'; |
15 hand.LineWidth = 2; | 29 hand.LineWidth = 2; |
16 end | 30 end |
31 | |
32 | |
33 | |
34 % function hand = plotConvergenceFit(slope, pos, width) | |
35 % x0 = pos(1); | |
36 % y0 = pos(2); | |
37 | |
38 % x = [x0*10^-(width/2) x0*10^(width/2)]; | |
39 % y = x.^slope * x0^-slope * y0; | |
40 | |
41 % hand = line(x,y); | |
42 % hand.Color = Color.black; | |
43 % hand.LineStyle = '--'; | |
44 % hand.LineWidth = 2; | |
45 % end |