code to implement continuous least square

7 次查看(过去 30 天)
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.

回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by