I get error undefined function or variable 'n' but don't show the line number.
조회 수: 1 (최근 30일)
이전 댓글 표시
function BSpline_B=Coef(n,t,y,a)
int8 i;int8 n;real p;real q;real r;real s;
a=[];h=[];t=[];y=[];
for i=1:n-1
h(i)=t(i)-t(i-1);
end
h(0)=h(1);
h(n+1)=h(n);
p=-1;
q=2*y(0);
r=p*q;
s=2;
for i=1:n
e=h(i+1)/h(i);
p=-e*p;
q=-e*q+(e+1)*y(i);
r=r+p*q;
s=s+p.^2;
end
a(0)=r./s;
for i=1:n-+1
a(i)= ((h(i-1)+h(i))*y(i-1)- (h(i)*a(i-1)))/(h(i-1));
end
end
function BSpline_B_Eval(n,t,a,h,x)
int8 i;int8 n;
real d;real e;real x;a=[];t=[];h=[];
for i=n-1:0
if x-t(i)>=0
break
end
end
i=i+1;
d=(a(i+1)*(x-t(i-1))+a(i)*(t(i)-x+h(i)))./(h(i)+h(i+1));
e= (a(i)*(x-(t(i-1)+h(i-1)))+a(i-1)*(t(i-1)-x+h(i)));
BSpline_B_Eval= (d*(x-t(i-1))+e*(t(i)-x))/h(i);
end
function BSpline_B_test()
int8 i;real e;real h;real x;
t=[];
y=[];
z=[];
n=41;
a=-1;
b=1;
q=(b-a)/n;
for i=0:n
t(i)=a+i*h;
y(i)=sin(t(i));
end
Coef(n,t,y,z)
temp=0;
for j=0:4*n
x=a+j*h/4;
e= abs(sin(x)-BSpline_B_Eval(n,t,y,z,x));
if e> temp
temp=e;
disp(j+ e+ x);
end
end
end
댓글 수: 0
채택된 답변
Star Strider
2018년 3월 29일
You have to call the function from a script, after you have defined values for all the arguments in your workspace:
n = ...;
t = ...;
y = ...;
a = ...;
BSpline_B = Coef(n,t,y,a);
You cannot run it correctly by clicking on the green Run triangle.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Splines에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!