Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. clear all
  2. P = [1 0;1 1;0 1];
  3. w = [1 1 1];
  4. w2 = [1 1 0.5];
  5.  
  6. t=[0:0.01:1];
  7. %hyperbole
  8. x=(1-(t.^2));
  9. y=t;
  10. %plot(x,y,'Color',"blue");
  11.  
  12. hold on
  13. for i = 1:1:length(P)
  14. plot(P(i,1),P(i,2),'O');
  15. end
  16. hold off
  17. bases_rationelles(P,w,100,'O');
  18. %bases_rationelles(P,w2,100,'.');
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25. function nb = Binomial(n,k)
  26. nb = factorial(n)/(factorial(k)*factorial(n-k));
  27. end
  28.  
  29. %exists function "bernstein" which does almost the same thing
  30. function polynome = Bernstein(i,n,t)
  31.  
  32. for j = 1:1:length(t)
  33. polynome(1,j) = (Binomial(n,i))*((t(1,j))^i)*((1-(t(1,j)))^(n-i));
  34. end
  35. end
  36.  
  37. function polynome = Rational(i,n,w,t)
  38. tmp = zeros(1,length(t));
  39. for j = 1:1:n
  40. tmp = tmp + w(j) * Bernstein(j-1,n-1,t);
  41. end
  42. polynome = (w(i)*Bernstein(i-1,n-1,t))./tmp;
  43. end
  44.  
  45. function courbe = bases_rationelles(P,w,nb,forme)
  46. t = linspace(0,1,nb);
  47. n = length(P);
  48. courbeX = zeros(1,length(t));
  49. courbeY = zeros(1,length(t));
  50.  
  51. for i = 1:1:n
  52. courbeX = courbeX + (P(i,1) * Rational(i,n,w,t));
  53. courbeY = courbeY + (P(i,2) * Rational(i,n,w,t));
  54. end
  55. courbe = [courbeX;courbeY];
  56. hold on
  57. for i = 1:1:length(courbe)
  58. plot(courbe(1,i),courbe(2,i),forme);
  59. end
  60. hold off
  61. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement