Problem 258. linear least squares fitting
Inputs:
- f: cell-array of function handles
- x: column vector of x values
- y: column vector of y values, same length as x
Output:
- a: column vector of coefficients, same length as f
In a correct answer the coefficients a take values such that the function
fit = @(x) a(1)*f{1}(x) + a(2)*f{2}(x) + a(3)*f{3}(x) +...+ a(end)*f{end}(x)
minimizes the sum of the squared deviations between fit(x) and y, i.e. sum((fit(x)-y).^2) is minimal.
Remarks:
- The functions will all be vectorized, so e.g. f{1}(x) will return results for the whole vector x
- The absolute errors of a must be smaller than 1e-6 to pass the tests
Solution Stats
Problem Comments
-
6 Comments
Show
3 older comments
Alfonso Nieto-Castanon
on 10 Jan 2013
and nice problem, by the way!
Tomasz
on 10 Jan 2013
Thanks! Nice catch, I fixed that second issue too (those randomized tests have their drawbacks)
Tikay
on 26 Oct 2020
Sorry, but I can not understand the problem to solve.
Can anyone explain to me, please?
Solution Comments
Show commentsGroup

Sequences & Series I
- 14 Problems
- 87 Finishers
- Sum all integers from 1 to 2^n
- Integer sequence - 2 : Kolakoski sequence
- Sum all integers from 1 to 2^n
- Project Euler: Problem 2, Sum of even Fibonacci
- Sum of first n terms of a harmonic progression
- Project Euler: Problem 6, Natural numbers, squares and sums.
- Integer Sequence - II : New Fibonacci
- Project Euler: Problem 2, Sum of even Fibonacci
- Project Euler: Problem 6, Natural numbers, squares and sums.
- Find the stride of the longest skip sequence
- Sum the Infinite Series
- Return the Fibonacci Sequence
- Sum of first n terms of a harmonic progression
- "Look and say" sequence
- Is X a Fibonacci Matrix?
- Square Digits Number Chain Terminal Value (Inspired by Project Euler Problem 92)
- Golomb's self-describing sequence (based on Euler 341)
- Alternating sum
- Integer sequence - 2 : Kolakoski sequence
- Integer Sequence - II : New Fibonacci
Problem Recent Solvers109
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!