Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- approx_func_plot(5,3);
- approx_func_plot(5,5);
- approx_func_plot(5,10);
- approx_func_plot(5,20);
- function [Fi] = approx_func_plot(n,k)
- Fi = zeros(n,k);
- f = @(x) sqrt(1-x^2)*exp(x);
- for i=1:n
- x(i) = -1 + 2*(i-1)/(n-1);
- y(i) = f(x(i));
- end
- for i=1:k
- xk(i) = -1 + 2*(i-1)/(k-1);
- end
- for j=1:k
- for i=1:n
- Fi(i,j) = sinc(x(i) - xk(j));
- end
- end
- y = y';
- A = Fi'*Fi;
- b = Fi'*y;
- p = A\b;
- x = linspace(-1,1,100);
- for i=1:100
- y_100(i) = f(x(i));
- end
- tmp2 = 0;
- for i=1:100 % CREATING APPROX FUNCTION OUTOUT
- for j=1:k
- tmp = p(j)*sinc(x(i)-xk(j));
- tmp2 = tmp2 + tmp;
- end
- fapp(i) = tmp2;
- tmp2 = 0;
- end
- f4 = figure;
- figure(f4);
- plot(x,fapp, x, y_100);
- legend('approximated', 'real function');
- title(['Approximated function for n= ' num2str(n) ' k= ' num2str(k)]);
- xlabel('x');
- ylabel('y');
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement