finding a number that satisfies given conditions
4 ビュー (過去 30 日間)
古いコメントを表示
I need to find a floating point number x from the interval 1 < x < 2 such that: x ∗ (1/x) isn't equal to 1. I'ma beginner at Matlab and don't know how this can be done. I was given a clue that using integrals could help in solving this. Could anyone help me?
3 件のコメント
Walter Roberson
2013 年 10 月 25 日
編集済み: Walter Roberson
2013 年 10 月 25 日
Multiplication, I would say. Looks like an exercise in exploring the limits of binary floating point representation.
回答 (2 件)
Mike Hosea
2013 年 11 月 4 日
Integrals? Not sure about that. A random search will finish faster. There are LOTS. You can use LINSPACE to generate evenly spaced trial numbers, or you can us 1 + rand(1,n) to generate n random numbers between 1 and 2. Then you can check the condition using MATLAB's elementwise array operators: bool = x.*(1./x) ~= 1. Notice the .* instead of *, since * without the . is matrix multiplication. Same thing for division. Actually if you generate a boolean array that way from a set of trial numbers, you can also extract the results from your trial vector x using MATLAB's logical indexing, e.g. x(bool). Try it!
0 件のコメント
Walter Roberson
2013 年 11 月 4 日
Do a binary search over the interval realmin() to 1, to find the boundary point.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!