Message Boards Message Boards

GROUPS:

Find the equation of the line passing through two points

Posted 9 days ago
223 Views
|
5 Replies
|
1 Total Likes
|

I've the data corresponding to two points on the line Ff = a z + b, which meet the following condition :

0.1 a + b = 0
0.2 a + b = 0.2 (Lb + 0.2 Hg) G/L

The following code is used to find the coefficients a and b:

In[165]:= data = {{0.1, 0}, {0.2, 0.2 (Lb + 0.2 Hg) G/L }};
a z + b /. 
  Solve[a data[[1, 1]] + b == data[[1, 2]] && 
    a data[[2, 1]] + b == data[[2, 2]], {a, b}] // Simplify
Ff = 2 (z - 0.1) (Lb + 0.2 Hg) G/L
% - %% // Simplify


Out[166]= {0. + (0.4 G (Hg (-0.1 + 1. z) + Lb (-0.5 + 5. z)))/L}

Out[167]= (2 G (0.2 Hg + Lb) (-0.1 + z))/L

Out[168]= {0. + (5.55112*10^-17 G Lb)/L}

Where, the equation Ff = 2 (z - 0.1) (Lb + 0.2 Hg) G/L is the solution calculated by hand. As you can see, it's not consistent with the result given by Wolfram.

Any hints for this problem will be appreciated.

Regards, Zhao

POSTED BY: Hongyi Zhao
5 Replies
Posted 9 days ago

The following methods can reconcile this problem in this specific scenario:

In[159]:= data = {{0.1, 0}, {0.2, 0.2 (Lb + 0.2 Hg) G/L }};
Y = a z + b /. 
   Solve[And @@ (a #[[1]] + b == #[[2]] & /@ data), {a, b}][[1]];
Ff = 2 (z - 0.1) (Lb + 0.2 Hg) G/L;
Y - Ff // Rationalize // Simplify
Y == Ff // Rationalize // Simplify
Y // Expand // Chop // Factor // Simplify
% == Ff // Expand // Chop // Factor // Simplify

Out[162]= 0

Out[163]= True

Out[164]= (0.4 G (Hg (-0.1 + 1. z) + Lb (-0.5 + 5. z)))/L

Out[165]= True
POSTED BY: Hongyi Zhao

How are Out[166] and Out[167] inconsistent?

POSTED BY: Daniel Lichtblau
Posted 9 days ago

Hi Daniel Lichtblau,

Thank you for pointing out this. Although Out[166] and Out[167] are also exactly the same, it's difficult to check and compare them with our naked eye, especially at the first glimpse.

On the other hand, as you can see, the difference between them is not equal to zero, which gives me an impression that they are inconsistent with each other. So, I want to find a method to check/confirm the coincidence between them programmatically in the definition field of the independent variables.

I still don't know how to perform the corresponding consistency check on the real number field.

Regards, Zhao

POSTED BY: Hongyi Zhao
Posted 9 days ago
data = {{0.1, 0}, {0.2, 0.2 (Lb + 0.2 Hg) G/L }};
a z+b/.Solve[a data[[1,1]]+b==data[[1,2]]&&a data[[2,1]]+b==data[[2,2]],{a,b}][[1]]//Expand//Chop
Ff = 2 (z - 0.1) (Lb + 0.2 Hg) G/L//Expand//Chop

-0.04*G*Hg/L - 0.2*G*Lb/L + 0.4*G*Hg*z/L + 2.*G*Lb*z/L

-0.04*G*Hg/L - 0.2*G*Lb/L + 0.4*G*Hg*z/L + 2.*G*Lb*z/L

but in general there will almost certainly be cases where you cannot completely reconcile the real number field with finite decimal approximations, floating point representations and calculations. This problem may most often appear when you think some numbers with decimal points represent exact quantities while Mathematica almost always interprets anything with a decimal point as approximate floating point quantities.

POSTED BY: Bill Nelson
Posted 9 days ago

It seems that there is no perfect solution to this type of problem. Basically, the root cause is that there is no perfect way to accurately represent all irrational numbers in a computer.

Side remark: The following approach, which does not use any approximation, seems to be a better solution to the problem discussed here:

In[248]:= data = {{0.1, 0}, {0.2, 0.2 (Lb + 0.2 Hg) G/L }};
Y = a z + b /. 
   Solve[And @@ (a #[[1]] + b == #[[2]] & /@ data), {a, b}][[1]];
Ff = 2 (z - 0.1) (Lb + 0.2 Hg) G/L;
Y == Ff // Expand // Factor // FullSimplify
Y == Ff // Expand // Together // FullSimplify

(*Y==Ff//Rationalize//Simplify
Y==Ff//Expand//Chop//Factor//Simplify*)

Out[251]= True

Out[252]= True
POSTED BY: Hongyi Zhao
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract