下标索引必须为正整数类型或逻辑类型.什么原因啊,下面是我的程序
functionxx=chase(a,b,c,r)n=length(a);b=[0,b];%方程组中b的序号从2开始,所以前面加一项0u(1)=r(1)/a(1);v(1...
function xx=chase(a,b,c,r)
n=length(a);
b=[0,b];%方程组中b的序号从2开始,所以前面加一项0
u(1)=r(1)/a(1);
v(1)=c(1)/a(1);
for i=2:n-1
u(i)=(r(i)-b(i)*u(i-1))/(a(i)-b(i)*v(i-1));
v(i)=c(i)/(a(i)-v(i-1)*b(i));
end
u(n)=(r(n)-b(n)*u(n-1))/(a(n)-b(n)*v(n-1));
%用赶法计算xx
xx(n)=u(n);
for i=n-1:-1:1
xx(i)=u(i)-v(i)*xx(i+1);
end
主程序:clear
a=[2,3,4,5];b=[-1,-2,-3];c=b;
r=[6,1,-2,1];
xx=[0,0,0,0];
xx=chase(a,b,c,r) 展开
n=length(a);
b=[0,b];%方程组中b的序号从2开始,所以前面加一项0
u(1)=r(1)/a(1);
v(1)=c(1)/a(1);
for i=2:n-1
u(i)=(r(i)-b(i)*u(i-1))/(a(i)-b(i)*v(i-1));
v(i)=c(i)/(a(i)-v(i-1)*b(i));
end
u(n)=(r(n)-b(n)*u(n-1))/(a(n)-b(n)*v(n-1));
%用赶法计算xx
xx(n)=u(n);
for i=n-1:-1:1
xx(i)=u(i)-v(i)*xx(i+1);
end
主程序:clear
a=[2,3,4,5];b=[-1,-2,-3];c=b;
r=[6,1,-2,1];
xx=[0,0,0,0];
xx=chase(a,b,c,r) 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询