# 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:= 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= {0. + (0.4 G (Hg (-0.1 + 1. z) + Lb (-0.5 + 5. z)))/L} Out= (2 G (0.2 Hg + Lb) (-0.1 + z))/L Out= {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
5 Replies
Sort By:
Posted 9 days ago
 The following methods can reconcile this problem in this specific scenario: In:= data = {{0.1, 0}, {0.2, 0.2 (Lb + 0.2 Hg) G/L }}; Y = a z + b /. Solve[And @@ (a #[] + b == #[] & /@ data), {a, b}][]; 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= 0 Out= True Out= (0.4 G (Hg (-0.1 + 1. z) + Lb (-0.5 + 5. z)))/L Out= True 
Posted 9 days ago
 How are Out and Out inconsistent?
Posted 9 days ago
 Hi Daniel Lichtblau,Thank you for pointing out this. Although Out and Out 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 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}][]//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 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:= data = {{0.1, 0}, {0.2, 0.2 (Lb + 0.2 Hg) G/L }}; Y = a z + b /. Solve[And @@ (a #[] + b == #[] & /@ data), {a, b}][]; 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= True Out= True