function S=csfit(X,Y,dx0,dxn) N=length(X)-1; H=diff(X) D=diff(Y) ./H; A=H(2:N-1)
ID: 1942067 • Letter: F
Question
function S=csfit(X,Y,dx0,dxn)
N=length(X)-1;
H=diff(X)
D=diff(Y) ./H;
A=H(2:N-1);
B=2*(H(1:N-1)+H(2:N));
C=H(2:N);
U=6*diff(D);
B(1)=B(1)-H(1)/2;
U(1)=U(1)-3*(D(1)-dx0);
B(N-1)=B(N-1)-H(N)/2;
U(N-1)=U(N-1)-3*(dxn-D(N));
for k=2:N-1
temp=A(k-1)/B(k-1);
B(k)=B(k)-temp*C(k-1);
U(k)=U(k)-temp*U(k-1);
end
M(N)=U(N-1)/B(N-1);
for k=N-2:-1:1
M(k+1)=(U(k)-C(k)*M(k+2))/B(k);
end
M(1)=3*(D(1)-dx0)/H(1)-M(2)/2;
M(N+1)=3*(dxn-D(N))/H(N)-M(N)/2;
for k=0:N-1
S(k+1,1)=(M(k+2)-M(k+1))/(6*H(k+1));
S(k+1,2)=M(k+1)/2;
S(k+1,3)=D(k+1)-H(k+1)*(2*M(k+1)+M(k+2))/6;
S(k+1,4)=Y(k+1);
end
Explanation / Answer
Yes it is. The algorithm is called "TDMA", the tridiagonal matrix algorithm. Sometimes it is called the Thomas Algorithm
Basically,
You find relationships between x(n) and x(n+1). When you get to the end, you can get an exact value for x(N), then you use the relationships you found and the exact x(N) to generate x(N-1), x(N-2) etc.
Here's a link that describes it in more detail:
http://pauli.uni-muenster.de/tp/fileadmin/lehre/NumMethoden/WS0910/ScriptPDE/Appendix.pdf
Sometimes the wording is a little odd, they go through the math fairly simply.
putting the whole derivation here would be unfeasible.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.