How do i get aproximation of a function?
1 visualizzazione (ultimi 30 giorni)
I have the following function :
f (t) = 0.05*sin(1000*t)+0.5*cos(pi*t)-0.4*(10*t)
t are points distributed equidistantly between [0,1] for which i calculate values of f .
The following pairs (ti,f(ti)) are inputs for aproximation of function f with Lagrange and Least Squares.
This is what i tried, but doesn't seem to work, because i'm not sure if i'm doing f right
f = 0.05*sin(1000*t)+0.5*cos(pi*t)-0.4*sin(10*t);
lagrange(t,f); % returns coeficients of Lagrange polynomial of rank 1
least_squares(t,f) % returns coeficients of polynomial of rank n using least squares method
This is the lagrange function:
function[L] = lagrange(x,y)
n = length(x);
mr=jr(jr~=j);%m-range 1<=m<=n, m~=j
And the least_squares function:
function [yR] =least_squares(x,y)
Gargi Patil il 15 Apr 2021
You can refer to the following thread for function approximation which includes a least squares method approach as well as Lagrange approximation:
You can also refer to the following link for other ways to approximate a function: