Skip to content

Commit a49bfa0

Browse files
committed
Small fixes to lsquare_plot_with_qr
Fix typo in a comment, change assert error message to be more consistent, fix potential bug with plot_step validation, and rename ambigious variable names for better reading.
1 parent aea4ee0 commit a49bfa0

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

lsquare_plot_with_qr.m

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function [x] = lsquare_plot_with_qr(t, y, basis, plot_step)
2-
% LSQUARE_PLOT_WITH_QR solve Ax = y for x in the least-square sense and
3-
% plot the least-square fit using QR decomposition.
2+
% LSQUARE_PLOT_WITH_QR Solves Ax = y for x in the least-square sense and
3+
% plots the least-square fit using QR decomposition.
44
%
55
% INPUT
66
% t & y: m paired input cordinates
@@ -15,10 +15,10 @@
1515
% validate and possibly default input
1616
m = length(t);
1717
assert(m > 0, 'length of t must be > 0')
18-
assert(length(y) == m, 'length of y should be same as t')
18+
assert(length(y) == m, 'length of y must be same as t')
1919
n = length(basis);
2020
assert(n > 0, 'length of basis must be > 0')
21-
if nargin == 3 || plot_step == 0
21+
if nargin == 3 || plot_step <= 0
2222
plot_step = 0.01;
2323
end
2424

@@ -47,16 +47,16 @@
4747
end
4848

4949
% make the curve from basis functions
50-
numbers = min(t) : plot_step:max(t);
51-
curve = x(1) * basis{1}(numbers);
50+
lsquare_x = min(t) : plot_step:max(t);
51+
lsquare_y = x(1) * basis{1}(lsquare_x);
5252
for i = 2 : n
53-
curve = curve + x(i) * basis{i}(numbers);
53+
lsquare_y = lsquare_y + x(i) * basis{i}(lsquare_x);
5454
end
5555

5656
% plot the given data points and the curve
5757
scatter(t,y);
5858
hold on
59-
plot(numbers,curve);
59+
plot(lsquare_x,lsquare_y);
6060
hold off
6161

6262
end

0 commit comments

Comments
 (0)