How to use the conj function from mathjs

Find comprehensive JavaScript mathjs.conj code examples handpicked from public code repositorys.

mathjs.conj is a function in the math.js library that computes the complex conjugate of a complex number.

13447
13448
13449
13450
13451
13452
13453
13454
13455
13456
var r = [];
var rowVal = this.state[row] || math.complex(0, 0);
for(var col = 0; col < numAmplitudes; col++) {
	var colVal = this.state[col] || math.complex(0, 0);
	if(colVal.re || colVal.im) {
		colVal = math.conj(colVal);
	}
	r.push(math.multiply(rowVal, colVal));
}
density.push(r);
fork icon43
star icon207
watch icon14

+ 157 other calls in file

71
72
73
74
75
76
77
78
79
80

function eta_left(w) {
    const z = w.neg();
    const zp1 = math.add(z, 1);

    if (z.im < 0) {return math.conj(eta_left(math.conj(w)));}


    let component_a = cmul(gamma(z), csin(cmul(z, math.pi/2)));
    if (z.im > 50) {
fork icon8
star icon29
watch icon3

+ 3 other calls in file

How does mathjs.conj work?

mathjs.conj is a function in the math.js library that computes the complex conjugate of a complex number. When you call mathjs.conj(), you pass in a complex number as a parameter. A complex number is a number of the form a + bi, where a and b are real numbers, and i is the imaginary unit (i.e., the square root of -1). The function then computes the complex conjugate of the input complex number, which is the complex number with the same real part and the negated imaginary part. In other words, if the input complex number is a + bi, the complex conjugate is a - bi. mathjs.conj() returns the complex conjugate of the input complex number as a new complex number. This function is useful for tasks that require manipulating complex numbers in JavaScript, such as in scientific or engineering applications. Overall, mathjs.conj provides a simple way to compute the complex conjugate of a complex number in JavaScript using the math.js library.

103
104
105
106
107
108
109
110
111
112
// Small z: https://math.stackexchange.com/questions/712434/erfaib-error-function-separate-into-real    -and-imaginary-part
// Large z: Custom expansion with Fresnel integral (centered around y=x).
// See https://samuelj.li/blog/2021-05-05-erf-expansion
function erf_large(z) {
    if (z.re < 0) {return erf_large(z.neg()).neg();}
    if (z.im < 0) {return math.conj(erf_large(math.conj(z)));}
    const TWO_SQRTPI = 1.1283791671;
    const W = math.complex(0.70710678118, 0.70710678118);
    const W_BAR = math.complex(0.70710678118, -0.70710678118);
    const rs = cmul(z, W_BAR);
fork icon8
star icon0
watch icon0

+ 31 other calls in file

Ai Example

1
2
3
4
5
6
7
8
9
const math = require("mathjs");

// Compute the complex conjugate of a complex number
const z = math.complex(3, 4);
const conjZ = math.conj(z);

// Log the original complex number and its complex conjugate to the console
console.log(`z = ${z}`);
console.log(`conj(z) = ${conjZ}`);

In this example, we use mathjs.conj to compute the complex conjugate of the complex number z = 3 + 4i. We create the complex number z using math.complex(), which takes the real and imaginary parts of the complex number as parameters. We then call math.conj() with z as a parameter to compute its complex conjugate. The function returns a new complex number conjZ. Finally, we log both the original complex number z and its complex conjugate conjZ to the console. Overall, mathjs.conj provides a simple way to compute the complex conjugate of a complex number in JavaScript using the math.js library.