Package SF1626

version 2011-03-18
Göran Andersson, goeran@kth.se

Read Me

This package contain some useful methods for the multi-variable calculus course SF1626 at KTH. The package is free ware.

Installation (only once)

Copy this notebook (SF1626.nb) and the package file (SF1626.m) to the same directory. Then reopen this notebook from this directory.

If you have a previous version of the package installed, remove the old package with the following command:

DeleteFile[FileNameJoin[{$UserAddOnsDirectory,"Applications","SF1626.m"}]]

Install the (new) package with the following command:

With[{
curDir=NotebookDirectory[],
appDir=FileNameJoin[{$UserAddOnsDirectory,"Applications"}],
package="SF1626.m"
},
If[!DirectoryQ[appDir],CreateDirectory[appDir]];
CopyFile[FileNameJoin[{curDir,package}],FileNameJoin[{appDir,package}]]
]

Loading Package (every new session)

When the package is installed start your Mathematica session by loading the package with

Needs["SF1626`"]

In order the avoid symbol hiding, it is important to begin with this command before you use any method in the package. The Needs command is ignored if the package is already loaded.

Package content

Needs["SF1626`"]

The package contains following methods:

?SF1626`*

Just input ?method in order to get syntax help, e.g.

?Taylor

Taylor[(x/(Sqrt[(x^2)+(y^2)+1])),{x,y},{0,0},5]

CompleteSquare

Always load the package before you use the methods of the package.

Needs["SF1626`"]

?CompleteSquare

The following command completes a single variable polynomial:

CompleteSquare[(x^2)+3x+3,x]

By this we can see that the minimum value is 3/4. And here’s a general quadratic polynomial:

CompleteSquare[a (x^2)+b x+c,x]

Here’s a polynomial that has two variables try:

CompleteSquare[(x^2)+(y^2)+4x+2y+6,{x,y}]

It he case of multi-variable polynomial the CompleteSquare is Folded. This means that the result might depend on the order of the given variables.

p=(x^2)+2(y^2)+4x+2x y+y+6;
CompleteSquare[p,{x,y}]

CompleteSquare[p,{y,x}]

A quadratic form is a special case of polynomial:

q=2 (x^2)-4 x y-4 (y^2);
QuadraticFormQ[q,{x,y}]

CompleteSquare[q,{y,x}]

Notice that the result depends on the order of the given variables:

CompleteSquare[q,{x,y}]

We finish by a quadratic form with 3 variables

CompleteSquare[(x^2)-(y^2)-(z^2)+2 x y+4 y z,{x,y,z}]

CompleteSquare[(x^2)-(y^2)-(z^2)+2 x y+4 y z,{z,x,y}]

SymmetricMatrix

Needs["SF1626`"]

?SymmetricMatrix

The symmetric matrix can be used to determine the type of a quadratic form.

q=2 (x^2)-4 x y-4 (y^2);

MatrixForm[
𝕄=SymmetricMatrix[q,{x,y}]
]

IndefiniteMatrixQ[𝕄]

We can also verify this by completing the quadratic form

CompleteSquare[q,{x,y}]

The quadratic form can be constructed from the symmetric matrix:

𝕣={x,y};
Expand[𝕣.𝕄.𝕣]

Notice that if 𝕩 is a vector and 𝔸 is a matrix then 𝔸·𝕩 is a vector. If 𝕏 is a matrix then 𝔸·𝕏 is a matrix.

{{1,2},{3,4}}.{x,y}

{{1,2},{3,4}}.{{x},{y}}

Taylor

Needs["SF1626`"]

The built-in method Series gives nested single variable expansion. Taylor gives a truncated multi-variable expansion of order n.

?Taylor

Here’s an example:

Taylor[(Sqrt[1+x+(y^2)]),{x,y},{0,0},4]

A general expansion:

Taylor[g[a+h,b+k],{h,k},{0,0},3]

We finish by an expansion of a function of three variables:

𝕣={x,y,z}; 𝕣1={1,0,0};𝕣2={-1,0,2};𝕣3={2,1,-1};
𝕠={0,0,0};𝕙={𝒽,𝓀,ℓ};
f[{x_,y_,z_}]:=Evaluate[(1/((𝕣-𝕣1).(𝕣-𝕣1)+1))+(1/((𝕣-𝕣2).(𝕣-𝕣2)+2))+(1/((𝕣-𝕣3).(𝕣-𝕣3)+3))]

Looking at the expression we can assume that there is a local extreme (where ∇f=0) around (Subscript[𝕣, 1]).

(∇f)[{x_,y_,z_}]:=Evaluate[D[f[𝕣],{𝕣}]]

𝕣0=𝕣/.FindRoot[(∇f)[𝕣]==𝕠,{𝕣,𝕣1}]

The expansion now gives (notice that the first derivatives are 0).

Taylor[f[𝕣0+𝕙],𝕙,𝕠,2]//Chop

and the quadratic form is:

q=Taylor[f[𝕣0+𝕙],𝕙,𝕠,2]-f[𝕣0]//Chop

CompleteSquare[q,𝕙]

We can see that the quadratic form is negative definite. Then (Subscript[𝕣, 1]) corresponds to a local maximum. We can of course find this with Mathematica methods directly:

FindMaximum[f[𝕣],{𝕣,𝕣1}]

Q - methods

Needs["SF1626`"]

?SF1626`*Q

The use of the Q-methods is straight forward. They all return a boolean.

?QuadraticFormQ

QuadraticFormQ[(x^2)-(y^2)+2x y,{x,y}]

QuadraticFormQ[(x^2)-(y^2)+2x ,{x,y}]

The matrix query method work on a Hermitian (symmetric) matrices.

IndefiniteMatrixQ[(({{1, 2, 3}, {2, 4, 5}, {3, 5, 6}}))]

Notice that the method PositiveDefiniteMatrixQ is a not a package method, it is a built-in method.

PositiveDefiniteMatrixQ[(({{4, 0, 0}, {0, 3, 1}, {0, 1, 2}}))]

Here’s a suggestion of how to create a method that determines the type of a quadratic form:

quadraticFormType[q_,x_]/;QuadraticFormQ[q,x]:=
With[
{m=SymmetricMatrix[q,x]},
Which[
PositiveDefiniteMatrixQ[m],"positive definite",
NegativeDefiniteMatrixQ[m],"negative definite",
PositiveSemidefiniteMatrixQ[m],"positive semi-definite",
NegativeSemidefiniteMatrixQ[m],"negative semi-definite",
IndefiniteMatrixQ[m],"indefinite",
True,"unclassified"
]
];
quadraticFormType[___]:="not a quadratic form";

quadraticFormType[2 (x^2)-4 x y-4 (y^2),{x,y}]

quadraticFormType[2 (x^2)-4 x y+4 (y^2),{x,y}]

quadraticFormType[(((x-1))^2)+(y^2),{x,y}]