Solve, floor(x/B)+1=L, for x, where B & L are constants & is a variable?

  • Thread starter Thread starter GreenPrint
  • Start date Start date
  • Tags Tags
    Constants Variable
GreenPrint
Messages
1,186
Reaction score
0
Solve, floor(x/B)+1=L, for x, where B & L are constants & is a variable?

Homework Statement



I'm trying to solve this for x

floor(x/B)+1=L

where
x is a variable
B and L are just some constants

Homework Equations


The Attempt at a Solution


I have no idea were to go after this
floor(x/B)=L-1
I don't know how to solve this further because I don't know what the inverse of the floor function is.

Thanks for any help!
 
Physics news on Phys.org


Hi GreenPrint! :smile:

The floor function does not have an inverse since it is not injective. So we will find multiple solutions (or none if L is not an integer).

In general, we know that floor(x)=y if and only if y is an integer such that

y\leq x<y+1

So we know that floor(x/B)=L-1 if and only if L is an integer such that

L-1\leq \frac{x}{B}<L

Can you go from here?
 


Well see the reason why I asked this question was because I was trying to solve a problem for this course that I'm taking in which I'm trying to learn how to use MATLAB. This question came up because I was confused by the math that was required to solve the question. Basically I'm trying to create a conversion table from degrees Celsius to degrees Rankine were the user inputs the starting temperature in degrees Celsius and the increments at which degrees Celsius is increased by from row to row.

"Generate a table of conversions from Celsius to Rankine. Allow the user to enter the stating temperature and the increment between lines. Print 25 lines in the table. Use disp and fprintf to create a table with a title, column headings, and appropriate spacing."

disp('The table about to be generated is a degrees Celsius to degrees Rankine conversion table, and will contain 25 lines.')
A=input('At which starting temperature, in degrees Celsius, would you like the table to start at?');
B=input('At what increment would you like the degrees Celsius to be displayed?');
table=[A:B:?;C_to_R(A:B:?)];
disp('degrees C to degrees R')
disp('degrees C degrees R')
fprintf('%4.2f %12.2f\n',table)

and I was having trouble coming up with what to place in the question marks. Note that C_to_R is a function I created in a earlier problem were the user inputs value(s) in degrees Celsius to convert them to degrees Rankine. Note that the notation "A:B:?" is nothing more than a series of values were A is the starting point, B is the increments at which to increase between each value after A, and ? is the ending point at which MATLAB doesn't list values past.

Hence 0:2:10 yields
0 2 4 6 8 10

and the equation I came up with if we let the three values be A:B:C and L the number of lines desired, was
C/B + 1 = L

hence
0:2:10 would yield 6 values because
C=10
B=2
10/2 + 1 = 5 + 1 = 6

I however realized that
C/B + 1 = L
didn't work on all occasions when C/B didn't produce a whole number and that the proper equation was actually
floor(C/B) + 1 = L
which works every single time
I'm just lost as how to solve for C and sense it's a value that I have to enter and not the user of the program I'm making I have to some how come up with the value myself given the number of lines, this case L=25, the starting value A, and the increments at which to increase B... but A really is irrelevant

hence I'm stuck because a range of values is the yielded answer when solving
floor(C/B)+1=25
sense were given L=25
 


I guess I could just let
C=24*B+.00000000001
 


There will be multiple values for C that work. Let's see if I can help you find them.

You know that floor(C/B)+1=25, thus floor(C/B)=24. This means that

24\leq C/B<25

What must hold for C now?
 


*reading above post*
 


it would be
24*B <= C < B*25
 


Indeed, so won't C=24B work?
 


Nope =(
24*B
if B = 5
24*5=120
I only get 24 results and not 25. Maybe my equation was wrong but I thought it was correct. floor(C/B) + 1 = L

4:5:120

ans =

Columns 1 through 19

4 9 14 19 24 29 34 39 44 49 54 59 64 69 74 79 84 89 94

Columns 20 through 24

99 104 109 114 119
 
  • #10


GreenPrint said:
Nope =(
24*B
if B = 5
24*5=120
I only get 24 results and not 25. Maybe my equation was wrong but I thought it was correct. floor(C/B) + 1 = L

4:5:120

ans =

Columns 1 through 19

4 9 14 19 24 29 34 39 44 49 54 59 64 69 74 79 84 89 94

Columns 20 through 24

99 104 109 114 119

Yes, of course you will get only 24 results here since your A=4. Your formula only works with A=0!

You'll need to do something like 24*B+A to get the right answer.
 
  • #11


Oh wow, I can't believe I didn't realize that. Thanks!
 
Back
Top