Inverse equations
434265
public function inverse($p)
    {
        $p->x -= $this->x0;
        $p->y = $this->rh - $p->y + $this->y0;

        if ($this->ns >= 0) {
            $rh1 = sqrt( $p->x * $p->x + $p->y * $p->y );
            $con = 1.0;
        } else {
            $rh1 = -sqrt( $p->x * $p->x + $p->y * $p->y );
            $con = -1.0;
        }

        $theta = 0.0;

        if ($rh1 != 0.0) {
            $theta = atan2($con * $p->x, $con * $p->y);
        }

        $ml = $this->g - $rh1 / $this->a;

        $lat = $this->phi3z( $ml, $this->e0, $this->e1, $this->e2, $this->e3 );
        $lon = Common::adjust_lon( $this->long0 + $theta / $this->ns );

        $p->x = $lon;
        $p->y = $lat;

        return $p;
    }
128386
public function inverse($p) {
        $p->x -= $this->x0;
        $p->y -= $this->y0;
        $x = $p->x / $this->a;
        $y = $p->y / $this->a;

        if( $this->sphere ) {
            $cosz = 0.0;
            #$rh;
            $sinz = 0.0;

            $rh = sqrt(($x * $x) + ($y * $y));
            $phi = $rh * 0.5;

            if ($phi > 1.0) {
                Proj4php::reportError('laea:Inv:DataError');
                return null;
            }

            $phi = 2. * asin( $phi );

            if ($this->mode == $this->OBLIQ || $this->mode == $this->EQUIT) {
                $sinz = sin($phi);
                $cosz = cos($phi);
            }
            switch( $this->mode ) {
                case $this->EQUIT:
                    $phi = (abs( $rh ) <= Common::EPSLN) ? 0. : asin( $y * $sinz / $rh );
                    $x *= $sinz;
                    $y = $cosz * $rh;
                    break;
                case $this->OBLIQ:
                    $phi = (abs( $rh ) <= Common::EPSLN) ? $this->phi0 : asin( $cosz * $this->sinph0 + $y * $sinz * $this->cosph0 / $rh );
                    $x *= $sinz * $this->cosph0;
                    $y = ($cosz - sin( $phi ) * $this->sinph0) * $rh;
                    break;
                case $this->N_POLE:
                    $y = -$y;
                    $phi = Common::HALF_PI - $phi;
                    break;
                case $this->S_POLE:
                    $phi -= Common::HALF_PI;
                    break;
            }

            $lam = ($y == 0.0 && ($this->mode == $this->EQUIT || $this->mode == $this->OBLIQ)) ? 0. : atan2($x, $y);
        } else {
            /*
            $cCe;
            $sCe;
            $q;
            $rho;
            */
            $ab = 0.0;

            switch($this->mode) {
                case $this->EQUIT:
                case $this->OBLIQ:
                    $x /= $this->dd;
                    $y *= $this->dd;
                    $rho = sqrt( $x * $x + $y * $y );

                    if ($rho < Common::EPSLN) {
                        $p->x = 0.;
                        $p->y = $this->phi0;
                        return $p;
                    }

                    $sCe = 2. * asin( .5 * $rho / $this->rq );
                    $cCe = cos( $sCe );
                    $x *= ($sCe = sin($sCe));

                    if ($this->mode == $this->OBLIQ) {
                        $ab = $cCe * $this->sinb1 + $y * $sCe * $this->cosb1 / $rho;
                        $q = $this->qp * $ab;
                        $y = $rho * $this->cosb1 * $cCe - $y * $this->sinb1 * $sCe;
                    } else {
                        $ab = $y * $sCe / $rho;
                        $q = $this->qp * $ab;
                        $y = $rho * $cCe;
                    }
                    break;
                case $this->N_POLE:
                    $y = -$y;
                case $this->S_POLE:
                    $q = ($x * $x + $y * $y);

                    if ( ! $q) {
                        $p->x = 0.;
                        $p->y = $this->phi0;
                        return $p;
                    }
                    /*
                      q = $this->qp - q;
                     */
                    $ab = 1.0 - $q / $this->qp;

                    if ($this->mode == $this->S_POLE) {
                        $ab = - $ab;
                    }
                    break;
            }
            $lam = atan2($x, $y);
            $phi = $this->authlat(asin($ab), $this->apa);
        }

        /*
          $Rh = sqrt($p->x *$p->x +$p->y * $p->y);
          $temp = Rh / (2.0 * $this->a);

          if (temp > 1) {
          Proj4php::reportError("laea:Inv:DataError");
          return null;
          }

          $z = 2.0 * Common::asinz(temp);
          $sin_z=sin(z);
          $cos_z=cos(z);

          $lon =$this->long0;
          if (abs(Rh) > Common::EPSLN) {
          $lat = Common::asinz($this->sin_lat_o * cos_z +$this-> cos_lat_o * sin_z *$p->y / Rh);
          $temp =abs($this->lat0) - Common::HALF_PI;
          if (abs(temp) > Common::EPSLN) {
          temp = cos_z -$this->sin_lat_o * sin(lat);
          if(temp!=0.0) lon=Common::adjust_lon($this->long0+atan2($p->x*sin_z*$this->cos_lat_o,temp*Rh));
          } else if ($this->lat0 < 0.0) {
          lon = Common::adjust_lon($this->long0 - atan2(-$p->x,$p->y));
          } else {
          lon = Common::adjust_lon($this->long0 + atan2($p->x, -$p->y));
          }
          } else {
          lat = $this->lat0;
          }
         */
        //return(OK);
        $p->x = Common::adjust_lon($this->long0 + $lam);
        $p->y = $phi;
        return $p;
    }
452160
public function inverse($p)
    {
        /*
        $rh;  // height above ellipsoid	
        $z;  // angle
        $sinz;
        $cosz; // sin of z and cos of z	
        $temp;
        $con;
        $lon;
        $lat;
        */

        $p->x -= $this->x0;
        $p->y -= $this->y0;
        $rh = sqrt($p->x * $p->x + $p->y * $p->y);

        if($rh > $this->a + 0.0000001) {
            Proj4php::reportError("orthoInvDataError");
        }

        $z = Common::asinz($rh / $this->a);

        $sinz = sin($z);
        $cosz = cos($z);

        $lon = $this->long0;

        if (abs($rh) <= Common::EPSLN) {
            $lat = $this->lat0;
        }

        $lat = Common::asinz($cosz * $this->sin_p14 + ($p->y * $sinz * $this->cos_p14) / $rh);
        $con = abs($this->lat0) - Common::HALF_PI;

        if (abs(con) <= Common::EPSLN) {
            if ($this->lat0 >= 0) {
                $lon = Common::adjust_lon($this->long0 + atan2($p->x, -$p->y));
            } else {
                $lon = Common::adjust_lon($this->long0 - atan2(-$p->x, $p->y));
            }
        }
        $con = $cosz - $this->sin_p14 * sin($lat);

        $p->x = $lon;
        $p->y = $lat;

        return $p;
    }
400860
public function inverse($p)
    {
        /*
        $dlon;
        $xx;
        $yy;
        $xys;
        $c1;
        $c2;
        $c3;
        $al;
        $asq;
        $a1;
        $m1;
        $con;
        $th1;
        $d;
        */

        $p->x -= $this->x0;
        $p->y -= $this->y0;

        $con = Common::PI * $this->R;

        $xx = $p->x / $con;
        $yy = $p->y / $con;

        $xys = $xx * $xx + $yy * $yy;

        $c1 = -abs( $yy ) * (1.0 + $xys);
        $c2 = $c1 - 2.0 * $yy * $yy + $xx * $xx;
        $c3 = -2.0 * $c1 + 1.0 + 2.0 * $yy * $yy + $xys * $xys;

        $d = $yy * $yy / $c3 + (2.0 * $c2 * $c2 * $c2 / $c3 / $c3 / $c3 - 9.0 * $c1 * $c2 / $c3 / $c3) / 27.0;

        $a1 = ($c1 - $c2 * $c2 / 3.0 / $c3) / $c3;
        $m1 = 2.0 * sqrt( -$a1 / 3.0 );
        $con = ((3.0 * $d) / $a1) / $m1;

        if (abs($con) > 1.0) {
            if ($con >= 0.0) {
                $con = 1.0;
            } else {
                $con = -1.0;
            }
        }

        $th1 = acos($con) / 3.0;

        if ($p->$y >= 0) {
            $lat = (-$m1 * cos($th1 + Common::PI / 3.0) - $c2 / 3.0 / $c3) * Common::PI;
        } else {
            $lat = -(-m1 * cos($th1 + Common::PI / 3.0) - $c2 / 3.0 / $c3) * Common::PI;
        }

        if (abs($xx) < Common::EPSLN) {
            $lon = $this->$long0;
        }

        $lon = Common::adjust_lon(
            $this->long0 + Common::PI * ($xys - 1.0 + sqrt(1.0 + 2.0 * ($xx * $xx - $yy * $yy) + $xys * $xys)) / 2.0 / $xx
        );

        $p->x = $lon;
        $p->y = $lat;

        return $p;
    }
1235504
public DenseMatrix inverse() {
        int n = L.nrows();
        DenseMatrix inv = Matrix.eye(n);
        solve(inv);
        return inv;
    }
1051440
public function inverse($p)
    {
        /*
        $rh;  // Rho 
        $z;  // angle 
        $sinc;
        $cosc;
        $c;
        $lon;
        $lat;
        */

        $p->x = ($p->x - $this->x0) / $this->a;
        $p->y = ($p->y - $this->y0) / $this->a;

        $p->x /= $this->k0;
        $p->y /= $this->k0;

        if (($rh = sqrt($p->x * $p->x + $p->y * $p->y))) {
            $c = atan2( $rh, $this->rc );
            $sinc = sin( $c );
            $cosc = cos( $c );

            $lat = Common::asinz( $cosc * $this->sin_p14 + ($p->y * $sinc * $this->cos_p14) / $rh );
            $lon = atan2( $p->x * sinc, rh * $this->cos_p14 * $cosc - $p->y * $this->sin_p14 * $sinc );
            $lon = Common::adjust_lon( $this->long0 + $lon );
        } else {
            $lat = $this->phic0;
            $lon = 0.0;
        }

        $p->x = $lon;
        $p->y = $lat;

        return $p;
    }
199049
def equation(self):
        
        mat = np.empty((self.nunknowns, self.model.neq))
        rhs = np.zeros(self.nunknowns)  # Needs to be initialized to zero
        for icp in range(self.ncp):
            istart = icp * self.nlayers
            ieq = 0
            for e in self.model.elementlist:
                if e.nunknowns > 0:
                    qx, qy = e.disvecinflayers(self.xc[icp], self.yc[icp], self.layers)
                    mat[istart:istart + self.nlayers, ieq:ieq + e.nunknowns] = \
                        qx * self.cosnorm[icp] + qy * self.sinnorm[icp] - self.resfac[:, np.newaxis] * \
                        (e.potinflayers(self.xcin[icp], self.ycin[icp], self.layers, aq=self.aq) / self.aq.Tcol[
                            self.layers] - \
                         e.potinflayers(self.xcout[icp], self.ycout[icp], self.layers, aq=self.aq) / self.aq.Tcol[
                             self.layers])
                    ieq += e.nunknowns
                else:
                    qx, qy = e.disveclayers(self.xc[icp], self.yc[icp], self.layers)
                    rhs[istart:istart + self.nlayers] -= qx * self.cosnorm[icp] + qy * self.sinnorm[icp] + self.resfac * \
                                                          (e.potentiallayers(self.xcin[icp], self.ycin[icp], self.layers,
                                                                             aq=self.aq) / self.aq.T[self.layers] -
                                                           e.potentiallayers(self.xcout[icp], self.ycout[icp],
                                                                             self.layers, aq=self.aq) / self.aq.T[
                                                              self.layers])
        return mat, rhs
298723
def equation(self):
        
        mat = np.zeros((self.nunknowns, self.model.neq))
        rhs = np.zeros(self.nunknowns)  # Needs to be initialized to zero
        rhs[0:self.nlayers - 1] = 0.0
        rhs[self.nlayers - 1] = self.Qc
        ieq = 0
        for e in self.model.elementlist:
            if e.nunknowns > 0:
                head = e.potinflayers(self.xc, self.yc, self.layers) / self.aq.Tcol[self.layers, :]
                mat[0:self.nlayers - 1, ieq:ieq + e.nunknowns] = head[:-1] - head[1:]
                if e == self:
                    for i in range(self.nlayers - 1):
                        mat[i, ieq + i] -= self.resfac[i]
                        mat[i, ieq + i + 1] += self.resfac[i + 1]
                    mat[self.nlayers - 1, ieq:ieq + self.nlayers] = 1.0
                ieq += e.nunknowns
            else:
                head = e.potentiallayers(self.xc, self.yc, self.layers) / self.aq.T[self.layers]
                rhs[0:self.nlayers - 1] -= head[:-1] - head[1:]
        return mat, rhs
349578
public function inverse($p)
    {
        /* Transformation */
        /* revert y, x */
        $tmp = $p->x;
        $p->x = $p->y;
        $p->y = $tmp;

        if ($this->czech) {
            $p->y *= -1.0;
            $p->x *= -1.0;
        }

        $ro = sqrt( $p->x * $p->x + $p->y * $p->y );
        $eps = atan2( $p->y, $p->x );
        $d = $eps / sin( $this->s0 );
        $s = 2. * (atan( pow( $this->ro0 / $ro, 1. / $this->n ) * tan( $this->s0 / 2. + $this->s45 ) ) - $this->s45);
        $u = asin( cos( $this->ad ) * sin( $s ) - sin( $this->ad ) * cos( $s ) * cos( $d ) );
        $deltav = asin( cos( $s ) * sin( $d ) / cos( $u ) );
        $p->x = $this->long0 - $deltav / $this->alfa;

        /* ITERATION FOR $lat */
        $fi1 = $u;
        $ok = 0;
        $iter = 0;
        do {
            $p->y = 2. * ( atan( pow( $this->k, -1. / $this->alfa ) *
                                pow( tan( $u / 2. + $this->s45 ), 1. / $this->alfa ) *
                                pow( (1. + $this->e * sin( $fi1 )) / (1. - $this->e * sin( $fi1 )), $this->e / 2. )
                      ) - $this->s45);
            if (abs( $fi1 - $p->y ) < 0.0000000001)
                $ok = 1;
            $fi1 = $p->y;
            $iter += 1;
        } while ($ok == 0 && $iter < 15);

        if ($iter >= 15) {
            Proj4php::reportError( "PHI3Z-CONV:Latitude failed to converge after 15 iterations" );
            //console.log('iter:', iter);
            return null;
        }

        return $p;
    }
