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

采纳的回答

Star Strider
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 个)

类别

Help CenterFile Exchange 中查找有关 Splines 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by