Advertisement
Debml

gaby

Apr 8th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. function[ybp]=JLCSplines(x,y,ypL,ypR)
  2. // Function to calculate clamped cubic splines
  3. // Detailed explanation goes here
  4. // x independient variable
  5. // y dependient variable
  6. // ypL = dy/dx in the left side i.e. x = xmin
  7. // ypR = dy/dx in the right side, i.e. x = xmax
  8. // ybp = d ( dy/dx )/dx = Second derivative
  9.  
  10. [m,nL]=size(x);
  11. if m>nL then
  12. ngg=m
  13. else
  14. ngg=nL
  15. end
  16.  
  17. N=ngg-1;
  18.  
  19. for i=1:N
  20. h(i)=x(i+1)-x(i);
  21. end
  22.  
  23. a(N+1)=h(N)/6.0;
  24. b(N+1)=h(N)/2.0-h(N)/6.0;
  25. c(N+1)=0.0;
  26. b(1)=h(1)/2.0-h(1)/6.0;
  27. c(1)=h(1)/6.0;
  28. a(1)=0.0;
  29.  
  30. for i=1:N-1
  31. a(i+1)=h(i)/6.0;
  32. b(i+1)=(h(i)+h(i+1))/2.0-(h(i)+h(i+1))/6.0;
  33. c(i+1)=h(i+1)/6.0;
  34. r(i+1)=(y(i+2)-y(i+1))/h(i+1)-(y(i+1)-y(i))/h(i);
  35. end
  36.  
  37. r(1)=(y(2)-y(1))/h(1)-ypL;
  38. r(N+1)=ypR-(y(N+1)-y(N))/h(N);
  39. aa=a';bb=b';cc=c';rr=r';
  40. ybp=JLTridiag(aa,bb,cc,rr);
  41.  
  42. yp = (ypL+ypR)/2;
  43.  
  44. kappa=-ybp/(1+(yp)^2)^(3/2);
  45.  
  46. R = 1/kappa;
  47.  
  48. endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement