matlab 解多元一次方程组
X1=1000+X2/2X2=X1+X3/2X3=X2+X4/2X4=X3+X5/2X5=X4+X6/2X6=X5+X7/2X7=X6+X8/2X8=X7+X9/2X9=...
X1=1000+X2/2 X2=X1+X3/2 X3=X2+X4/2 X4=X3+X5/2
X5=X4+X6/2 X6=X5+X7/2 X7=X6+X8/2 X8=X7+X9/2
X9=X8+X10/2 X10=X9+X11/2 X11=X10+X12/2 X12=X11+X13/2
X13=X12+X14/2 X14=X13+X15/2 X15=X14+X16/2 X16=X15+X17/2
X17=X16+X18/2 X18=X17+X19/2 X19=X18+X20/2 X20=X19+X21/2
X21=X20=X17/2
clear a b c d e f g h i j k l m n o p q r s t ;
[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t]=solve('a=1000+b/2','b=a+c/2','c=b+d/2','d=c+e/2','e=d+f/2','f=e+g/2','g=f+h/2','h=g+i/2','j=h+j/2','j=i+k/2','k=j+l/2','l=k+m/2','m=l+n/2','n=m+o/2','o=n+p/2','p=o+q/2','q=p+r/2','r=q+s/2','s=r+t/2','t=s+u/2','u=t+q/2','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t')
我编的程序算不出来结果
Error using ==> solve
Error, (in solve) a constant is invalid as a variable, (-1)^(1/2)
错误 求解决!! 展开
X5=X4+X6/2 X6=X5+X7/2 X7=X6+X8/2 X8=X7+X9/2
X9=X8+X10/2 X10=X9+X11/2 X11=X10+X12/2 X12=X11+X13/2
X13=X12+X14/2 X14=X13+X15/2 X15=X14+X16/2 X16=X15+X17/2
X17=X16+X18/2 X18=X17+X19/2 X19=X18+X20/2 X20=X19+X21/2
X21=X20=X17/2
clear a b c d e f g h i j k l m n o p q r s t ;
[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t]=solve('a=1000+b/2','b=a+c/2','c=b+d/2','d=c+e/2','e=d+f/2','f=e+g/2','g=f+h/2','h=g+i/2','j=h+j/2','j=i+k/2','k=j+l/2','l=k+m/2','m=l+n/2','n=m+o/2','o=n+p/2','p=o+q/2','q=p+r/2','r=q+s/2','s=r+t/2','t=s+u/2','u=t+q/2','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t')
我编的程序算不出来结果
Error using ==> solve
Error, (in solve) a constant is invalid as a variable, (-1)^(1/2)
错误 求解决!! 展开
1个回答
展开全部
clc;clear
A=zeros(21,21);
A(1,[1 2])=[1 -1/2];
for i=2:20
A(i,[i-1,i,i+1])=[1,-1,1/2];
end
A(21,[17,21])=[1/2,-1];
b=zeros(21,1);
b(1)=1000;
x=A\b;
求解得:
x =
0
-2000
-4000
-4000
0
8000
16000
16000
0
-32000
-64000
-64000
0
128000
256000
256000
0
-512000
-1024000
-1024000
0
注:最后一个等式是不是X21=X17/2
你写错了吧
不过看到你的程序好像是X21=X20+X17/2是吗,如果是
A(21,[17,21])=[1/2,-1];改成A(21,[17,,20,21])=[1/2,1,-1];
结果就是
x =
1.0e+006 *
0.000888888888889
-0.000222222222222
-0.002222222222222
-0.004000000000000
-0.003555555555556
0.000888888888889
0.008888888888889
0.016000000000000
0.014222222222222
-0.003555555555556
-0.035555555555556
-0.064000000000000
-0.056888888888889
0.014222222222222
0.142222222222222
0.256000000000000
0.227555555555556
-0.056888888888889
-0.568888888888889
-1.024000000000000
-0.910222222222222
A=zeros(21,21);
A(1,[1 2])=[1 -1/2];
for i=2:20
A(i,[i-1,i,i+1])=[1,-1,1/2];
end
A(21,[17,21])=[1/2,-1];
b=zeros(21,1);
b(1)=1000;
x=A\b;
求解得:
x =
0
-2000
-4000
-4000
0
8000
16000
16000
0
-32000
-64000
-64000
0
128000
256000
256000
0
-512000
-1024000
-1024000
0
注:最后一个等式是不是X21=X17/2
你写错了吧
不过看到你的程序好像是X21=X20+X17/2是吗,如果是
A(21,[17,21])=[1/2,-1];改成A(21,[17,,20,21])=[1/2,1,-1];
结果就是
x =
1.0e+006 *
0.000888888888889
-0.000222222222222
-0.002222222222222
-0.004000000000000
-0.003555555555556
0.000888888888889
0.008888888888889
0.016000000000000
0.014222222222222
-0.003555555555556
-0.035555555555556
-0.064000000000000
-0.056888888888889
0.014222222222222
0.142222222222222
0.256000000000000
0.227555555555556
-0.056888888888889
-0.568888888888889
-1.024000000000000
-0.910222222222222
追问
X21=X20+X17/2 这个是对的 麻烦您能受累写下结果么 明天交报告了 谢了!!! 加分!
追答
A=zeros(21,21);
A(1,[1 2])=[1 -1/2];
for i=2:20
A(i,[i-1,i,i+1])=[1,-1,1/2];
end
A(21,[17,20,21])=[1/2,1,-1];
b=zeros(21,1);
b(1)=1000;
x=A\b;
运行结果
x =
1.0e+006 *
0.000888888888889
-0.000222222222222
-0.002222222222222
-0.004000000000000
-0.003555555555556
0.000888888888889
0.008888888888889
0.016000000000000
0.014222222222222
-0.003555555555556
-0.035555555555556
-0.064000000000000
-0.056888888888889
0.014222222222222
0.142222222222222
0.256000000000000
0.227555555555556
-0.056888888888889
-0.568888888888889
-1.024000000000000
-0.910222222222222
你可以验算一下,应该没错了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询