# Approximation for Unknown Variable

1. Aug 2, 2012

### KingBigness

1. The problem statement, all variables and given/known data
Firstly sorry if this is in the wrong place. I have never submitted a question on this forum about a comp sci question.

I got an assignment that asked me to solve for a variable using Bisection of successive approximations. This however is not why I am here as I know you do not give answers to assignments.

I have done the assignment properly and submitted it so this is just for general knowledge. I was wondering if anyone could come up with a more efficient solution to this problem using other techniques that I may not have heard of before.

2. Relevant equations
$d = \frac{vcos(\theta)}{g}(vsin(\theta)+\sqrt{v^{2}sin^{2}(\theta)-2gh}$

Given v, g, h and d solve for theta.

Thanks for any ideas =D

2. Aug 2, 2012

### Staff: Mentor

What are the values of those 4 variables?

3. Aug 2, 2012

### KingBigness

Inputted by the user.

I forgot to to say that theta will lie in the range

$arctan(\frac{v^{2}}{g*d})\le \theta \le 90 degrees$

4. Aug 3, 2012

### Staff: Mentor

Could you please post your solution? We need to see that before we can be of much help.

5. Aug 5, 2012

### KingBigness

Assumed you meant my code.

http://pastebin.com/X0Ni4ebz

6. Aug 5, 2012

### Staff: Mentor

There's something fishy with the given equation... given the usual physical interpretation of the variables there is a units mismatch in the expression. Since the trig functions yield unitless results (so we can ignore them for purposes of unit analysis), both "d" and "v2/g" terms yield meters, but the radical term yields m/s.

7. Aug 5, 2012

### KingBigness

The equation was written by a computer scientist and it producing a real world value is beside the point.

The way I wrote my program to solve for theta was start with the lower limit of theta, trial it and see how much it deviated from d and if this deviation was more than 0.0001 then increment theta and try again until the deviation is less than 0.0001.
To me this doesn't seem very accurate in a real world situation (fine here because the answer only needs to be to two decimal places).

That's why I am here to ask you guys if you can think of a better method of solving it eg monte carlo etc.

8. Aug 5, 2012

### Staff: Mentor

On the contrary, if you wish for help here then the onus rests with you to ensure you are not a cavalier waste of other's time.

The equation you provided is wrong. That's indisputable. Even blind Freddie can see it has mismatched brackets. So before you make yourself look a complete goose, go back and fix it to how it should be.

A lesson you should take from this is to learn to better proof-read your own posts.

Thanks to gneill for taking the time to highlight your oversight.

9. Aug 5, 2012

### Staff: Mentor

There is a significant hint in the problem statement as you've written it: Bisection.

Do a search on "Bisection method". It'll be a lot more efficient than creeping up on the solution by fixed steps as you're doing.