Re: Problem with conditional statement



"mukesh tiwari" <mukeshtiwari.iiitm@xxxxxxxxx> wrote in message
news:1182190699.734601.203130@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi everybody i am trying to solve problem
http://acm.uva.es/p/v105/10512.html.

my solution is

(x+y)y=P (1)
(x-y)x=Q (2)

(1+(y/x))xy=P (1)//taking x outside
(1-(y/x))x^2=Q (2)

dividing 1 and 2 and let (y/x)=k

(1+k)k/(1-k)=P/Q;

solving for k
k=-(P+Q) +-sqrt((P+Q)^2+4PQ)/2Q;
You seem to have slipped up in your working! Check!

since x>=y so we can not take -ve sign as it will make |k|>1 which is
not possible so i take only +ve sign ;
I think your logic here is flawed! Check!

solution is possible only when
(P+Q)^2+4PQ is perfect square .
after determining k we can find out x and y
so my values are

x=+-sqrt(Q/(1-k));
and y=+-sqrt(Pk/(1+k));
now my problem is based on for each value of x we have two values of
y so we have 4 pair of values .So which value to output .

It is not advisable to compute y this way as you introduce an unnecessary
ambiguity in the sign which would lead to an erroneous result. You would do
better using your relation: k = y/x => y = k*x

With corrections your approach is getting there - be careful though as one
solution to k leads to non-integer solutions while the other leads to
success. However, which one will depend on the values of P & Q. (On a
quick look transposing P & Q switches which root you need to take for k).

An interesting approach - but probably computationally inefficient because
of the SQRT. But it does seem to yield solutions in the negative integer
domain where appropriate.

--
Stuart


.



Relevant Pages

  • Re: Looking for problem
    ... I'm looking for an toy problem which leads to solving ... a sparse but unstructured linear system. ...
    (sci.math.num-analysis)
  • Looking for problem
    ... I'm looking for an toy problem which leads to solving ... a sparse but unstructured linear system. ... As I need it for teaching students during their first ...
    (sci.math.num-analysis)
  • Re: How to solve for L?
    ... The only thing I know for sure is that solving for L leads to the value ... The equations system arises from the problem of determining the critical ... The best way to predict reality, is to know exactly what you DON'T want. ...
    (sci.math)
  • How to solve for L?
    ... The only thing I know for sure is that solving for L leads to the value ... The equations system arises from the problem of determining the critical ... 2-x+y, applying Lagrange's multipliers method. ...
    (sci.math)
  • Re: Object-relational mapping tool
    ... because the blunder that leads to O-R mappings leads also ... A nightmare induced by object-think. ... We avoid the gui and configure Toplink ... you need to be more careful. ...
    (comp.object)