# how can i get 498 matrices???

조회 수: 1(최근 30일)
youngdong jang 2020년 6월 4일
답변: VBBV 2021년 11월 29일
function y = BSSpline(x)
%Basic cubic spline function of Chapter 10, (51)
%Function built to accept vector arguments.
for i=1:length(x)
if x(i)>=0 & x(i)<=1
y(i)=((2-x(i))^3-4*(1-x(i))^3)/4;
elseif x(i)>1 & x(i)<=2
y(i)=(2-x(i))^3/4;
elseif x(i)>2
y(i)=0;
else, y(i) = BSSpline(-x(i));
end
end
n=500; h=1/(n+1);
x=linspace(0,1,n+2);
t=0:.00001:1;
for i=2:499
phi(i)=BSSpline((t-(i).*h)/h);
end
i want to get phi(2)=[ ~] , phi(3)=[ ~], .....phi(499)=[~]. my cod has error about index.

댓글을 달려면 로그인하십시오.

### 답변(2개)

n=500;
h=1/(n+1);
x=linspace(0,1,n+2);
t=0:1e-5:1;
phi = cell(size(t));
for ii=1:498
phi(ii)={BSSpline((t-(ii).*h)/h)};
end
% celldisp(phi)
function y = BSSpline(x)
%Basic cubic spline function of Chapter 10, (51)
%Function built to accept vector arguments.
y = zeros(size(x)); %preallocate
for ii=1:length(x)
if x(ii)>=0 && x(ii)<=1
y(ii)=((2-x(ii))^3-4*(1-x(ii))^3)/4;
elseif x(ii)>1 && x(ii)<=2
y(ii)=(2-x(ii))^3/4;
elseif x(ii)>2
y(ii)=0;
else, y(ii) = BSSpline(-x(ii));
end
end
end
##### 댓글 수: 0표시숨기기 이전 댓글 수: -1

댓글을 달려면 로그인하십시오.

VBBV 2021년 11월 29일
n=500; h=1/(n+1);
x=linspace(0,1,n+2);
t=0:.001:1;
for i=2:499
phi(i,:)=BSSpline((t-(i).*h)/h); % use a multidimensional array
end
plot(phi,'.')
function y = BSSpline(x)
%Basic cubic spline function of Chapter 10, (51)
%Function built to accept vector arguments.
for i=1:length(x)
if x(i)>=0 & x(i)<=1
y(i)=((2-x(i))^3-4*(1-x(i))^3)/4;
elseif x(i)>1 & x(i)<=2
y(i)=(2-x(i))^3/4;
elseif x(i)>2
y(i)=0;
else, y(i) = BSSpline(-x(i));
end
end
end
Use the cell array or mutlidimension array and plot

댓글을 달려면 로그인하십시오.

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by