code to implement continuous least square
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Dinesh Yadav
le 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 commentaires
Voir également
Catégories
En savoir plus sur Polynomials dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!