finding a number that satisfies given conditions

조회 수: 3 (최근 30일)
Beaya
Beaya 2013년 10월 25일
답변: Walter Roberson 2013년 11월 4일
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
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.
Beaya
Beaya 2013년 11월 1일
I wrote a program to do this in C, but I must have done something wrong because the result was: 4.94066e - 324, which is smaller than 1.

댓글을 달려면 로그인하십시오.

답변 (2개)

Mike Hosea
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!

Walter Roberson
Walter Roberson 2013년 11월 4일
Do a binary search over the interval realmin() to 1, to find the boundary point.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by