Cody

Problem 43553. Linear Least Squares (L2 fitting problem )

Given a set of real measurements

     (x(i), y(i))

find a line sol(1)x + sol(2) (more specifically furnish the vector with sol=[sol(1),sol(2)])such that it fits the data (it minimises the 2 norm)

Example: Input:

% INPUT
x=linspace(0,1,50);
y=4*x-1+ randn(50,1); % perturbed observations
% SOLUTION:
sol=[4,-1]

HINT : This problem can be expressed as a convex optimisation problem:

min_{sol} sum(sol(1)*x+sol(2)-y)^2   

Suggestion: use the following code to test your function:

plot(x,y,'.') % plot the data
hold on
plot(x,sol(1)*x+sol(2))
legend('measurements', 'L2 fit')

Solution Stats

52.94% Correct | 47.06% Incorrect
Last solution submitted on Mar 18, 2019

Problem Comments