code to implement continuous least square

조회 수: 3 (최근 30일)
sam2021
sam2021 2020년 2월 28일
답변: Dinesh Yadav 2020년 3월 2일
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에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by