1261708
def inverse_mercator(xy):
    
    lon = (xy[0] / 20037508.34) * 180
    lat = (xy[1] / 20037508.34) * 180
    lat = 180 / math.pi * \
        (2 * math.atan(math.exp(lat * math.pi / 180)) - math.pi / 2)
    return (lon, lat)
238942
def inverse(self):
        
        return ResizingOperator(domain=self.range, range=self.domain,
                                pad_mode=self.pad_mode,
                                pad_const=self.pad_const)
1162003
function inverse(matrix) {
    //http://www.wolframalpha.com/input/?i=Inverse+%5B%7B%7Ba,c,e%7D,%7Bb,d,f%7D,%7B0,0,1%7D%7D%5D

    var a = matrix.a,
        b = matrix.b,
        c = matrix.c,
        d = matrix.d,
        e = matrix.e,
        f = matrix.f;


    var denom = a * d - b * c;

    return {
        a: d / denom,
        b: b / -denom,
        c: c / -denom,
        d: a / denom,
        e: (d * e - c * f) / -denom,
        f: (b * e - a * f) / denom
    };
}
773191
function performTermOperationOnEquation(equation, op, term, changeType) {
  const oldEquation = equation.clone();

  const leftTerm = clone(term);
  const rightTerm = clone(term);
  const leftNode = performTermOperationOnExpression(
    equation.leftNode, op, leftTerm);
  const rightNode = performTermOperationOnExpression(
    equation.rightNode, op, rightTerm);

  let comparator = equation.comparator;
  if (Negative.isNegative(term) && (op === '*' || op === '/')) {
    comparator = COMPARATOR_TO_INVERSE[comparator];
  }

  const newEquation = new Equation(leftNode, rightNode, comparator);
  return new EquationStatus(changeType, oldEquation, newEquation);
}
590626
public static void inverse(int[] a)
  {
    for (int i = 0; i < a.length; i++) {
      if (a[i] >= 0) {
        inverseLoop(a, i);
      }
    }

    for (int i = 0; i < a.length; i++) {
      a[i] = ~a[i];
    }
  }
1279686
def inverse(self):
        """"""
        inv = np.empty(self.size, np.int)
        inv[self.sorter] = self.sorted_group_rank_per_key
        return inv
151450
def equation(self):
        
        mat = np.empty((self.nunknowns, self.model.neq))
        rhs = np.zeros(self.nunknowns)  # Needs to be initialized to zero
        for icp in range(self.ncp):
            istart = icp * self.nlayers
            ieq = 0
            for e in self.model.elementlist:
                if e.nunknowns > 0:
                    qxin, qyin = e.disvecinflayers(self.xcin[icp], self.ycin[icp], self.layers, aq=self.aqin)
                    qxout, qyout = e.disvecinflayers(self.xcout[icp], self.ycout[icp], self.layers, aq=self.aqout)
                    mat[istart:istart + self.nlayers, ieq:ieq + e.nunknowns] = \
                        (qxin - qxout) * self.cosnorm[icp] + (qyin - qyout) * self.sinnorm[icp]
                    ieq += e.nunknowns
                else:
                    qxin, qyin = e.disveclayers(self.xcin[icp], self.ycin[icp], self.layers, aq=self.aqin)
                    qxout, qyout = e.disveclayers(self.xcout[icp], self.ycout[icp], self.layers, aq=self.aqout)
                    rhs[istart:istart + self.nlayers] -= (qxin - qxout) * self.cosnorm[icp] + (qyin - qyout) * \
                                                         self.sinnorm[icp]
        return mat, rhs
1169640
public double[][] inverse() {
    // Build permuted identity matrix efficiently:
    double[][] b = new double[piv.length][m];
    for(int i = 0; i < piv.length; i++) {
      b[piv[i]][i] = 1.;
    }
    return solveInplace(b);
  }