Programming Challenge: a classic trigonometry problem

12302013, 08:50 PM
(This post was last modified: 12302013 08:57 PM by Thomas Klemm.)
Post: #1




Programming Challenge: a classic trigonometry problem
This appears to be a well known problem for some of you. Nevertheless I had some fun finding a solution when I stumbled upon it some time ago. My suggestions are:
I'm looking forward to your solutions. Cheers Thomas 

01012014, 12:25 AM
Post: #2




RE: Programming Challenge: a classic trigonometry problem
Isn't that the beauty of calculators like the HP48? I got the answer in a couple of minutes, while the pen and paper method did not seem to work for me cause I'm not that bright. It's a bit like " God made man, but Samuel Colt made them equal". :)
Very interesting task, I'm looking forward to see some smart solutions to it. Thanks, 

01012014, 02:23 AM
Post: #3




RE: Programming Challenge: a classic trigonometry problem
(01012014 12:25 AM)RMollov Wrote: Isn't that the beauty of calculators like the HP48? I got the answer in a couple of minutes, while the pen and paper method did not seem to work for me cause I'm not that bright.Did you use the MultipleEquation Solver? I failed and got: Too many Unknowns. The solver apparently can not handle equations having at least two unknowns. Thus I'm very much interested in your solution. Quote:It's a bit like " God made man, but Samuel Colt made them equal". :)Why should we restrict ourselves to old calculators to solve problems when we can throw Mathematica at it? Why should we walk when we can take a car? There are hard problems that are very difficult or even impossible to solve with the limited power of these calculators. And there are distances that I don't want to walk. In this challenge I wanted to invite you for a walk. No problem if you don't feel like it. Quote:Very interesting task, I'm looking forward to see some smart solutions to it. Thanks,Me too! 

01012014, 06:12 AM
(This post was last modified: 01012014 07:04 AM by RMollov.)
Post: #4




RE: Programming Challenge: a classic trigonometry problem
(01012014 02:23 AM)Thomas Klemm Wrote: Did you use the MultipleEquation Solver? I failed and got: Too many Unknowns. I couldn't find a solution the way you wanted (without using solver), couldn't work it out even in AutoCAD, so I used the HP48G solver. It's only one equation and HP48 finds the solution in no time. I have never came across with this problem neither searched for solution on the net. Cheers, edit: my original notes: 

01012014, 08:44 AM
(This post was last modified: 01012014 08:45 AM by Thomas Klemm.)
Post: #5




RE: Programming Challenge: a classic trigonometry problem
(01012014 06:12 AM)RMollov Wrote: It's only one equation and HP48 finds the solution in no time.I used these these two equations with the MultipleEquation Solver: \[ \frac{\sqrt{a^2x^2}}{x}=\frac{c}{xd} \\ \frac{\sqrt{b^2x^2}}{x}=\frac{c}{d} \\ \] But the HP48 can't deal with it. What about HP50G? However I used additional variables: \[ u=\sqrt{a^2x^2} \\ v=\sqrt{b^2x^2} \\ \] And then reversed nominator and denominator: \[ \frac{x}{u}=\frac{xd}{c} \\ \frac{x}{v}=\frac{d}{c} \\ \] Adding these two equations leads to: \[ \frac{x}{u}+\frac{x}{v}=\frac{xd}{c}+\frac{d}{c}=\frac{x}{c} \] Now we can get rid of \(x\): \[ \frac{1}{u}+\frac{1}{v}=\frac{1}{c} \] In a similar way I could remove \(x\) from the first two equations and got: \[ u^2v^2=a^2b^2 \] Your solution is correct. Congratulations! Cheers Thomas 

01012014, 02:52 PM
Post: #6




RE: Programming Challenge: a classic trigonometry problem
Very nice solution Rmolov! I looked at the problem too. My mistake is that I complicated things, making the solution difficult (as in solving multiple nonlinear equations).
Namir 

01012014, 04:06 PM
Post: #7




RE: Programming Challenge: a classic trigonometry problem
Nice problem! After several false starts I was able to get the math right this using the hints here. Solved it with my prime.
Jonathan 

01042014, 01:23 PM
Post: #8




RE: Programming Challenge: a classic trigonometry problem
Sorry to join a bit later...
There is a solution without multivariable solver and needing only a polynomial one Let B the length of the biggest triangle (red) right edge and C the length of the left edge smaller triangle (green), with Thales (similar triangles) or a cartesian couple of equations one gets: 1) BC=15(B+C) with Pythagore: 2) B²+x²=40² and 3) C²+x²=30² Then 4) B²C²=40²30²=700=(BC)(B+C) From 1)>5) B=15C/(C15) Using 5) in 4) gives: C⁴30C³+700C²21000C+157500=0 with C>15 for having B>0 A polynomial solver gives: C=25.38493804, then B=36.6659935 and x=15.98764901 Everything by hand, except solving the 4th order equation. Regards 

01042014, 04:19 PM
Post: #9




RE: Programming Challenge: a classic trigonometry problem
(01042014 01:23 PM)Bunuel66 Wrote: Sorry to join a bit later...Better late than never! Quote:1) BC=15(B+C)Compare this to: (B=u, C=v) (01012014 08:44 AM)Thomas Klemm Wrote: \[ From here we can take different roads. One is using Newton's algorithm. I won't go into details here but leave a solution written in Python: Code:
As expected the convergence is quadratic: u = 35.0000000000000 v = 25.0000000000000 u = 36.6702279202279 v = 25.3383190883191 u = 36.6659267952683 v = 25.3848840365818 u = 36.6659934976999 v = 25.3849380375812 u = 36.6659934977741 v = 25.3849380377187 x = 15.9876490085686 Yet another approach is to use a fixedpoint equation. From the 2nd equation we extract \(u=f(v)\) and from the 1st \(v=g(u)\) . This leaves us with: \(u=f(g(u))\). For the 1st equation we can use the WP34S with the  operator to find: \(\frac{1}{v}=\frac{1}{c}+\frac{1}{u} \) Thus assuming \(c\) = 15 is stored in register 00 we can use: 001 RCL 00 002  From the 2nd equation we conclude \(u^2 = v^2 + 700\) where we can use →POL to solve for \(u\). The constant \(\sqrt{700}\) has to be stored in register 01 beforehand: 003 RCL 01 004 →POL These four steps are the core that is needed to solve for \(u\). We iterate these steps until the value doesn't change: 36.6659934978 And now we can calculate \(x=\sqrt{a^2u^2}\): 15.9876490086 For this last step trigonometric functions can be used if everything is scaled so that \(a=1\). Initialization:
Program: 001 RCL X 002 RCL 00 003  004 RCL 01 005 →POL 006 x≠? Z 007 BACK 006 008 ACOS 009 SIN 010 RCL× 02 011 END You can use any value as initial guess though a good starting point will be 0.9. Cheers Thomas PS: Anybody noticed that this construction can be used as a calculator for parallel resistors? 

01042014, 06:30 PM
(This post was last modified: 01042014 06:32 PM by Bunuel66.)
Post: #10




RE: Programming Challenge: a classic trigonometry problem
Going that way it is possible to build a more 'brute force' approach:
Rewriting equations from my previous post like: 1) BC15(B+C)=d(B,C) 2) B²+L²40²=e(B,L) 3) C²+L²30²=f(B,L) Let's build a cost function J=d²(B,C)+e²(B,L)+f²(B,L) Then using a standard gradient descent it is possible to solve J iteratively for B,C,L in one shot. Nevertheless I like a little bit of calculations before taking the hammer ;) BTW, scipy has some non linear multidimensional solvers. I haven't experimented with them. Regards 

01042014, 08:44 PM
Post: #11




RE: Programming Challenge: a classic trigonometry problem  
01052014, 07:04 PM
Post: #12




RE: Programming Challenge: a classic trigonometry problem
Thank you Thomas,
now I know, how to use the command MSLV! But I tried some other starting values say [1, 2,] and the hp 50g don't find an answer. It is a very sensitive context for finding solutions or not. Greetings peacecalc 

01052014, 08:57 PM
Post: #13




RE: Programming Challenge: a classic trigonometry problem
(01052014 07:04 PM)peacecalc Wrote: I tried some other starting values say [1, 2,] and the hp 50g don't find an answer. It is a very sensitive context for finding solutions or not. There are four solutions, two of them complex: pi@raspberrypi ~ $ wolfram Wolfram Language (Raspberry Pi Pilot Release) Copyright 19882013 Wolfram Research Information & help: wolfram.com/raspi In[1]:= NSolve[{1/u + 1/v == 1/15, u^2 == v^2 + 700}, {u, v}] Out[1]= {{u > 28.2118, v > 9.79309}, {u > 10.7729 + 6.01706 I, v > 2.58901  25.037 I}, {u > 10.7729  6.01706 I, v > 2.58901 + 25.037 I}, {u > 36.666, v > 25.3849}} The Newtonmethod diverges when started with [1, 2]: u = 1.0000000000000 v = 2.0000000000000 u = 41.3296296296296 v = 153.5851851851852 u = 49.4302111802062 v = 55.6512210512007 u = 205.7273127249908 v = 182.3140738957537 u = 1531.2733452510920 v = 1701.0869808819939 u = 93677.9530127932958 v = 84487.5385742955987 u = 247742042.5258520543575 v = 274681321.0911503434181 u = 2360136807978930.5000000000000 v = 2128667206649884.7500000000000 u = 157153398351889397901521059840.0000000000000 v = 174242135544052632367543615488.0000000000000 u = 949697291864817741529613623730114668140362827139987275776.0000000000000 v = 856556058361719901532676603696429135498784220559660023808.0000000000000 u = 25446017402251229885290585326635955008806695822895345978365490840398038769950489107047203019229485426806177660928.0000000000000 v = 28212997362815701894929958679669880027277377292558295324362552321603076286842132473592025945218693975400526118912.0000000000000 This is one of the advantages of the solution for the fixedpoint equation: it's globally convergent. Cheers Thomas 

01052014, 09:54 PM
Post: #14




RE: Programming Challenge: a classic trigonometry problem
'√(900X^2)/X=15/(X15*X/√(1600X^2))'
X: 15,9876490085 

01052014, 11:50 PM
Post: #15




RE: Programming Challenge: a classic trigonometry problem  
01062014, 12:23 AM
(This post was last modified: 01062014 12:32 AM by Gerson W. Barbosa.)
Post: #16




RE: Programming Challenge: a classic trigonometry problem
(01052014 11:50 PM)Thomas Klemm Wrote:Really nicer that way!(01052014 09:54 PM)Gerson W. Barbosa Wrote: '√(900X^2)/X=15/(X15*X/√(1600X^2))'Y Same as Bunuel's method, I think. But it was fun to find a solution on my own. http://m.flickr.com/photos/113638379@N08.../lightbox/ Cheers, Gerson. 

01062014, 01:40 AM
Post: #17




RE: Programming Challenge: a classic trigonometry problem  
01062014, 04:33 AM
Post: #18




RE: Programming Challenge: a classic trigonometry problem
(01062014 01:40 AM)Gerson W. Barbosa Wrote: Or RMollov's. Hopefully no copyright infringement here :) BTW the HP35s despite it's uselessness deals pretty well with this problem. After inputting the EQN: SQRT(A^2  X^2)  C / (1  C / SQRT(B^2  X^2)) and firing up SOLVE for X, it nicely asks for A, C & B and comes up with the answer in about a second or two. Cheers, 

01062014, 01:48 PM
(This post was last modified: 01062014 02:11 PM by peacecalc.)
Post: #19




RE: Programming Challenge: a classic trigonometry problem
Hello all,
Original from Gerson W. Barbosa: Quote:BTW the HP35s despite it's uselessness deals pretty well with this problem. After inputting the EQN: Same as with 32s II. Oh, well these good old machines... But only with a reasonable starting value for X, like 13. Greetings peaceglue 

01072014, 06:03 AM
(This post was last modified: 01072014 06:13 AM by Thomas Klemm.)
Post: #20




RE: Programming Challenge: a classic trigonometry problem
(01062014 12:23 AM)Gerson W. Barbosa Wrote: Same as Bunuel's method, I think. Wikipedia provides yet another solution: Crossed ladders problem \[ x^3(xc)=1 \] Which leads to: \[ x=\frac{1}{x^3}+c \] This equation can be solved iterating the following program: 001 \(x^3\) 002 1/x 003 RCL+ C For C use: \(\frac{60}{\sqrt{700}}\). Start with x = 2. After 12 runs the value doesn't change anymore: 2.34530476375 Can it be any shorter? Cheers Thomas 

« Next Oldest  Next Newest »

User(s) browsing this thread: 1 Guest(s)