Skip to content

Latest commit

 

History

History
278 lines (177 loc) · 6.68 KB

File metadata and controls

278 lines (177 loc) · 6.68 KB

zrotg

Construct a Givens plane rotation.

Usage

var zrotg = require( '@stdlib/blas/base/zrotg' );

zrotg( za, zb )

Constructs a Givens plane rotation provided two double-precision complex floating-point values za and zb.

var Complex128 = require( '@stdlib/complex/float64/ctor' );

var za = new Complex128( 4.0, 3.0 );
var zb = new Complex128( 0.0, 0.0 );

var out = zrotg( za, zb );
// returns <Float64Array>[ 4.0, 3.0, 1.0, 0.0, 0.0 ]

The function has the following parameters:

  • za: rotational elimination parameter (complex number).
  • zb: rotational elimination parameter (complex number).

The function returns an array with the following elements:

  • r: real part of the rotated vector (real number).
  • r_imag: imaginary part of the rotated vector (real number).
  • c: cosine of the rotation angle (real number).
  • s: real part of the sine of the rotation angle (real number).
  • s_imag: imaginary part of the sine of the rotation angle (real number).

zrotg.assign( za, zb, out, stride, offset )

Constructs a Givens plane rotation provided two double-precision complex floating-point values za and zb and assigns results to an output array.

var Complex128 = require( '@stdlib/complex/float64/ctor' );
var Float64Array = require( '@stdlib/array/float64' );

var za = new Complex128( 4.0, 3.0 );
var zb = new Complex128( 0.0, 0.0 );

var out = new Float64Array( 5 );

var y = zrotg.assign( za, zb, out, 1, 0 );
// returns <Float64Array>[ 4.0, 3.0, 1.0, 0.0, 0.0 ]

var bool = ( y === out );
// returns true

Notes

  • zrotg() corresponds to the BLAS level 1 function zrotg.

Examples

var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var Complex128 = require( '@stdlib/complex/float64/ctor' );
var zrotg = require( '@stdlib/blas/base/zrotg' );

var out;
var i;

function rand() {
    return new Complex128( discreteUniform( -5, 5 ), discreteUniform( -5, 5 ) );
}

for ( i = 0; i < 100; i++ ) {
    out = zrotg( rand(), rand() );
    console.log( out );
}

C APIs

Usage

#include "stdlib/blas/base/zrotg.h"

c_zrotg( a, b, *Out, strideOut )

Constructs a Givens plane rotation provided two double-precision complex floating-point values a and b.

#include "stdlib/complex/float64/ctor.h"

double Out[ 5 ];
const stdlib_complex128_t a = stdlib_complex128( 4.0, 3.0 );
const stdlib_complex128_t b = stdlib_complex128( 0.0, 0.0 );

c_zrotg( a, b, Out, 1 );
// Out => [ 4.0, 3.0, 1.0, 0.0, 0.0 ]

The function accepts the following arguments:

  • a: [in] stdlib_complex128_t rotational elimination parameter.
  • b: [in] stdlib_complex128_t rotational elimination parameter.
  • Out: [out] double* output array.
  • strideOut: [in] CBLAS_INT stride length for Out.
void c_zrotg( const stdlib_complex128_t a, const stdlib_complex128_t b, double *Out, const CBLAS_INT strideOut );

c_zrotg_assign( a, b, *Out, strideOut, offsetOut )

Constructs a Givens plane rotation provided two double-precision complex floating-point values a and b using alternative indexing semantics.

#include "stdlib/complex/float64/ctor.h"

double Out[ 5 ];
const stdlib_complex128_t a = stdlib_complex128( 4.0, 3.0 );
const stdlib_complex128_t b = stdlib_complex128( 0.0, 0.0 );

c_zrotg_assign( a, b, Out, 1, 0 );
// Out => [ 4.0, 3.0, 1.0, 0.0, 0.0 ]

The function accepts the following arguments:

  • a: [in] stdlib_complex128_t rotational elimination parameter.
  • b: [in] stdlib_complex128_t rotational elimination parameter.
  • Out: [out] double* output array.
  • strideOut: [in] CBLAS_INT stride length for Out.
  • offsetOut: [in] CBLAS_INT starting index for Out.
void c_zrotg_assign( const stdlib_complex128_t a, const stdlib_complex128_t b, double *Out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut );

Examples

#include "stdlib/blas/base/zrotg.h"
#include "stdlib/complex/float64/ctor.h"
#include <stdio.h>

int main( void ) {
    // Specify rotational elimination parameters:
    const stdlib_complex128_t a = stdlib_complex128( 4.0, 3.0 );
    const stdlib_complex128_t b = stdlib_complex128( 0.0, 0.0 );
    int i;

    // Create output array:
    double Out[ 5 ];

    // Specify stride length:
    const int strideOut = 1;

    // Apply plane rotation:
    c_zrotg( a, b, Out, strideOut );

    // Print the result:
    for ( i = 0; i < 5; i++ ) {
        printf( "Out[%d] = %lf\n", i, Out[ i ] );
    }

    // Apply plane rotation using alternative indexing semantics:
    c_zrotg_assign( a, b, Out, strideOut, 0 );

    // Print the result:
    for ( i = 0; i < 5; i++ ) {
        printf( "Out[%d] = %lf\n", i, Out[ i ] );
    }
}