Loop structure for fixed point.
显示 更早的评论
Hello, I have problem with Loop structure for fixed point.

This is the problem, and i made code like this.

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-16
Please post your code as code. Also, why haven't you tried stepping through your code line by line to see what the variables are?
You can find guidelines for posting homework on this forum here. If you have trouble with Matlab basics you may consider doing the Onramp tutorial (which is provided for free by Mathworks). If your main issue is with understanding the underlying concept, you may consider re-reading the material you teacher provided and ask them for further clarification.
I hope @VBBV will not actually do as you ask and provide a working solution. If you hand that in as your own work you would be commiting academic fraud. Asking for help is fine, asking for solutions isn't.
Your question is asking for help, the comment you wrote was asking for a solution. I was not claiming you were doing something nefarious, I was simply pointing you to helpful guidelines and to a tutorial.
If you had actually stepped through your code, you would have realised the values of your variables:
x0=5;
x=sqrt(1.8*x0+2.5);
xb=x;
x=sqrt(1.8*x+2.5);
disp((x-xb)/x)
The solution to your problem is that you probably want to look at the absolute value of the error term.
Rik
2021-4-17
How large is that difference? And what is the code you're currently using? And what results are you expecting?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!