Previous Article Next Article MATLAB Help – Linear Splines
Posted in MATLAB

MATLAB Help – Linear Splines

1 comment

  1. X=(-10:2:10)';
    Y=sign(X);
    plot(X,Y,'b*')
    0=7;
    H=ones(lenght(X),0+1);
    for idx=2:(0+1)
    H(:,idx)=X.^(idx-1);
    end
    Astar=inv(H'*H)*H'*Y;
    Xsmooth=linspace(X(1),X(end),100);
    Hs=ones(lenght(Xsmooth),0+1);
    for idx=2:(0+1)
    Hs(:,idx)=Xsmooth.^(idx-1);
    end
    Ytilde=Hs*Astar;
    hold on
    plot(Xsmooth,Ytilde,'r-')
    for idx=1:lenght(X)-1
    m=(Y(idx+1)-Y(idx))/(X/idx+1)-X(idx));
    xspline=linspace(X(idx),X(idx+1),10);
    yspline=m*(xspline-X(idx))+Y(idx);
    plot(xspline-yspline,'g-')
    end

    this code is isnt working in my matlab2015a. What is the problem ? Can you help?

Leave a Reply

Your email address will not be published. Required fields are marked *