Loop structure for fixed point.
1 回表示 (過去 30 日間)
古いコメントを表示
Hello, I have problem with Loop structure for fixed point.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/585601/image.png)
This is the problem, and i made code like this.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/585606/image.png)
It only caculates 1 time and just stops. Which mean, it's not repeating my code, xb=x; and x=sqrt(1.8*x+2.5)
if i manually repeat xb=x; and x=sqrt(1.8*x+2.5) the answer is correct, however it's not repeating those code.
What's wrong about my loop and How to fix it?
5 件のコメント
Rik
2021 年 4 月 17 日
How large is that difference? And what is the code you're currently using? And what results are you expecting?
採用された回答
Walter Roberson
2021 年 4 月 17 日
and the correct answer when I calculated manually is 2.7424
No it is not. The correct answer is 2.71934053986603
format long g
roots([-1 1.8 2.5])
You tried the transform
-x^2 + 1.8*x + 2.5 == 0
implies 1.8*x + 2.5 == x^2
implies sqrt(1.8*x + 2.5) == sqrt(x^2)
and you deduced from that that
x == sqrt(1.8*x + 2.5)
but that is not correct. sqrt(x^2) is not x: it is abs(x) . So
abs(x) == sqrt(1.8*x + 2.5)
and you should be working both branches of that.
I suggest that you instead
-x^2 + 1.8*x + 2.5 == 0
implies 1.8*x == x^2 - 2.5
implies x == (x^2 - 2.5)/1.8
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!