Note that there are some explanatory texts on larger screens.

plurals
  1. POSolve for an equation of a plane in Python (like in Matlab)
    primarykey
    data
    text
    <p>I have a data set, and I'm trying to get the equation of a plane from it. That is: a*x + b*y + c = z In my case, dT = x, dTa = y, Constant = c, and dV = z.</p> <p>I'm able to do this quite easily in Matlab, code:</p> <pre><code>dT = [8.5; 3.5; .4; 12.9] dT = 8.5000 3.5000 0.4000 12.9000 dTa = [8.5; 18; 22; 34.9] dTa = 8.5000 18.0000 22.0000 34.9000 dV = [3; 1; .5; 3] dV = 3.0000 1.0000 0.5000 3.0000 Constant = ones(size(dT)) Constant = 1 1 1 1 coefficients = [dT dTa Constant]\dV coefficients = 0.2535 -0.0392 1.0895 </code></pre> <p>so, here, coefficients = (a, b, c).</p> <p>Is there an equivalent way to do this in Python? I've been trying to use the numpy module (numpy.linalg), but its not working out so well. For one, the matrix MUST be square, and even so, it doesn't give very nice answers. For example:</p> <p>Error:</p> <pre><code>&gt;&gt;&gt; dT [8.5, 3.5, 0.4, 12.9] &gt;&gt;&gt; dTa [8.5, 18, 22, 34.9] &gt;&gt;&gt; dV [3, 1, 0.5, 3] &gt;&gt;&gt; Constant array([ 1., 1., 1., 1.]) &gt;&gt;&gt; numpy.linalg.solve([dT, dTa, Constant], dV) Traceback (most recent call last): File "&lt;pyshell#45&gt;", line 1, in &lt;module&gt; numpy.linalg.solve([dT, dTa, Constant], dV) File "C:\Python27\lib\site-packages\numpy\linalg\linalg.py", line 312, in solve _assertSquareness(a) File "C:\Python27\lib\site-packages\numpy\linalg\linalg.py", line 160, in _assertSquareness raise LinAlgError, 'Array must be square' LinAlgError: Array must be square </code></pre> <p>Wokrking with square matrix:</p> <pre><code>&gt;&gt;&gt; dT array([ 8.5, 3.5, 12.9]) &gt;&gt;&gt; dTa array([ 8.5, 18. , 34.9]) &gt;&gt;&gt; dV array([3, 1, 3]) &gt;&gt;&gt; Constant array([ 1., 1., 1.]) &gt;&gt;&gt; numpy.linalg.solve([dT, dTa, Constant], dV) array([ 2.1372267 , 2.79746835, -1.93469505]) </code></pre> <p>These are not even close to the values I got before!!</p> <p>Any ideas guys? Any advice appreciated. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload