0

私はプログラムを実行しましたが、何らかの理由でそれは間違い ( c = tridiagonal ( hi(1:n-1), dd, hi(1:n-1), ri );) であり、理由がわかりません。正しいと確信しているので、誰か助けてください。コードは次のとおりです。

function csc = cubic_clamped ( xi, fi, fpa, fpb )n = length ( xi );        
m = length ( fi );        
if ( n ~= m )
   disp ( 'number of ordinates and number of function values must be equal' )          
   return         
end        
for i = 1 : n-1         
    hi(i) = xi(i+1) - xi(i);         
end          
dd(1) = 2.0*hi(1);  dd(n) = 2.0*hi(n-1);                  
ri(1) = (3.0/hi(1))*(fi(2)-fi(1)) - 3.0 * fpa;        
ri(n) = 3.0 * fpb - (3.0/hi(n-1))*(fi(n)-fi(n-1));        
for i = 1 : n-2        
    dd(i+1) = 2.0 * ( hi(i) + hi(i+1) );        
    ri(i+1) = (3.0/hi(i+1))*(fi(i+2)-fi(i+1))-(3.0/hi(i))*(fi(i+1)-fi(i));        
end          
disp ( [dd' ri'] )        
c = tridiagonal ( hi(1:n-1), dd, hi(1:n-1), ri );          
d = zeros ( n,1 );        
b = d;          
for i = 1 : n-1        
    d(i) = (c(i+1)-c(i))/(3.0*hi(i));        
    b(i) = (fi(i+1)-fi(i))/hi(i) - hi(i)*(c(i+1)+2.0*c(i))/3.0;        
end          
if ( nargout == 0 )        
   disp ( [ xi' fi' b c' d ] )        
else        
   csc = [ xi' fi' b c' d ];        
end      

三重対角コード (エラー: w = a(i) - b(i)*v(i-1); )

function y = tridiagonal( a, b, c, f )            
n = length(f);        
v = zeros(n,1);        
y = v;        
w = a(1);        
y(1) = f(1)/w;        
for i=2:n        
    v(i-1) = c(i-1)/w;        
    w = a(i) - b(i)*v(i-1);        
    y(i) = ( f(i) - b(i)*y(i-1) )/w;        
end        
for j=n-1:-1:1        
   y(j) = y(j) - v(j)*y(j+1);        
end        
4

0 に答える 0