t=[0,0,0,0,1,2,3,3,3,4,5,6,6,6,6] t = Columns 1 through 9 0 0 0 0 1 2 3 3 3 Columns 10 through 15 4 5 6 6 6 6 xx=linspace(0,6,101); plot(xx,BSplineEval(1,4,t,xx)) plot(xx,BSplineEval(2,4,t,xx)) plot(xx,BSplineEval(3,4,t,xx)) plot(xx,BSplineEval(4,4,t,xx)) plot(xx,BSplineEval(,4,t,xx)) ??? plot(xx,BSplineEval(,4,t,xx)) | Error: Expression or statement is incorrect--possibly unbalanced (, {, or [. plot(xx,BSplineEval(5,4,t,xx)) plot(xx,BSplineEval(6,4,t,xx)) plot(xx,BSplineEval(7,4,t,xx)) plot(xx,BSplineEval(8,4,t,xx)) xx=linspace(-1,1,101); plot(xx,abs(xx).^(1/2)) xx=linspace(0,6,101); plot(xx,BSplineEval(6,4,t,xx)) uiopen('/home/accounts/personale/clrmrc90/aa1213/advanced_numerical_analysis/orderbspline.m', true); % Modify expression to add input arguments. % Example: % a = [1 2 3; 4 5 6]; % foo(a); orderbspline x = -1.0000 -1.0000 -0.7500 -0.2500 0 0 0.2500 0.7500 1.0000 1.0000 t t = -1.0000 -1.0000 -1.0000 -1.0000 -0.5000 0 0 0 0.5000 1.0000 1.0000 1.0000 1.0000 x x = -1.0000 -1.0000 -0.7500 -0.2500 0 0.2500 0.7500 1.0000 1.0000 length(x) ans = 9 length(t) ans = 13 plot(t,zeros(size(t)),'x',x,zeros(size(x)),'o') help spapi SPAPI Spline interpolation. SPAPI(KNOTS,X,Y) (with both KNOTS and X vectors) returns the spline f (if any) of order k := length(KNOTS) - length(X) with knot sequence KNOTS for which Y(:,j) equals f(X(j)) , all j. This is taken in the osculatory sense in case some data sites are repeated, i.e., in the sense that D^m(j) f(X(j)) = Y(:,j) with m(j) := #{ ispaps, spap2. Reference page in Help browser doc spapi x x = -1.0000 -1.0000 -0.7500 -0.2500 0 0.2500 0.7500 1.0000 1.0000 help spline SPLINE Cubic spline data interpolation. PP = SPLINE(X,Y) provides the piecewise polynomial form of the cubic spline interpolant to the data values Y at the data sites X, for use with the evaluator PPVAL and the spline utility UNMKPP. X must be a vector. If Y is a vector, then Y(j) is taken as the value to be matched at X(j), hence Y must be of the same length as X -- see below for an exception to this. If Y is a matrix or ND array, then Y(:,...,:,j) is taken as the value to be matched at X(j), hence the last dimension of Y must equal length(X) -- see below for an exception to this. YY = SPLINE(X,Y,XX) is the same as YY = PPVAL(SPLINE(X,Y),XX), thus providing, in YY, the values of the interpolant at XX. For information regarding the size of YY see PPVAL. Ordinarily, the not-a-knot end conditions are used. However, if Y contains two more values than X has entries, then the first and last value in Y are used as the endslopes for the cubic spline. If Y is a vector, this means: f(X) = Y(2:end-1), Df(min(X))=Y(1), Df(max(X))=Y(end). If Y is a matrix or N-D array with SIZE(Y,N) equal to LENGTH(X)+2, then f(X(j)) matches the value Y(:,...,:,j+1) for j=1:LENGTH(X), then Df(min(X)) matches Y(:,:,...:,1) and Df(max(X)) matches Y(:,:,...:,end). Example: This generates a sine-like spline curve and samples it over a finer mesh: x = 0:10; y = sin(x); xx = 0:.25:10; yy = spline(x,y,xx); plot(x,y,'o',xx,yy) Example: This illustrates the use of clamped or complete spline interpolation where end slopes are prescribed. In this example, zero slopes at the ends of an interpolant to the values of a certain distribution are enforced: x = -4:4; y = [0 .15 1.12 2.36 2.36 1.46 .49 .06 0]; cs = spline(x,[0 y 0]); xx = linspace(-4,4,101); plot(x,y,'o',xx,ppval(cs,xx),'-'); Class support for inputs x, y, xx: float: double, single See also interp1, pchip, ppval, unmkpp, mkpp, splines (The spline Toolbox). Reference page in Help browser doc spline % Modify expression to add input arguments. % Example: % a = [1 2 3; 4 5 6]; % foo(a); orderbspline % Modify expression to add input arguments. % Example: % a = [1 2 3; 4 5 6]; % foo(a); orderbspline % Modify expression to add input arguments. % Example: % a = [1 2 3; 4 5 6]; % foo(a); orderbspline % Modify expression to add input arguments. % Example: % a = [1 2 3; 4 5 6]; % foo(a); orderbspline help spapi SPAPI Spline interpolation. SPAPI(KNOTS,X,Y) (with both KNOTS and X vectors) returns the spline f (if any) of order k := length(KNOTS) - length(X) with knot sequence KNOTS for which Y(:,j) equals f(X(j)) , all j. This is taken in the osculatory sense in case some data sites are repeated, i.e., in the sense that D^m(j) f(X(j)) = Y(:,j) with m(j) := #{ ispaps, spap2. Reference page in Help browser doc spapi uiopen('/home/accounts/personale/clrmrc90/aa1213/advanced_numerical_analysis/decasteljau.m', true); t=linspace(0,1); b=[1;2] b = 1 2 t=linspace(0,1,5); t t = 0 0.2500 0.5000 0.7500 1.0000 b b = 1 2 repmat(t,2,1) ans = 0 0.2500 0.5000 0.7500 1.0000 0 0.2500 0.5000 0.7500 1.0000 repmat(b,1,5) ans = 1 1 1 1 1 2 2 2 2 2 repmat(t,2,1).*repmat(b,1,5) ans = 0 0.2500 0.5000 0.7500 1.0000 0 0.5000 1.0000 1.5000 2.0000 a{1}=rand(3); ??? Cell contents assignment to a non-cell array object. clear all a{1}=rand(3); a{2}=rand(3); a{1} ans = 0.9649 0.9572 0.1419 0.1576 0.4854 0.4218 0.9706 0.8003 0.9157 a{2} ans = 0.7922 0.0357 0.6787 0.9595 0.8491 0.7577 0.6557 0.9340 0.7431 b=[1;2] b = 1 2 t ??? Undefined function or variable 't'. t=linspace(0,1,5); b=[0,1;1;1/2] ??? Error using ==> vertcat CAT arguments dimensions are not consistent. b=[0,1;1,1/2] b = 0 1.0000 1.0000 0.5000 t t = 0 0.2500 0.5000 0.7500 1.0000 y = reshape(repmat(b,length(t),1),size(b,1),length(t)*(n+1)); Warning: Could not find an exact (case-sensitive) match for 'n'. /home/accounts/personale/clrmrc90/aa1213/advanced_numerical_analysis/N.m is a case-insensitive match and will be used instead. You can improve the performance of your code by using exact name matches and we therefore recommend that you update your usage accordingly. Alternatively, you can disable this warning using warning('off','MATLAB:dispatcher:InexactCaseMatch'). This warning will become an error in future releases. ??? Input argument "k" is undefined. Error in ==> N at 2 t = [zeros(1,k-1),linspace(0,k,k+1),k*ones(1,k-1)]; n=1 n = 1 y = reshape(repmat(b,length(t),1),size(b,1),length(t)*(n+1)); y y = Columns 1 through 5 0 0 0 0 0 1.0000 1.0000 1.0000 1.0000 1.0000 Columns 6 through 10 1.0000 1.0000 1.0000 1.0000 1.0000 0.5000 0.5000 0.5000 0.5000 0.5000 t t = 0 0.2500 0.5000 0.7500 1.0000 b=[0,1,2;1,1/2,1] b = 0 1.0000 2.0000 1.0000 0.5000 1.0000 n=2 n = 2 y = reshape(repmat(b,length(t),1),size(b,1),length(t)*(n+1)); y y = Columns 1 through 5 0 0 0 0 0 1.0000 1.0000 1.0000 1.0000 1.0000 Columns 6 through 10 1.0000 1.0000 1.0000 1.0000 1.0000 0.5000 0.5000 0.5000 0.5000 0.5000 Columns 11 through 15 2.0000 2.0000 2.0000 2.0000 2.0000 1.0000 1.0000 1.0000 1.0000 1.0000 2.0000 2.0000 2.0000 2.0000 2.0000 ??? 2.0000 2.0000 2.0000 2.0000 2.0000 | Error: Unexpected MATLAB expression. mat2cell(y,size(b,1),ones(1,size(b,2))*length(t)); y=mat2cell(y,size(b,1),ones(1,size(b,2))*length(t)); y{1} ans = 0 0 0 0 0 1 1 1 1 1 y{2} ans = 1.0000 1.0000 1.0000 1.0000 1.0000 0.5000 0.5000 0.5000 0.5000 0.5000 y{3} ans = 2 2 2 2 2 1 1 1 1 1