MATLAB Answers

code to implement continuous least square

39 views (last 30 days)
sam2021
sam2021 on 28 Feb 2020
Answered: Dinesh Yadav on 2 Mar 2020
Write Matlab code to implement the continuous least squares method of finding the best-fit polynomial of degree n for a given function f on the interval [a, b]. Again, you may not use the Matlab command polyfit or anything similar. Populate a matrix and vector and solve the resulting matrix-vector equation. Once you have solved the matrix-vector equation, you may then use the polyval function. The inputs should be contained in a Matlab function file called clsin.m, which should contain, for example,
function [n f a b] = clsin()
syms x;
n = 5;
f = sqrt(x);
a = 0;
b = 1;
end
In this example, we are trying to fit a polynomial of degree 5 to the function f(x) = x on the interval [0,1]. Your output should be a picture, showing both the original function f and its least squares polynomial approximation, both only on the interval [a, b]. The Matlab command fplot (in the symbolic toolbox) may prove to be handy.
I am really struggling with this problem. We cannot use polyfit or anything similar. Any help on this problem would be appreciated.

  0 Comments

Sign in to comment.

Answers (1)

Dinesh Yadav
Dinesh Yadav on 2 Mar 2020
Hi,
Kindly go through the following doc on methods to solve linear least squares problem using matlab without using polyfit.
Hope it helps.

  0 Comments

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!