首页 > 解决方案 > A math problem i encountered when trying to make a program

问题描述

A rather simple/complicated math problem I encountered whilst programming. Here's the simplified version of it:

a+c=e
b=absolute value of(X-R)
C=absolute value of(X-r)
R-r? 

a,c,e,b,X,R are all known but r isn't.

Edit

        if(x-R>0&&x-r>0) {//x-R is B and x-r is C
            int Rminusr=C-B;
        }else if(x-R>0&&x-r<0) {
            int Rminusr=-C-B;
        }else if(x-R<0&&x-r>0) {
            int Rminusr=B+C;
        }else if(x-R<0&&x-r<0) {
            int Rminusr=B-C;
        }else if(x-R==0) {
            int Rminusr=-r+x;
        }else if(x-r==0) {
            int Rminusr=R-x;
        }

this is what I got until i realized that i dont actually know r or X-r

标签: mathabsolute-value

解决方案


这里真的只有一个方程式很重要,因为它是唯一一个涉及到的方程式r

c = |X-r|

这意味着以下情况之一为真:

c = X-r
c = -(X-r) = r-X

这反过来意味着它r具有两个可能的值之一:

r = X-c
r = X+c

您需要引入另一个约束r以确切知道它是这两个值中的哪一个。

你做这些计算是为了什么?可能还有另一种方法可以实现您的目标。


推荐阅读