daily pastebin goal
55%
SHARE
TWEET

Untitled

a guest Feb 13th, 2018 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function [c, flag]= approx(f,a,b,n,m)
  2. %create a vector for x data
  3. xdata=[];
  4. for j=0:m
  5.      xdata=[xdata,(a+(b-a)*j/m)];
  6. end
  7.  
  8. V=[];
  9. p=0;
  10. %create a Vandermore matrix by putting x data into the poewr of n
  11. for i=1:n+1
  12.  
  13.     V(:,i)=xdata.^(p);
  14.     p=p+1;
  15. end
  16. %find out y data
  17. ydata=feval(f,xdata);
  18. g=[ydata]';
  19. %conduct QR factorization
  20. [Q,R]=qr(V);
  21. %check whether the matrix is full rank and if not do not
  22. %compute c
  23. if ((rank(R) == size(R,1))||(rank(R) == size(R,2)))
  24.     c=[];
  25.     c=R(Q'*g);
  26.     flag=0;
  27. else
  28.     flag=1;
  29. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top