How do I use the for loop function?
Show older comments
I need help with this question please. How do I go about writing it out in Matlab? Thanks

4 Comments
Kevin Phung
on 28 Mar 2019
what have you tried so far?
Malath Al-Khairi
on 28 Mar 2019
Kevin Phung
on 28 Mar 2019
instead of defining conditions for y, you should check conditions for x and evaluate y
Walter Roberson
on 28 Mar 2019
You do not define y.
If you did define y, then you would have the problem that ((x.^2)./((x.^2)+1)) is a vector, and you would be comparing y to a vector. You would get a vector of logical results. When you have an vector or array of logical values in an if statement or while loop, then the condition is considered true only if all of the values are non-zero (that is, true) just as if all() had been written,
if all(y==((x.^2)./((x.^2)+1)))
If even one of those results was not true then the entire test would be considered false. It is possible that none of your three tests would be considered true, since each one of them might have some element where the test was false.
You also have the problem that you are comparing for bit-for-bit equality when you use == . If there was even a single bit difference due to round-off error, then you would get the result false. For example, due to round-off, 1/49 * 49 is not exactly 1.0
Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!