Author Topic: what's the meaning of the code  (Read 490 times)

Offline totle

  • Newbie
  • *
  • Posts: 1
  • Matlab Forum
    • View Profile
what's the meaning of the code
« on: September 23, 2010, 04:28:31 PM »
Hi
I took a look at the function spline.m, trying to understand the algorithm for cubic hermite interpolation.
the spline.m focuses on calculating the slope of every spline function, then using the slope to calculate the coefficients of the second and third order elements. if in every interval, Si(x)=a+b(x-xi)+c(x-xi)^2+d(x-xi)^3, then the slope is b. c and d are calculated based on b (in pwch.m) .

in spline.m, I really want to understand this part of code. is there anyone who can explain it??? Thanks a lot!!!!

b=zeros(yd,n);
   b(:,2:n-1)=3*(dx(dd,2:n-1).*divdif(:,1:n-2)+dx(dd,1:n-2).*divdif(:,2:n-1));
   if isempty(endslopes)
      x31=x(3)-x(1);xn=x(n)-x(n-2);
      b(:,1)=((dx(1)+2*x31)*dx(2)*divdif(:,1)+dx(1)^2*divdif(:,2))/x31;
      b(:,n)=...
      (dx(n-1)^2*divdif(:,n-2)+(2*xn+dx(n-1))*dx(n-2)*divdif(:,n-1))/xn;
   else
      x31 = 0; xn = 0; b(:,[1 n]) = dx(dd,[2 n-2]).*endslopes;
   end
   dxt = dx(:);
   c = spdiags([ [x31;dxt(1:n-2);0] ...
        [dxt(2);2*[dxt(2:n-1)+dxt(1:n-2)];dxt(n-2)] ...
        [0;dxt(2:n-1);xn] ],[-1 0 1],n,n);

   % sparse linear equation solution for the slopes
   mmdflag = spparms('autommd');
   spparms('autommd',0);
   s=b/c;

Offline anna

  • Banned
  • *
  • Posts: 14
  • Matlab Forum
    • View Profile
Re: what's the meaning of the code
« Reply #1 on: October 16, 2010, 03:52:04 PM »
I think more time is needed. It is complicated

Matlab and SimuLink Development Forum

Re: what's the meaning of the code
« Reply #1 on: October 16, 2010, 03:52:04 PM »