Documentation

linalg::scalarProduct

Scalar product of vectors

MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

Syntax

linalg::scalarProduct(u, v, <Real>)

Description

linalg::scalarProduct(u, v) computes the scalar product of the vectors and with respect to the standard basis, i.e., the sum .

The scalar product is also called “inner product” or “dot product”.

If the component ring of the vectors u and v does not define the entry "conjugate" or if the option Real is specified, then linalg::scalarProduct uses the definition u1v1 + … + unvn of the scalar product.

The vectors u and v must be defined over the same component ring.

linalg::scalarProduct can be redefined to a different scalar product. This also affects the behaviour of functions such as linalg::angle, linalg::factorQR, linalg::isUnitary, norm (for vectors and matrices), linalg::orthog and linalg::pseudoInverse depend on the definition of linalg::scalarProduct. See Example 3.

Environment Interactions

Properties of identifiers are taken into account.

Examples

Example 1

We compute the scalar product of the vectors (i, 1) and (1, - i):

MatC := Dom::Matrix(Dom::Complex):
u := MatC([I, 1]): v := MatC([1, -I]):
linalg::scalarProduct(u, v) Example 2

We compute the scalar product of the vectors and with the symbolic entries u1, u2, v1, v2 over the standard component ring for matrices:

delete u1, u2, v1, v2:
u := matrix([u1, u2]): v := matrix([v1, v2]):
linalg::scalarProduct(u, v) You can use assume to tell the system that the symbolic components are to represent real numbers:

assume([u1, u2, v1, v2], Type::Real):

Then the scalar product of and simplifies to:

linalg::scalarProduct(u, v) Alternatively, the option Real can be specified:

unassume(u1, u2, v1, v2):
linalg::scalarProduct(u, v, Real) Example 3

One particular scalar product in the real vector space of continuous functions on the interval [0, 1] is defined by .

To compute an orthogonal basis corresponding to the polynomial basis 1, t, t2, t3, … with respect to this scalar product, we replace the standard scalar product by the following procedure:

standardScalarProduct := linalg::scalarProduct:
unprotect(linalg):
linalg::scalarProduct := proc(u, v)
local F, f, t;
begin
// (0)
f := expr(u * v);

// (1)
t := indets(f);
if t = {} then t := genident("t") else t := op(t, 1) end_if;

// (2)
F := int(f, t = 0..1);

// (3)
u::dom::coeffRing::coerce(F)
end:

We start with step (0) to convert f(t) g(t) to an expression of a basic domain type, such that the system function int in step (2) can handle its input (this is not necessary if the elements of the component ring of the vectors are already represented by elements of basic domains).

Step (1) extracts the indeterminate of the polynomials, step (2) computes the scalar product as defined above and step (3) converts the result back to an element of the component ring of vectors u and v.

Note that we need to unprotect the write protected identifier linalg, otherwise the assignment would lead to an error message.

We next create the matrix which consists of the first five of the above polynomials:

P := matrix([[1, t, t^2, t^3, t^4]]) If we now perform the Gram-Schmidt orthogonalization procedure on the columns of P with the function linalg::orthog, we get:

S := linalg::orthog(linalg::col(P, 1..4)) Each vector in S is orthogonal to the other vectors in S with respect to the modified scalar product. We check this for the first vector:

linalg::scalarProduct(S, S[j]) \$ j = 2..nops(S) Finally, we undo the redefinition of the scalar product, so as not to run into trouble with subsequent computations:

linalg::scalarProduct := standardScalarProduct:
protect(linalg, Error):

Parameters

 u, v Vectors of the same dimension (a vector is an n×1 or 1 ×n matrix of a domain of category Cat::Matrix)

Options

 Real Use u1 v1 + … + un vn as the definition of the scalar product, i.e., suppress the use of conjugate.

Return Values

Element of the component ring of u and v.