mathlab数学实验题编程判断函数f(x)=(x-1)/(x+1) 的迭代序列是否收敛.
2019-04-13
mathlab数学实验题编程判断函数f(x)=(x-1)/(x+1) 的迭代序列是否收敛.
优质解答
count = 0;
flag1 = 0;
flag2 = 0;
x = 2;
while(1)
y = x+1;
if ((x-1)/(x+1) == (y-1)/(y+1))
count = count + 1;
end
if((count = 0) & ((x-1)/(x+1) = (y-1)/(y+1)))
count = 0;
end
if(count == 5)
flag1 = 1;
break;
end
x = x*2;
end
x = -2;
while(1)
y = x-1;
if ((x-1)/(x+1) == (y-1)/(y+1))
count = count +1;
end
if((count = 0) & ((x-1)/(x+1) = (y-1)/(y+1)))
count = 0;
end
if(count == 10)
flag2 = 1;
break;
end
x = x*2;
end
最后在看一下flag1和flag2的值,如果为1,则说明收敛!(前者表示像正无穷方向收敛,后者像负无穷方向)
count = 0;
flag1 = 0;
flag2 = 0;
x = 2;
while(1)
y = x+1;
if ((x-1)/(x+1) == (y-1)/(y+1))
count = count + 1;
end
if((count = 0) & ((x-1)/(x+1) = (y-1)/(y+1)))
count = 0;
end
if(count == 5)
flag1 = 1;
break;
end
x = x*2;
end
x = -2;
while(1)
y = x-1;
if ((x-1)/(x+1) == (y-1)/(y+1))
count = count +1;
end
if((count = 0) & ((x-1)/(x+1) = (y-1)/(y+1)))
count = 0;
end
if(count == 10)
flag2 = 1;
break;
end
x = x*2;
end
最后在看一下flag1和flag2的值,如果为1,则说明收敛!(前者表示像正无穷方向收敛,后者像负无穷方向)