• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Apr 24th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. function yi = SplineC2natural(x, y, xi)
2.     n = length(x);
3.     for i=1:n
4.         a(i)=y(i);
5.         if(i < n)
6.             h(i)=x(i+1)-x(i);
7.         endif
8.     endfor
9.
10.     A = zeros(n, n);
11.
12.     for i=2:n-1
13.         A(i,i-1) = h(i-1);
14.         A(i,i) = 2*(h(i-1)+h(i));
15.         A(i,i+1) = h(i);
16.     endfor
17.
18.     A(1,1) = 1;
19.     A(n+1, n) = 1;
20.
21.     B = zeros(n+1,1);
22.
23.     for i=2:n-2
24.         B(i)=3*(a(i+1)-a(i))/h(i) - 3*(a(i) - a(i-1))/h(i-1);
25.     endfor
26.
27.     c = A\B;
28.
29.     length(c)
30.     length(a)
31.     length(h)
32.
33.     for i=1:n-1
34.         b(i) = (a(i+1)-a(i))/h(i) - h(i)/3*(2*c(i) + c(i+1));
35.         d(i)=(c(i+1)-c(i))/(3*h(i));
36.     endfor
37.
38.     for i=1:n-1
39.     if (xi >= x(i) && xi <= x(i+1))
40.     yi =a(i)+b(i)*(xi-x(i))+c(i)*(xi-x(i))^2+d(i)*(xi-x(i))^3;
41.     endif
42.     endfor
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.

Top