Quick Start Guide
Table of Contents
1 Equations, Inequalities, and System of Equations
I. Simplify, Expand, Factor, and Compare Expressions
Expand an expression by "epd;expr" or "epd(expr)", factor an expression by "fac;expr" or "fac(expr)", and convert a decimal to a fraction by "fra;decimal" or fra(decimal). To simplify an expression, just enter the expression.
For complex numbers, type “I” for the imaginary unit, and use the expression “abs(a+b*I)” to calculate its magnitude. To evaluate if two expressions are equivalent, enter “f(x) == g(x)” or “f(x) – g(x) == 0”, where “f(x)” and “g(x)” may be functions or number expressions. The result is “True” if the two expressions are equivalent, and “False” otherwise. Similarly, the expressions such as “x > y”, “x < y”, "x >= y", "x <= y", "f(x) > g(x)" and so on compares two numbers or expressions to determine if one is greater or less than the other.
Table 1.1 Simplify, Expand, Factor, and Compare Expressions
Q: x+5>x A: True |
Q: e^pi>pi^e A: True |
Q: sin(0.1)< cos(0.1) A: True |
Q: log(.6)/log(.5)>log(.5)/log(.6) A: False |
Q: x^7-exp(7*log(x)) A: \(-x^7+x^7= 0\) |
Q: epd;(a+b)^5 A: Expand \((a+b)^5=5ab^4+10a^2b^3+10a^3b^2+5a^4b+a^5+b^5\) |
Q: fac;z^4-16 A: Factor \(z^4-16=(z-2)(2+2)(z^2+4)\) |
Q: fac;2*f(x)^2+f(x)*g(y) A: Factor \(2f^2(x)+f(x)g(y)=(2f(x)+g(y))f(x)\) |
Q: exp(I*pi) A: \(=-1\) |
Q: (cos(t)+I*sin(t))^9==exp(9*I*t) A: True |
Q: (2+5*I)^4+(2-5*I)^4 A: \(=82\) |
Q: abs(6+8*I) A: \(=10\) |
Q: sin(x)^2+cos(x)^2 A: \(\sin^2(x)+\cos^2(x)=1\) |
Q: cos(x-y)==cos(x)*cos(y)+sin(x)*sin(y) A: True |
Q: cos(asin(1/2)) A: \(=\frac{\sqrt{3}}{2}\) |
Q: (sinh(x)+cosh(x))^9 A: \((\sinh(x)+\cosh(x))^9=e^{9x}\) |
Q: (cos(t)+I*sin(t))^n A: \((i\sin(t)+\cos(t))^n=(e^{it})^n\) |
Q: gamma(53)/(gamma(6)*gamma(48)) A: \(=2598960\) |
II. Equations and Inequalities
At least three necessary elements are needed for solving an equation or inequality: The name "slv" for the operation, the expression of the equation or inequality, and the variable to be solved. The array of elements “slv; f(x); x” or “slv(f(x), x)” helps solving the equation f(x) = 0 for x. The arrays “slv; f(x) ≥ g(x); x”, “slv(f(x) ≤ g(x), x)”, “slv; f(x) > g(x); x”, and “slv; f(x) < g(x); x” find the intervals (or values) of x such that the corresponding inequality is satisfied.
In case an equation is expressed in form of f(x) = g(x), rewrite it as f(x) – g(x) = 0, and enter “slv; f(x) - g(x); x” for solution x.
Additional options can be added to the function “slv(f(x), x)”. For instance, “slv(f(x), x, C)” or “slv; f(x); x; C” finds the complex roots of f(x) = 0, where the keyword “C” is for complex roots.
Table 1.2 Solve Equations and Inequalities by “slv” Operation
Q: slv;(x^4-16)/(x^2+2*x-8);x A: Solve \(\frac{x^4-16}{x^2+2x-8}=0\) for \(x=\{-2\}\) |
Q: slv(x^4-x^2+1,x,C) A: \(=\left\{-\frac{\sqrt{3}}{2}-\frac{i}{2},-\frac{\sqrt{3}}{2}+\frac{i}{2},\frac{\sqrt{3}}{2}-\frac{i}{2}, \frac{\sqrt{3}}{2}+\frac{i}{2}\right\}\) |
Q: slv;abs(3*y/2+4)>1;y A: Solve abs\((\frac{3y}{2}+4)>1\) for \(y=(−∞,−\frac{10}{3})∪(−2,∞)\) |
Q: slv(abs(a-1)< abs(3*a-5),a) A: \(a=(−∞,\frac{3}{2})∪(2,∞)\) |
Q: slv;1/(z-2)>4/(z+3);z A: Solve \(\frac{1}{z−2}>\frac{4}{z+3}\) for \(z=(−∞,−3)∪(2,\frac{11}{3})\) |
Q: slv;abs(z^2-2*z-3);z A: Solve \(|z^2-2z-3|=0\) for \(z=\{-1,3\}\) |
Q: slv;abs(2-3*w)<=4;w A: Solve abs\((2−3w)≤4\) for \(w=[−\frac{2}{3},2]\) |
Q: slv;1/t<2*t/(t-5);t A: Solve \(\frac{1}{t}<\frac{2t}{t−5}\) for \(t=(−∞,0)∪(5,∞)\) |
Q: slv;abs(x^2-x-6)-(x-1);x A: \(x=\{\sqrt{7},1+\sqrt{6}\}\) |
Q: slv;2*log(b)-3;b A: Solve \(2\log(b)−3=0\) for \(b=\{e^{\frac{3}{2}}\}\) |
Q: slv;exp(-2*v)-5;v A: Solve \(−5+e^{−2v}=0\) for \(v=\{−\frac{\log(5)}{2}\}\) |
Q: slv;2*sin(t)+cos(t)-1;t A: \(t=\{2nπ|n∈Z\}∪\{2nπ−\text{atan}(\frac{4}{3})+π∣n∈Z\}\) |
Q: slv;3*asin(x)-2*pi;x A: Solve \(3\text{asin}(x)−2π=0\) for \(x=\{\frac{\sqrt{3}}{2}\}\) |
Q: slv;u^4-u^2-2;u;C A: Solve \(u^4-u^2-2=0\) for \(u=\{-\sqrt{2},\sqrt{2},-i,i\}\) |
III. Systems of Equations
The array "eqs(f(x, y), g(x, y))" or "eqs; f(x, y); g(x, y); x; y" helps solving a system of two equations f(x, y) = 0 and g(x, y) = 0 for the unknowns x and y, and displays the solutions in an alphabetical order.
By default, the operation “eqs” gives the solutions to all unknowns in the system. If particular variables to be solved are specified at the end such as "eqs(f(x, y), g(x, y), x, y)", other variables in the equations are treated as constants.
The array “eqs; f(x, y, z); g(x, y, z); h(x, y, z); x; y; z” or “eqs(f(x, y, z), g(x, y, z), h(x, y, z), x, y, z)” helps solving a system of three equations, where variables x, y, and z are optional unless there are additional variables in the system. Following the same pattern, use “eqs” for solving a system of four or more equations.
Example 1 Solve the linear system \(x + y + z = u + 1, 2x + y + z = 3u - 1, 3x - 2y + 2 = u,\) and \(x - y + 5z = 2u + 5\).
A: Solve \([−u+x+y+z−1=0, −3u+2x+y+z+1=0, −u+3x−2y+2=0,\)\(−2u+x−y+5z−5=0]\) for \((u,x,y,z)=(1, 0, \frac{1}{2}, \frac{3}{2})\)
Example 2 Solve the nonlinear system of equations \(x^2-y^2=a\) and \(x^2+y^2=31\).
A: Solve \([x^2−y^2−1=0, x^2+y^2−31=0]\) for \((x,y)=\{(−4, −\sqrt{15}),(−4, \sqrt{15}),(4, −\sqrt{15}),(4, \sqrt{15})\}\)
Example 3 Solve the nonlinear system by \(u^2-v^2=6\) and \(u^2-3v^2+4=0\).
A: Solve \([u^2−v^2−6=0, 2u^2−3v^2+4=0]\) for \((u,v)=\{(−\sqrt{22}, −4),(−\sqrt{22}, 4),(\sqrt{22}, −4),(\sqrt{22}, 4)\}\)
2 Limits
I. Limits (One-Sided, Finite and Infinite Limits, and Limits at Infinity)
Use the array of four elements "lim; f(x); x; c" or "lim(f(x), x, c, n/p)" to determine the limit of a function f(x) as x approaches c, where 'lim' is the operation name, 'f(x)' the function expression, 'x' the independent variable, and 'c' is the value that 'x' approaches.
The default limit is two-sided. For one-sided limits, add the keyword 'n' (for negative '-' or left side) or 'p' (for positive '+' or right side) to the end, so the array become “lim; f(x); x; c; n” or “lim; f(x); x; c; p”.
To find limit at infinity, enter 'oo' for infinity \(∞\) and '-oo' for \(-∞\). In addition, "pi" stands for the number π, and "e" or "E" for the number \(e\).
Table 2.1: Determine Limits of Functions by “lim” Operation
Q: lim((1+1/n)^n,n,oo) A: \(=e\) |
Q: lim(sin(x)/x,x,0) A: \(=1\) |
Q: lim(abs(x)/x,x,0,n) A: \(\lim\limits_{x\to 0^−}\frac{|x|}{x} =−1\) |
Q: lim((z^8-9^8)/(z^7-9^7),z,9) A: \(=\frac{72}{7}\) |
Q: lim;(2*x-3)/(x^2-2*x-1)^(1/2);x;-oo A: \(\lim\limits_{x\to−∞}\frac{2x−3}{\sqrt{x^2−2x−1}} =−2\) |
Q: lim;floor(x);x;2;p A: \(\lim\limits_{x\to2^+}⌊x⌋=2\) |
Q: lim(ceiling(x),x,-3,n) A: \(\lim\limits_{x→−3^−}⌈x⌉ =−3\) |
Q: 2*lim(tan(2*x)/sin(3*x),x,0)-3*lim(y^y,y,0,p)/(4*lim(atan(t),t,-oo)) A: \(=\frac{9+8π}{6π}\) |
Q: lim;sin(x);x;oo A: \(\lim\limits_{x→∞}\sin(x)=⟨−1,1⟩\) |
Q: lim;1/x;x;0 A: \(\lim\limits_{x→0}\frac{1}{x}=\tilde{∞}\) |
Q: lim(c,x,-oo) A: \(=c\) |
Q: lim;abs(x)/x;x;0 A: \(\lim\limits_{x→0}\frac{|x|}{x}=\) undefined |
II. Properties and Formal Definition of Limit
The expression “a*lim(f(x),x,c)+b*lim(g(x),x,c)-lim(a*f(x)+b*g(x),x,c)” yields a result of 0, which verifies the linearity property \(\displaystyle\lim_{x→c}[af(x)+bg(x)]= a\lim_{x→c}f(x)+b\lim_{x→c}g(x)\).
A: \(=0\)
To verify the formal definition of limit, one needs to find the corresponding δ interval for a given ε value by the array “lim; f(x); x; c; ε”, or “lim; f(x); x; c; n/p; ε” for one-sided limits.
Table 2.2: Verify Properties and Formal Definition of Limit by “lim” Operation
Q: lim;1/n**2;n;oo;p;0.001 A: \(\lim\limits_{n→∞}\frac{1}{n^2}=0; ∣n^{−2}∣<0.001\) if \(n∈(31.6227766016838,∞)\) |
Q: lim;1/2**n;n;oo;p;0.000001 A: \(\lim\limits_{n→∞}2^{−n}=0; |2−n|<1e−06\) if \(n∈(\frac{13.8155105579643}{\log(2)},∞)\) |
Q: lim;1/x;x;-oo;0.001 A: \(\lim\limits_{x→−∞}\frac{1}{x}=0; ∣x^{−1}∣<0.001\) if \(x∈(−∞,−1000.0)\) |
Q: lim;2/(3-z);z;3;p;-500 A: \(\lim\limits_{z→3^+}\frac{2}{3-z}=−∞; \frac{2}{(3−z)}<−500.0\) if \(z∈(3,3.004)\) |
Q: lim;1/x;x;0;p;1000000 A: \(\lim\limits_{x→0^+}\frac{1}{x}=∞; 1000000.0< x−1\) if \(x∈(0,1.0⋅10^{−6})\) |
Q: lim;log(1+u);u;0;0.01 A: \(\lim\limits_{u→0}\log(u+1)=0; |\log(1+u)|<0.01\) if \(u∈(−0.00995016625083189,0.0100501670841679)\) |
III. Derivatives by Limits
Derivative is defined by limit, and thus one can verify some derivative formulas using the “lim” operation.
Table 2.3: Verify Derivatives Formulas by “lim” Operation
Q: lim;(f(x+h)-f(x))/h;h;0 A: \(\lim\limits_{h→0}\frac{−f(x)+f(h+x)}{h}=\frac{d}{dx}f(x)\) |
Q: lim;(f(x)-f(c))/(x-c);x;c A: \(\lim\limits_{x→c}\frac{f(x)-f(c)}{x-c}=\frac{d}{dc}f(c)\) |
Q: lim((a^(x+h)-a^x)/h,h,0) A: \(=a^x\log(a)\) |
Q: lim((2^(x+h)-2^x)/h,h,0) A: \(=2^x\log(2)\) |
Q: lim((x^(2/3)-c^(2/3))/(x-c),x,c) A: \(=\frac{2}{3\sqrt[3]{c}}\) |
Q: lim(((8+h)^(2/3)-8^(2/3))/h,h,0) A: \(=\frac{1}{3}\) |
Q: lim;(sin(x)-sin(0))/x;x;0 A: \(\lim\limits_{x→0}\frac{\sin(x)}{x}=1\) |
Q: lim;(exp(x+h)-exp(x))/h;h;0 A: \(\lim\limits_{h→0}\frac{−e^x+e^{h+x}}{h}=e^x\) |
Q: lim;(tan(pi/4+h)-1)/h;h;0 A: \(\lim\limits_{h→0}\frac{\tan(h+\frac{π}{4})−1}{h}=2\) |
Q: lim;(f(a+h,b)-f(a,b))/h;h;0 A: \(\lim\limits_{h→0}\frac{−f(a,b)+f(a+h,b)}{h}=\frac{∂}{∂a}f(a,b)\) |
Q: lim;(f(a,b+h)-f(a,b))/h;h;0 A: \(\lim\limits_{h→0}\frac{−f(a,b)+f(a,b+h)}{h}=\frac{∂}{∂b}f(a,b)\) |
Q: lim;((x+h)^2-x^2)/h;h;0 A: \(\lim\limits_{h→0}h+2x=2x\) |
IV. Find Limits of Vector Functions
For the limit of a vector function, express the vector as a linear combination of the standard basis vectors i, j and k , and then use the “lim” operation by treating it as a scalar function.
Table 2.4: Limits of Vector-Valued Functions by “lim” Operation
Q: lim;cos(t)*i+exp(-t)*j-(1+t)^(-2)*k;t;0 A: \(\lim\limits_{t→0}i\cos(t)+je^{−t}−\frac{k}{(t+1)^2}=i+j−k\) |
Q: lim;sin(u)*i+cos(u)*j+u*k;u;pi/2 A: \(\lim\limits_{u→\frac{π}{2}}i\sin(u)+j\cos(u)+ku=i+\frac{πk}{2}\) |
V. Improper Integrals by Limits
One can evaluate improper integrals by definition using "lim" and “itg” operations.
Table 2.5: Evaluate Improper Integrals by “lim” and “itg” Operations
Q: lim(itg(exp(-x),x,0,a),a,oo) A: \(=1\) |
Q: lim(itg(1/x,x,a,1),a,0,p) A: \(=∞\) |
Q: lim(itg(1/x**(2/3),x,a,1),a,0,p) A: \(=3\) |
Q: lim(itg(1/x**3,x,b,1),b,0,p) A: \(=∞\) |
VI. Graphs of Functions and Equations
Click here for plotting graphs of functions and equations in 2D plane and 3D space.3 Differentiation
I. Derivatives of Single-Variable Functions
(1) Derivative Functions
The array “dif; f(x); x” or “dif(f(x), x)” calculates the derivative of a function f(x) with respect to x, where “dif” is the operation name, “f(x)” is the function expression, and “x” is the variable to which the derivative is taken. By default, the operation returns the first derivative. For the \(n\)th order derivatives of f(x), use “dif; f(x); x; n”, where "n" is a positive integer. The "dif" function uses a few more optional parameters for finding derivatives at a particular value, linear approximation, extreme values of functions, and partial derivatives.
Table 3.1: Find Derivatives by “dif” Operation
Q: dif;a*f(x)+b*g(x);x A: \(\frac{∂}{∂x}(af(x)+bg(x))=a\frac{d}{dx}f(x)+b\frac{d}{dx}g(x)\) |
Q: dif;f(g(x));x A: \(\frac{d}{dx}f(g(x))=\frac{d}{dx}g(x)\frac{d}{dg(x)}f(g(x))\) |
Q: dif;f(x)/g(x);x A: \(\frac{d}{dx}\frac{f(x)}{g(x)}=\frac{(−f(x)\frac{d}{dx}g(x)+g(x)\frac{d}{dx}f(x))}{g(x)^2}\) |
Q: dif;x*f(x)^n;x A: \(\frac{∂}{∂x}xf^n(x)=nxf(x)^{−1+n}\frac{d}{dx}f(x)+f(x)^n\) |
Q: dif;a^(f(x));x A: \(\frac{∂}{∂x}a^{f(x)}=a^{f(x)}\log(a)\frac{d}{dx}f(x)\) |
Q: dif;f(x)^(g(x));x A: \(\frac{d}{dx}f^{g(x)}(x)=f(x)^{−1+g(x)}(g(x)\frac{d}{dx}f(x)+f(x)\log(f(x))\frac{d}{dx}g(x))\) |
Q: dif;log(f(x));x A: \(\frac{d}{dx}\log(f(x))=\frac{\frac{d}{dx}f(x)}{f(x)}\) |
Q: dif;((h^3-3)/(2*h^2+1))^2;h;2 A: \(\frac{d^2}{dh^2}\frac{(h^3−3)^2}{(2h^2+1)^2}=\frac{2(−36−18h+360h^2+96h^3+15h^4−24h^5+8h^6+4h^8)} {(1+8h^2+24h^4+32h^6+16h^8)}\) |
Q: dif;L/(1-A*exp(-k*t));t;2 A: \(\frac{∂^2}{∂t^2}\frac{L}{−Ae^{−kt}+1}=\frac{−ALk^2e^{kt}(A+e^{kt})}{(A−e^{kt})^3}\) |
Q: dif;cos(t)*exp(t);t A: \(\frac{d}{dt}e^t\cos(t)=\sqrt{2}e^t\cos(t+(\frac{1}{4})π)\) |
Q: dif;(x+2)^(60);x A: \(\frac{d}{dx}(x+2)^{60}=60(2+x)^{59}\) |
Q: dif;c/(c^2+8)^(1/2);c;2 A: \(\frac{d^2}{dc^2}\frac{c}{\sqrt{c^2+8}}=\frac{−24c}{(8+c^2)^{\frac{5}{2}}}\) |
Q: dif;log(x)/x;x;4 A: \(\frac{d^4}{dx^4}\frac{\log(x)}{x}=\frac{2(−25+12\log(x))}{x^5}\) |
Q: dif;1/(y+1);y;14 A: \(\frac{d^{14}}{dy^{14}}\frac{1}{y+1}=\frac{87178291200}{(1+y)^{15}}\) |
Q: dif;sin(v);v;15 A: \(\frac{d^{15}}{dv^{15}}\sin(v)=−\cos(v)\) |
Q: dif;exp(-z);z;16 A: \(\frac{d^{16}}{dz^{16}}e^{−z}=e^{−z}\) |
(2) Slopes, Rates of Change, Equations of Tangent Lines
To evaluate the derivative of f(x) at x = c, add the keyword “rt” (rate) followed by value c to the "dif" function, making the array as “dif; f(x); x; n; rt; c”. For instance, “dif(f(x), x, 1, rt, c)” or “dif; f(x); x; 1; rt; c” finds the slope of the tangent line to the curve y = f(x) at x = c, and “dif(f(x), x, 1, tn, c)” or “dif; f(x); x; 1; tn; c” determines the equation of the tangent line.
Table 3.2: Rates of Change, Slopes, and Equations of Tangent Lines by “dif” Operation
Q: dif;(x-2)^2*(x+3)/5;x;1;rt;0 A: \(\frac{d}{dx}\frac{(x−2)^2(x+3)}{5}=\frac{(−2+x)(4+3x)}{5};\frac{d}{dx}\frac{(x−2)^2(x+3)}{5}|_{x=0}=\frac{−8}{5}\) |
Q: dif;(x-2)^2*(x+3)/5;x;1;tn;0 A: \(\frac{d}{dx}\frac{(x−2)^2(x+3)}{5}=\frac{(−2+x)(4+3x)}{5};\frac{d}{dx}\frac{(x−2)^2(x+3)}{5}|_{x=0}=\frac{−8}{5}\); tangent line \(L(x)=\frac{12}{5}+(\frac{−8}{5})x\) |
Q: dif;(2*x^2+1)^(1/2);x;1;tn;2 A: \(\frac{d}{dx}\sqrt{2x^2+1}=\frac{2x}{\sqrt{1+2x^2}};\frac{d}{dx}\sqrt{2x^2+1}|_{x=2}=\frac{4}{3}\); tangent line \(L(x)=\frac{1}{3}+(\frac{4}{3})x\) |
Q: dif;s/(1+s^2)^(1/2);s;1;tn;-1 A: \(\frac{d}{ds}\frac{s}{\sqrt{s^2+1}}=(1+s^2)^{\frac{−3}{2}};\frac{d}{ds}\frac{s}{\sqrt{s^2+1}}|_{s=−1}=\frac{\sqrt{2}}{4}\); tangent line \(L(s)=\frac{\sqrt{2}(−1+x)}{4}\) |
Q: dif;x*exp(x);x;1;tn;-2 A: \(\frac{d}{dx}xe^x=e^x(1+x);\frac{d}{dx}xe^x|_{x=−2}=−e^{−2}\); tangent line \(L(x)=−e^{−2}(4+x)\) |
(3) Differentials and Linearization
The array "dif; f(x); x; 1; df; c; dx" or "dif(f(x), x, 1, df, c, dx)" approximates f(x) at x close to c, where keyword "df" is for differential, "c" is a value (tangency point at x = c), and "dx" is an increment (or small change Δx). The result from "dif(f(x), x, 1, df, c, dx)" gives a linear approximation of the function value f(c + dx).
Table 3.3: Differentials and Linearization by “dif” Operation
Estimate sec(58°) | Q: dif;sec(x);x;1;df;pi/3;-pi/90 A: \(Δf≈df=−\frac{\sqrt{3}π}{45};f(\frac{29π}{90})≈1.87908004\) |
Estimate \(e^{0.1}\) | Q: dif;exp(x);x;1;df;0;0.1 A: \(Δf≈df=0.1;f(0.1)≈1.1\) |
Estimate \(25.8^{\frac{2}{3}}\) | Q: dif;x^(2/3);x;1;df;27;-1.2 A: \(Δf≈df=−0.266666666666667;f(25.8)≈8.73333333\) |
(4) Monotonicity, Concavity, and Extreme Values
One can determine the interval on which a function f(x) is increasing by “dif; f(x); x; 1; ic” and decreasing by “dif; f(x); x; 1; dc”; determine the interval on which f(x) is concave up by “dif; f(x); x; 2; cu” and concave down by “dif; f(x); x; 2; cd”. Using the keywords “cp” and “ip”, one can find possible critical numbers of f(x) by “dif; f(x); x; 1; cp”, and find inflection points by “dif; f(x); x; 2; ip”. The results from these operations can be used to determine the extreme values for f(x).
Conceptually, “dif;f(x);x;1;cp” equals "slv(dif(f(x),x),x)", “dif;f(x);x;1;dc” equals "slv(dif(f(x),x)<0,x)", “dif;f(x);x;1;ic” equals "slv(dif(f(x),x)>0,x)", “dif;f(x);x;1;ip” equals "slv(dif(f(x),x,2),x)", “dif;f(x);x;2;cu” equals "slv(dif(f(x),x,2)>0,x)", and “dif;f(x);x;2;cd” equals "slv(dif(f(x),x)<0,x)".
For example, let \(f(x)=\frac{x^2}{x-2}\). First, locate possible critical numbers of f(x) by array “dif;x^2/(x-2);x;1;cp”, which gives x = {0, 4}.
A: \(\frac{d}{dx}\frac{x^2}{x−2}=\frac{x(−4+x)}{4−4x+x^2}; \frac{x^2}{−2+x}\) has critical number(s) \(x=\{0,4\}\)
The second derivative test by “dif;x^2/(x-2);x;2;cu” and “dif;x^2/(x-2);x;2;cd” indicates g(x) is concave up on \((2, ∞)\) and down on \((-∞, 2)\), which implies f''(4) > 0, f''(0) < 0. Thus, f(4) = 8 is a relative minimum, and f(0) = 0 is a local maximum.
Q: dif;x^2/(x-2);x;2;cu A: \(\frac{d^2}{dx^2}\frac{x^2}{x−2}=\frac{8}{−8+12x−6x^2+x^3};\frac{x^2}{−2+x}\) concave up on \((2,∞)\) |
Q: dif;x^2/(x-2);x;2;cd A: \(\frac{d^2}{dx^2}\frac{x^2}{x−2}=\frac{8}{−8+12x−6x^2+x^3};\frac{x^2}{−2+x}\) concave down on \((-∞,2)\) |
Table 3.4: Monotonicity and Concavity, and Extreme Values by “dif” Operation
Q: dif;x^3-8*x^2;x;1;dc A: \(\frac{d}{dx}(x^3−8x^2)=x(−16+3x); −8x^2+x^3\) decreases on \((0,\frac{16}{3})\) |
Q: dif;x-x^3;x;2;cd A: \(\frac{d^2}{dx^2}(−x^3+x)=−6x;x−x^3\) concave down on \((0,∞)\)\) |
Q: dif;u/(1+u^2);u;2;cu A: \(\frac{d^2}{du^2}\frac{u}{u^2+1}=\frac{2u(−3+u^2)}{(1+u2)^3}; \frac{u}{1+u^2}\) concave up on \((−\sqrt{3},0)∪(\sqrt{3},∞)\) |
Q: dif;cosh(t);t;2;cu A: \(\frac{d^2}{dt^2}\cosh(t)=\cosh(t); \cosh(t)\) concave up on \(R\) |
Q: dif;s^2*exp(-s);s;2;ip A: \(\frac{d^2}{ds^2}s^2e^{−s}=e^{−s}(2−4s+s^2); s^2e^{−s}\) has inflection point \(s=\{2−\sqrt{2},2+\sqrt{2}\}\) |
Q: dif; x^4-9*x^3+30*x^2-44*x+24;x;1;cp A: \(\frac{d}{dx}(x^4−9x^3+30x^2−44x+24)=-44+60x−27x^2+4x^3; 24−44x+30x^2−9x^3+x^4\) has critical number(s) \(x=\{2,\frac{11}{4}\}\) |
Q: dif;x^3/5+11*x^2/10-4*x/5-8;x;1;ic A: \(\frac{d}{dx}(\frac{x^3}{5}+\frac{11x^2}{10}−\frac{4x}{5}−8)=\frac{−4}{5}+(\frac{11}{5})x+(\frac{3}{5})x^2 ; −8+(\frac{−4}{5})x+(\frac{11}{10})x^2+(\frac{1}{5})x^3\) increases on \((−∞,−4)∪(\frac{1}{3},∞)\) |
(5) Expressions for Differential Equations
Differential equations involve derivatives of unknown functions, and the function "dif" can be used to express a differential equation with different orders. For instance, "dif(g(x), x, 2)-2*dif(g(x), x) - 3" represents the differential equation g''(x) - 2g'(x) - 3 = 0, and "ode(dif(g(x), x, 2)-2*dif(g(x), x) -3)" finds the general solution to the unknown function g(x). Refer to Section (8) "Differential Equations" for more details on the "ode" function.
II. Implicit Differentiation
Suppose y is implicitly defined by x in f(x, y) = 0. To find the \(n\)th order implicit differentiation of y to x, use “idf; f(x, y); x; y; n”. By default n = 1, and it is optional.
To evaluate implicit derivatives at a given point (x0, y0), add the values "x0" (for "x") and "y0" (for "y") to the end, making the array as "idf; f(x, y); x; y; n; x0, y0" or "idf(f(x, y), x, y, n, x0, y0)".
Related Rates In case both x and y are functions of t, x'(t) and y'(t) are related rates, because the functions x and y are related in the equation f(x(t), y(t)) = 0. Use implicit differentiation "idf;f(x(t), y(t)); t; x" for x'(t), and "idf;f(x(t), y(t)); t; y" for y'(t). Specifying “x” as “x(t)” and “y” as “y(t)” in the operation is required because both are functions of “t”. Otherwise, “x” and “y” would be treated as constants.
For instance, if y(x) and z(x) are related in x + 2y - 3z = 7, obtain y'(x) by “idf;x+2*y(x)-3*z(x)-7;x;y” and z'(x) by “idf;x+2*y(x)-3*z(x)-7;x;z”.
Q: idf;x+2*y(x)-3*z(x)-7;x;y A: \(\frac{d}{dx}y=\frac{3\frac{d}{dx}z(x)}{2}−\frac{1}{2}\) |
Q: idf;x+2*y(x)-3*z(x)-7;x;z A: \(\frac{d}{dx}z=\frac{2\frac{d}{dx}y(x)}{3}+\frac{1}{3}\) |
Table 3.5: Implicit Differentiation by “idf” Operation
Q: idf;x^2+x*y+y^2-1;x;y A: \(\frac{d}{dx}y=-\frac{2x+y}{x+2y}\) |
Q: idf;x^2+x*y+y^2-1;x;y;2 A: \(\frac{d^2}{dx^2}y=-\frac{3x(2x+y)+3y(x+2y)(x+2y)}{x^2+4xy+4y^2}\) |
Q: idf;x^2+x*y+y^2-1;x;y;1;0;1 A: \(\frac{d}{dx}y|_{(0,1)}=\frac{−1}{2}\) |
Q: idf;x^2+x*y+y^2-1;x;y;2;0;1 A: \(\frac{d^2}{dx^2}y|_{(0,1)}=\frac{−3}{4}\) |
Q: idf;exp(x+y)-cos(x*y)-x^2*y^2;x;y A: \(\frac{d}{dx}y=\frac{2xy^2−y\sin(xy)−e^{x+y}}{−2x^2y+x\sin(xy)+e^{x+y}}\) |
Q: idf;y^2-x-cos(x*y);x;y;1;0;1 A: \(\frac{d}{dx}y|_{(0,1)}=\frac{1}{2}\) |
III. Derivatives for Functions of Several Variables
(1) Partial Derivatives
The array "dif; f(x, y, z, …); x; y; z; x ..." helps find partial derivatives for a differentiable function f(x, y, z, …) of two or more variables, where "dif" is the operation name, "f(x, y, z, …)" a function of several variables, and "x; y; z; x; ..." are the sequence of variables to which the partial derivative is taken.
For a function f(x, y) of two variables, calculate the first partial derivative of f(x, y) by “dif; f(x, y); x” and “dif; f(x, y); y”; calculate the second partial derivatives by “dif; f(x, y); x; x”, “dif; f(x, y); y; y”, “dif; f(x, y); x; y”, and “dif; f(x, y); y; x”. For repetition, one can also use “dif; f(x, y); x; 2”, “dif; f(x, y); y; 2”. Continue this pattern for higher order partial derivatives.
Table 3.6: Partial Derivatives by “dif” Operation
Q: dif;exp(x*y*z)*sin(x);x;y;z A: \(\frac{∂^3}{∂z∂y∂x}e^{xyz}\sin(x)=e^{xyz}(x\cos(x)+3xyz\sin(x)+x^2yz\cos(x)+x^2y^2z^2\sin(x)+\sin(x))\) |
Q: dif;exp(x*y*z)*sin(x);z;y;x A: \(\frac{∂^3}{∂x∂y∂z}e^{xyz}\sin(x)=e^{xyz}(x\cos(x)+3xyz\sin(x)+x^2yz\cos(x)+x^2y^2z^2\sin(x)+\sin(x))\) |
Q: dif;x^3*sin(y)+y^2*cos(x);y;x A: \(\frac{∂^2}{∂x∂y}(x^3\sin(y)+y^2\cos(x))=3x^2\cos(y)−2y\sin(x))\) |
Q: dif;sin(x*y*z)+z/y;x;y;z A: \(\frac{∂^3}{∂z∂y∂x}(\sin(xyz)+zy)=−3xyz\sin(xyz)−x^2y^2z^2\cos(xyz)+\cos(xyz)\) |
Q: dif;y^x;x;y;x A: \(\frac{∂^3}{∂x∂y∂x}y^x=y^{−1+x}\log(y)(2+x\log(y))\) |
Q: dif;cos(x^2*y^3);y;x;y A: \(\frac{∂^3}{∂y∂x∂y}\cos(x^2y^3)=−12xy\sin(x^2y^3)−48x^3y^4\cos(x^2y^3)+18x^5y^7\sin(x^2y^3)\) |
Q: dif;u/(u+v);u;u;v A: \(\frac{∂^3}{∂v∂u^2}\frac{u}{u+v}=\frac{2(−u+2v)}{(u+v)^4}\) |
Q: dif;asin(x/y);u;v A: \(\frac{∂^2}{∂v∂u}\text{asin}(xy)=0\) |
Q: dif;cos(3*x)*sin(4*y);y;x A: \(\frac{∂^2}{∂x∂y}\sin(4y)\cos(3x)=−12\sin(3x)\cos(4y)\) |
Q: dif;(x^2*y-x*y^2)/(x^2+y^2);x;y A: \(\frac{∂^2}{∂y∂x}x^2y−xy^2x^2+y^2=\frac{2xy(−3xy^2+3x^2y+x^3−y^3)}{(3x^2y^4+3x^4y^2+x^6+y^6)}\) |
The following examples use the “dif” function to verify if the order of partial derivatives matters by “dif(f(x,y),x,y)-dif(f(x,y),y,x)”.
Table 3.7: Equality of Mixed Partial Derivatives by “dif” Operation
Q: dif(f(x,y),x,y)-dif(f(x,y),y,x) A: \(=0\) |
Q: dif(cos(x+y)*exp(x*y),x,y)-dif(cos(x+y)*exp(x*y),y,x) A: \(=0\) |
Q: dif(x^2*y+y^3*x,x,y)-dif(x^2*y+y^3*x,y,x) A: \(=0\) |
Q: dif(g(x)*h(y),x,y)-dif(g(x)*h(y),y,x) A: \(=0\) |
Q: dif(g(x)*h(y),x)*dif(g(x)*h(y),y)-dif(g(x)*h(y),x,y)*g(x)*h(y) A: \(=0\) |
Q: x*dif(y*exp(x/y),x)+y*dif(y*exp(x/y),y)-y*exp(x/y) A: \(=0\) |
Q: x*dif(x^2-5*x*y+y^2,x)+y*dif(x^2-5*x*y+y^2,y)-2*(x^2-5*x*y+y^2) A: \(=0\) |
Q: dif(f(x^2+y^2),x)*y-x*dif(f(x^2+y^2),y) A: \(=0\) |
The following example shows the three approaches by "dif; exp(x*y); x; 3", “dif(exp(x*y), x, 3)”, and “dif(exp(x*y), x, x, x)” yield the same partial derivatives.
Q: dif;exp(x*y);x;3 A: \(ye^{xy}\) |
Q: dif(exp(x*y),x,3) A: \(ye^{xy}\) |
Q: dif(exp(x*y),x,x,x) A: \(ye^{xy}\) |
One can use the expression “dif(f(x, y), x)” to write a first-order partial differential equation. For example, the expression “dif(g(x, y), y) - 2*x” represents the partial differential equations gy(x, y) - 2x = 0, and “pde(dif(g(x, y), y) - 2*x)” gives the general solution to the unknown function g(x, y). Refer to Section (8) "Differential Equations" for more information on the "pde" function.
(2) Gradient and Critical Points
For functions of several variables, for example f(x, y, z), the array "vec;grd(f(x, y, z), x, y, z)" finds the gradient vector of f(x, y, z). To evaluate the gradient vector at a particular point (x0, y0, z0), use array “vec;grd(f(x, y, z),x,x0,y,y0,z,z0)”.
Composing the two functions "sol" and "grd", one may find possible critical points of the function f(x, y, z) by "vec;sol(grd(f(x, y, z), x, y, z),x,y,z)", where the "sol" function finds the solution to the normal equations.
Table 3.8: Gradient and Critical Points for Several-Variable Functions by “sol” and “grd” Operations
Q: vec;grd(2*x+3*y^2-cos(z),x,y,z) A: \(⟨2,6y,\sin(z)⟩\) |
Q: vec;grd(2*x+3*y^2-cos(z),x,1,y,2,z,pi/2) A: \(⟨2,12,1⟩\) |
Q: vec;grd(x^3*y+z^2,x,2,y,3,z,-1) A: \(⟨36,8,−2⟩\) |
Q: vec;sol(grd(x^3+y^3+3*x^2*y^2,x,y),x,y) A: Critical point(s) \((x,y) = \{(−\frac{1}{2},−\frac{1}{2}),(0, 0),(−2(\frac{1}{4}−\frac{\sqrt{3}i}{4})^2, \frac{1}{4}−\frac{\sqrt{3}i}{4}),(−2(\frac{1}{4}+\frac{\sqrt{3}i}{4})^2, \frac{1}{4}+\frac{\sqrt{3}i}{4})\}\) |
Q: vec;sol(grd(x*y*(x+2*y+3),x,y),x,y) A: Critical point(s) \((x,y)=\{(−3, 0),(−1, −\frac{1}{2}),(0, −\frac{3}{2}),(0, 0)\}\) |
Q: vec;sol(grd(x^2*y+x*y^2-x*y,x,y),x,y) A: Critical point(s) \((x,y) = \{(0, 0),(0, 1),(\frac{1}{3}, \frac{1}{3}),(1, 0)\}\) |
Q: vec;sol(grd(x^3+y^3+3*x^2*y^2,x,y),x,y) A: Critical point(s) \((x,y) = \{(−\frac{1}{2},−\frac{1}{2}),(0, 0),(−2(\frac{1}{4}−\frac{\sqrt{3}i}{4})^2, \frac{1}{4}−\frac{\sqrt{3}i}{4}),(−2(\frac{1}{4}+\frac{\sqrt{3}i}{4})^2, \frac{1}{4}+\frac{\sqrt{3}i}{4})\}\) |
(3) Directional Derivatives
The directional derivative of a function F(x, y, z) is the rate at which F changes at a point in the direction of the unit vector u, and it is given by the dot product ∇F·u, where ∇F is the gradient vector of F. The array "vec; grd(F(x,y,z),x,y,z)*uexpr/lnt(uexpr)" helps find the directional derivative of F in the direction of u. For example, the directional derivative of F(x, y) = sqrt(2)*x*y in the direction θ = π/4 is x + y by "vec;grd(sqrt(2)*x*y,x,y)*(sqrt(2)*i/2+sqrt(2)/2*j)", where the unit vector of the direction is \(⟨\frac{\sqrt{2}}{2},\frac{\sqrt{2}}{2}⟩\)
If the direction is not a unit vector, normalize it before getting the directional derivative. For example, "vec;grd(e^(x+y+z),x,y,z)*(2*i-3*j+6*k)/lnt(2*i-3*j+6*k)" gives the directional derivative of exp(x + y + z), which is \(\frac{5}{7}e^{x+y+z}\). In general, the array "vec;grd(F(x,y,z),x,y,z)*uexpr/lnt(uexpr)" finds the directional derivative of F(x, y, z) at a point in the direction of u, where the expression "uexpr/lnt(uexpr)" normalizes the vector u to a unit vector.
The direction vector u in the "vec" function is required to be written as a linear combination of the standard basis vectors i, j, and k. Refer to Section 7 for more information on vector expressions, dot product, and other vector operations.
Table 3.9: Directional Derivatives by “vec” and "grd" Operations
Q: vec;grd(x^2*y^3/z,x,y,z)*i A: = \(\frac{2xy^3}{z}\) |
Q: vec;grd(x^2*y^3/z,x,y,z)*j A: = \(\frac{3x^2y^2}{z}\) |
Q: vec;grd(x^2*y^3/z,x,y,z)*k A: = \(\frac{−x^2y^3}{z^2}\) |
Q: vec;grd(7*x*y*z,x,y,z)*(2*i+3*j-6*k)/lnt(2*i+3*j-6*k) A: = 3xz + 2yz - 6xy |
Q: vec;(0.6*i+0.8*j)/lnt(0.6*i+0.8*j)*grd(exp(x*y),x,y) A: = \(e^{xy}(0.8x+0.6y)\) |
Q: vec;(i-2*j+2*k)/lnt(i-2*j+2*k)*grd(3*(z-x^2*y),x,y,z) A: = 2 - 2xy + 2x2 |
Partial derivatives and gradient vectors can be conceptually viewed as directional derivatives in the direction of the standard basis vectors i, j, and k (the coordinate axes).
For example, if \(f(x,y,z)=x^2y^3z^{-1}\), get the gradient vector by “vec;grd(x^2*y^3/z, x, y, z)”, whose components can be computed by directional derivatives in the positive direction of the coordinate axes by “vec;grd(x^2*y^3/z,x,y,z)*i”, “vec;grd(x^2*y^3/z,x,y,z)*j”, “vec;grd(x^2*y^3/z,x,y,z)*k”, or by partial derivatives “dif(x^2*y^3/z, x)”, “dif(x^2*y^3/z, y)”, “dif(x^2*y^3/z, z)”.
Q: vec;grd(x^2*y^3/z,x,y,z) A: \(=(\frac{2xy^3}{z}, \frac{3x^2y^2}{z}, −\frac{x^2y^3}{z^2})\) |
Q: vec;grd(x^2*y^3/z,x,y,z)*i A: \(\frac{2xy^3}{z}\) |
Q: vec;grd(x^2*y^3/z,x,y,z)*j A: \(\frac{3x^2y^2}{z}\) |
Q: vec;grd(x^2*y^3/z,x,y,z)*k A: \(−\frac{x^2y^3}{z^2}\) |
Q: dif(x^2*y^3/z,x) A: \(\frac{2xy^3}{z}\) |
Q: dif(x^2*y^3/z,y) A: \(\frac{3x^2y^2}{z}\) |
Q: dif(x^2*y^3/z,z) A: \(−\frac{x^2y^3}{z^2}\) |
Q: vec;grd(x^2*y^3/z,x,y,z) A: \(=⟨\frac{2xy^3}{z}, \frac{3x^2y^2}{z}, −\frac{x^2y^3}{z^2}⟩\) |
(4) Chain Rule for Composite of Scalar and Vector Functions
Suppose \(f(x,y,z)\) is a composite function for \(x=x(u,v,w),y=y(u,v,w)\), and \(z=z(u,v,w)\). The partial derivative \(f_u'\) can be calculated by \(f'_u=\frac{∂f}{∂u}=\frac{∂f}{∂x}\frac{∂x}{∂u}+\frac{∂f}{∂y}\frac{∂y}{∂u}+\frac{∂f}{∂z}\frac{∂z}{∂u}=∇f·⟨x'_u,y'_u,z'_u⟩, f'_v=∇f·⟨x'_v,y'_v,z'_v⟩\) and \(f'_w=∇f·⟨x'_w,y'_w,z'_w⟩\) by the chain rule. Each result is written as a dot product of two vectors, where the former is the gradient vector of the function \(f(x,y,z)\) and the latter is the tangent vector of \(xi + yj + zk\) with respect to one of its parameters \(u, v\) or \(w\).
Combine the functions "grd" and "tnv" for "vec;grd(f(x,y,z),x,x(u,v,w),y,y(u,v,w),z,z(u,v,w))*tnv(x(u,v,w)*i+y(u,v,w)*j+z(u,v,w)*k,u)" to find \(f_u'\), "vec;grd(f(x,y,z),x,x(u,v,w),y,y(u,v,w),z,z(u,v,w))*tnv(x(u,v,w)*i+y(u,v,w)*j+z(u,v,w)*k,v)" to find \(f_v'\), and "vec;grd(f(x,y,z),x,x(u,v,w),y,y(u,v,w),z,z(u,v,w))*tnv(x(u,v,w)*i+y(u,v,w)*j+z(u,v,w)*k,w)" to find \(f_w'\). Refer to Section 7 for more information on "grd" and "tnv" and other vector operations.
Table 3.10: Chain Rule for Composite of Scalar and Vector Functions by “grd” and "tnv" Operations
Q: vec;grd(x^2+2*y^2,x,r*cos(t),y,r*sin(t))*tnv(r*cos(t)*i+r*sin(t)*j,r) A: = \(2r(1+\sin(t)^2)\) |
Q: vec;grd(x^2+2*y^2,x,r*cos(t),y,r*sin(t))*tnv(r*cos(t)*i+r*sin(t)*j,t) A: = \(r^2\sin(2t)\) |
Q: vec;grd(2*x^3+y^3,x,cos(t),y,sin(t))*tnv(cos(t)*i+sin(t)*j,t) A: = \(3(\sin(t)−2\cos(t))\sin(t)\cos(t)⟩\) |
Q: vec;grd(x^2*y^4,x,2*t^2,y,3*(t-2)^3)*tnv(2*t^2*i+3*(t-2)^3*j,t) A: = \(t^3(−2+t)^{11}(−2592+5184t)\) |
Q: vec;grd(log(x^2+y^2),x,exp(t^2),y,exp(-t))*tnv(exp(t^2)*i+exp(-t)*j,t) A: = \(\frac{2(−1+2te^{2t(1+t)})}{(1+e^{2t(1+t)})}\) |
Q: vec;grd(x^2-2*y+z^3,x,exp(t),y,log(t),z,cos(t))*tnv(exp(t)*i+log(t)*j+cos(t)*k,t) A: \(=2e^{2t}−3\sin(t)\cos^2(t)−\frac{2}{t}\) |
Q: vec;grd(u^3*v^2,u,x+y,v,x-y)*tnv((x+y)*i+(x-y)*j,x) A: = \((5x−y)(x−y)(x+y)^2\) |
Q: vec;grd(u^3*v^2,u,x+y,v,x-y)*tnv((x+y)*i+(x-y)*j,y) A: = \((x+y)^2(2(−x+y)(x+y)+3(x−y)^2)\) |
(5) Second Derivative Test, Hessian Determinant and Local Extreme Values
Suppose f(x, y) has continuous second partial derivatives in an open disk containing a critical point (x, y) = (a, b). Using the array "vec;hsd(f(x, y), x, a, y, b)", one can calculate the Hessian determinant and the second partial derivatives fxx, fyy, and fxy, which can be used to test whether the function has a local minimum, maximum, or neither. The values (a, b) in the "hsd" function correspond to the critical numbers “x = a” and “y = b” of f(x, y).
The results from "vec;hsd(f(x, y), x, a, y, b)" are expressed in the form "Di + fxxj + fyyk" or ⟨D, fxx, fyy⟩, where D is Hessian determinant, and fxx and fyy are the second partial derivatives. The following example uses the “hsd” function to determine the local extreme values of a function f(x, y).
Example Let f(x, y) = xy(x + 2y + 3). Four critical points are found by “vec;sol(grd(x*y*(x+2*y+3),x,y),x,y)”. The results of the second derivative test for each critical number are given below, and they show f(x, y) has a local maximum at (-1, -1/2), where D = 3, fxx = -1, and fyy = -4.
Q: vec;sol(grd(x*y*(x+2*y+3),x,y),x,y) A: Critical point(s) \((x,y) = \{(−3, 0),(−1, −\frac{1}{2}),(0, −\frac{3}{2}),(0, 0)\}\) |
Q: vec;hsd(x*y*(x+2*y+3),x,-1,y,-1/2) A: = (3, −1, −4) |
Q: vec;hsd(x*y*(x+2*y+3),x,0,y,0) A: Hessian determinant = −9; fxx = 0; fyy = 0 |
Q: vec;hsd(x*y*(x+2*y+3),x,-3,y,0) A: Hessian determinant = −9; fxx = 0; fyy = −12 |
Q: vec;hsd(x*y*(x+2*y+3),x,0,y,-3/2) A: Hessian determinant = −9; fxx = −3; fyy = 0 |
Q: vec;hsd(x*y*(x+2*y+3),x,-1,y,-1/2) A: Hessian determinant = 3; fxx = −1; fyy = −4 |
(6) Lagrange Multipliers and Optimization Subject to Constraints
Assume f(x, y) and g(x, y) are differentiable. If f(x, y) has a local extreme value on the constraint curve g(x, y) = 0, one need to solve the Lagrange equations ∇f = λ∇g along with the equation g(x, y) = 0 to determine the critical point(s) P, where ∇f and ∇g are gradient vectors, ∇gp is nonzero, and λ is some constant.
The array "vec;sol(grd(f(x, y), x, y)-m*grd(g(x, y), x, y) + g(x, y)*kx,y,m)" solves a system of three equations for (m, x, y), and helps find the critical points for f(x, y) subject to the constraint g(x, y) = 0, where "grd(f(x, y), x, y) - m*grd(g(x, y), x, y)" represents the Lagrange equations ∇f = m∇g , and "g(x, y)*k" is for the constraint equation g(x, y) = 0. The solutions to the unknown variables (m, x, y) appear in an alphabetical order.
For functions of three variables f(x, y, z) subject to a constraint g(x, y, z) = 0, obtain the three Lagrange equations by "vec;grd(f(x, y, z), x, y, z) - m*grd(g(x, y, z), x, y, z)", simplify these equations (possibly by substitution), and then use the “eqs” function to solve the simplified system of equations for (m, x, y, z).
If there are two constraints g(x, y, z) = 0 and h(x, y, z) = 0, the critical points must simultaneously satisfy the three Lagrange equations ∇f = λ∇g + μ∇h and two constraint equations g(x, y, z) = 0 and h(x, y, z) = 0. In this case, use "vec;grd(f(x,y,z), x, y, z) - m*grd(g(x,y,z), x, y, z) - n*grd(h(x,y,z), x, y, z)" to get the Lagrange equations, simplify them by substitution, and then apply "slv" or "eqs" to find solutions to the system of five equations for (m, n, x, y, z). Following a similar procedure, one can determine critical points for functions subject to more than two constraints. The following examples describe how to use these functions to determine critical points and extreme values.
Example 1 If f(x, y) = 2x2 + y2 subject to the constraint x – 2y = 3, determine the critical points by first computing ∇f and ∇g and then solving the system of three equations. Combine the functions “dif”, "grd" and “eqs” and get the critical point (m, x, y) = (4/3, 1/3, -4/3) by “eqs(dif(2*x^2+y^2,x)-m*dif(x-2*y-3,x),dif(2*x^2+y^2,y)-m*dif(x-2*y-3,y),x-2*y-3)”, or by “vec;sol(grd(2*x^2+y^2,x,y)-m*grd(x-2*y-3,x,y)+(x-2*y-3)*k,x,y,m)”.
Q: eqs(dif(2*x^2+y^2,x)-m*dif(x-2*y-3,x),dif(2*x^2+y^2,y)-m*dif(x-2*y-3,y),x-2*y-3) A: \(=(\frac{4}{3}, \frac{1}{3}, −\frac{4}{3})\) |
Q: vec;sol(grd(2*x^2+y^2,x,y)-m*grd(x-2*y-3,x,y)+(x-2*y-3)*k,x,y,m) A: \(=(\frac{4}{3}, \frac{1}{3}, −\frac{4}{3})\) |
Example 2 Find a point (x, y, z) on the plane 2x + 3y - z = 7 that is closest to the origin by the functions “grd” and “sol”. To minimize the distance is equivalent to minimize d2 = x2 + y2 + z2 subject to the constraint 2x + 3y - z = 7. Get the gradients by “vec;grd(x^2+y^2+z^2,x,y,z)”.
Q: vec;grd(x^2+y^2+z^2,x,y,z) A: \(⟨2x, 2y, 2z⟩\) |
Q: vec;grd(2*x+3*y-z-7,x,y,z) A: \(⟨2, 3, −1⟩\) |
Solve the system of equations by “eqs;x-m;2*y-3*m;2*z+m;2*x+ 3*y-z-7”, and obtain the critical point (1, 3/2, -1/2).
A: Solve \([−m+x=0, −3m+2y=0, m+2z=0, 2x+3y−z−7=0]\) for \((m,x,y,z)=(1, 1, \frac{3}{2}, −\frac{1}{2})\)
Example 3 Determine the extreme values of x2 + y2 + z2 subject to the two constraints x + z = 2 and x - y = 4. First, get the Lagrange equations by “vec;grd(x^2+y^2+z^2,x,y,z)-m*grd(x+z-2,x,y,z)-n*grd(x-y-4,x,y)”.
A: \(=(−m−n+2x, n+2y, −m+2z)\)
Then solve the system of linear equations “eqs;2*x-m-n;2*y+n;2*z-m;x+z-2;x-y-4” for the critical point (x, y, z) = (2, -2, 0). The minimum value of x2 + y2 + z2 is 4.
A: Solve \([−m−n+2x=0, n+2y=0, −m+2z=0, x+z−2=0, x−y−4=0]\) for \((m,n,x,y,z)=(0, 4, 2, −2, 0)\)
Example 4 Find extreme values of xyz subject to constrains x + y + z = 3 and x - y + z = 5. Simplify the Lagrange equation system "vec;grd(x*y*z,x,y,z)-m*grd(x+y+z-3,x,y,z)-n*grd(x-y+z-5,x,y,z)".
A: \(=(−m−n+yz, −m+n+xz, −m−n+xy)\)
Solve the equation system "eqs;y*z-m-n;x*z-m+n;x*y-m-n; x+y+z-3;x-y+z-5" for (m, n, x, y, z).
A: Solve \([−m−n+yz=0, −m+n+xz=0, −m−n+xy=0, x+y+z−3=0, x−y+z−5=0]\) for \((m,n,x,y,z)=\{(1, −3, 2, −1, 2)\}\)
4 Integration
I. Antiderivatives and Definite Integrals
If f(x) is integrable, the array "itg; f(x); x" or "itg(f(x), x)" helps find an antiderivative of f(x), where "itg" is the function name, "f(x)" the integrand expression, and "x" the variable of integration.
Integration and differentiation are inverse operations, so the actions of the two operations “dif” and “itg” cancel each other, and one can verify both expressions “itg(dif(f(x), x), x)” and “dif(itg(f(x), x), x)” are equal to f(x), or they differ by a constant. Notice that the antiderivative from the "itg" function does not include the constant.
Table 5.1: Antiderivatives or Indefinite integrals by “itg” Operation
Q: itg(dif(f(x),x),x) A: \(=f(x)\) |
Q: dif(itg(f(x),x),x) A: \(=f(x)\) |
Q: itg(dif(x,x),x) A: \(=x\) |
Q: dif(itg(cos(x^2),x),x) A: \(=\cos(x^2)\) |
Q: itg(c*f(x),x) A: \(=c∫f(x)dx\) |
Q: itg(f(x)+g(x),x) A: \(=∫(f(x)+g(x))dx\) |
Q: dif(itg(f(x),x)+c,x) A: \(=f(x)\) |
Q: itg(2*dif(f(x),x),x) A: \(=2f(x)\) |
Q: dif(itg(log(x)**2,x),x) A: \(=2\log(x)^2\) |
Q: itg(dif(exp(-x),x),x) A: \(=e^{-x}\) |
Q: itg(dif(2*x,x),x) A: \(=2x\) |
Q: dif(itg(x^2,x),x) A: \(=x^2\) |
The array “itg(f(x), x, a, b)" or "itg; f(x); x; a; b" evaluates a definite integral of f(x) over the interval [a, b], where “f(x)” is the integrand, “x” the integration variable, and “a; b” are the integration limits. Similarly, “itg(f(x, y), x, a, b, y, c, d)" or "itg; f(x, y); x; a; b; y; c; d" evaluates a double integral of f(x, y) over the rectangle [a, b] × [c, d], and "itg; f(x); x; a; b; y; c ; d; z; r; s" or "itg(f(x), x, a, b, y, c, d, z, r, s)" evaluates triple integrals of f(x, y, z) over the box [a, b] × [c, d] × [r, s].
Table 5.2: Definite Integrals by “itg” Operation
Q: itg(c,x,a,b) A: \(=c(-a+b)\) |
Q: itg(c*f(x),x,a,b) A: \(=c∫_a^bf(x)dx\) |
Q: itg;abs(x);x;-2;3 A: \(∫_{-2}^3\text{abs}(x)dx=\frac{13}{2}\) |
Q: itg(f(x)+g(x),x,a,b)-itg(f(x),x,a,b)-itg(g(x),x,a,b) A: \(=0\) |
Q: itg(f(x),x,a,a) A: \(=0\) |
Q: itg(x,x,a,c)-itg(x,x,a,b)-itg(x,x,b,c) A: \(=0\) |
Q: itg(x**2,x,a,b)+itg(x**2,x,b,a) A: \(=0\) |
Q: itg;r*h;r;0;a;t;0;2*pi A: \(∫_0^{2π}∫_0^ahrdrdt=πa^2h\) |
Q: itg;r**2*sin(s);r;0;2*a*cos(s);s;0;pi/4;t;0;2*pi A: \(∫_0^{2π}∫_0^{\frac{π}{4}}∫_0^{2a\cos(s)}r^2\sin(s)drdsdt=πa^3\) |
Q: itg;2*(a**2-r**2)**(1/2)*r;r;0;a;t;0;2*pi A: \(∫_0^{2π}∫_0^a2r\sqrt{a^2−r^2}drdt=\frac{4πa^2\sqrt{a^2}}{3}\) |
Q: itg;z;z;x+y;x*y;y;x;x**2;x;0;1 A: \(∫_0^1∫_x^{x2}∫_{x+y}^{xy}zdzdydx=\frac{569}{7560}\) |
Q: itg;z;z;cos(x+y);sin(x-y);y;x;0;x;0;pi/4 A: \(∫_0^{\frac{π}{4}}∫_x^0∫_{\cos(x+y)}^{\sin(x−y)}zdzdydx=\frac{1}{16}\) |
Q: itg;z;z;x+y;2*x+3*y;x;0;3;y;1;4 A: \(∫_1^4∫_0^3∫_{x+y}^{2x+3y}zdzdxdy=\frac{1845}{4}\) |
Q: itg;x;z;x-y;2*x+3*y;y;0;x;x;-2;3 A: \(∫_{-2}^3∫_0^x∫_{x-y}^{2x+3y}xdzdydx=\frac{195}{4}\) |
Q: itg;x-y;x;2*z;3*y;y;-z;0;z;0;1 A: \(∫_0^1∫_{-z}^0∫_{2z}^{3y}x−ydxdydz=−\frac{5}{8}\) |
Q: itg(y^2,y,0,1-x^2,x,-1,1)/itg(y,y,0,1-x^2,x,-1,1) A: \(=\frac{4}{7}\) |
Q: log(x)==itg(1/t,t,1,x) A: = True |
Q: itg;atan(x)-cosh(x);x;0;1 A: \(∫_0^1−\cosh(x)+\text{atan}(x)dx=−\sinh(1)−\frac{\log(2)}{2}+\frac{π}{4}\) |
II. Numerical Integration
The array "nit(f(x), x, a, b, n)" or "nit; f(x); x; a; b; n" approximates the definite integral of f(x) over the interval [a, b] by Riemann sum (e.g., Simpson's approach), where “f(x)” is the integrand, “x” the integration variable, and “n” the number of partitions in [a, b].
Table 5.3: Numerical Integration by “nit” Operation
Q: nit;cos(x**2);x;0;3;20 A: Simpson = 0.7029; Trapezoidal = 0.6982; Midpoints = 0.7053; Right endpoints = 0.5548; Left endpoints = 0.8415 |
Q: nit((1+x**2)**(1/2),x,0,2,20) A: \(=2.9579\) |
Q: nit;exp(-x**3);x;0;2;20 A: Simpson = 0.893; Trapezoidal = 0.893; Midpoints = 0.893; Right endpoints = 0.843; Left endpoints = 0.9429 |
Q: nit;(1+x**3);x;-1;2;20 A: Simpson = 6.75; Trapezoidal = 6.7669; Midpoints = 6.7416; Right endpoints = 7.4419; Left endpoints = 6.0919 |
Q: nit(sin(x**2),x,0,1,20) A: \(=0.3103\) |
III. Functions Defined by Integrals
Functions can be constructed by integrals with the "itg" function, and one can find the derivatives, partial derivatives, or limits of such functions by combining the functions "dif", “lim” and "itg".
Table 5.4: Operation on Functions Defined by Integrals by “dif”, “lim” and “itg”
Q: dif(itg(f(t),t,a,h(x)),x) A: \(=f(h(x))\frac{d}{dx}h(x)\) |
Q: dif(itg(f(t),t,u(x),h(x)),x) A: \(=f(h(x))\frac{d}{dx}h(x)−f(u(x))\frac{d}{dx}u(x)\) |
Q: dif(itg(f(t),t,b,-x),x) A: \(=-f(-x)\) |
Q: dif(itg(f(t),t,-x,x),x) A: \(=f(-x)+f(x)\) |
Q: lim(itg(exp(t**2-1),t,1,1+h)/h,h,0) A: \(=1\) |
Q: lim(itg(exp(t**2-1),t,a,a+h)/h,h,0) A: \(=e^{a^2−1}\) |
Q: dif(itg(f(x,y),y,a,b),x)-itg(dif(f(x,y),x),y,a,b) A: \(=0\) |
Q: itg(dif(f(x,y),x),y,a,b) A: \(=∫_a^b\frac{∂}{∂x}f(x,y)dy\) |
Q: itg(dif(f(x,y),y),x,a,b) A: \(=∫_a^b\frac{∂}{∂y}f(x,y)dx\) |
Q: dif(itg(f(t),t,x,y),x,2) A: \(=−\frac{d}{dx}f(x)\) |
Q: dif(itg(f(x,y,z),z,a,b),x,y) A: \(=∫_a^b\frac{∂^2}{∂y∂x}f(x,y,z)dz\) |
Q: dif(itg(f(x,y,z),z,a,b),y,2) A: \(=∫_a^b\frac{∂^2}{∂y^2}f(x,y,z)dz\) |
Q: dif(itg(f(x,y,z),z,a,b),x) A: \(=∫_a^b\frac{∂}{∂x}f(x,y,z)dz\) |
Q: dif(itg(f(t),t,x,y),y,2) A: \(=\frac{d}{dy}f(y)\) |
Q: dif(itg(f(t),t,x,y),y) A: \(=f(y)\) |
Q: dif(itg(f(t),t,x,y),x) A: \(=-f(x)\) |
IV. Line and Surface Integrals
Scalar Line Integrals The array "lit; f(x,y,z); x(t)i + y(t)j + z(t)k; t; a; b; x; y; z" or "lit(f(x, y, z), x(t)i + y(t)j + z(t)k, t, a, b, x, y, z)" evaluates the scalar line integral of f(x, y, z) along a curve parametrized by r(t), where "lit" is the operation name, “f(x, y, z)” is a scalar function, “x(t), y(t)” and “z(t)” are component functions of a vector parametrization r(t) = ⟨x(t), y(t), z(t)⟩, “t” is the parameter, [a, b] is the interval of parameter “t”, and "x; y; z" are the component names of r(t). The "lit" function requires the order of the names "x; y; z" of r(t) to exactly match the parametrization r(t) = x(t)i + y(t)j + z(t)k.
If f(x, y, z) = 1, the array "lit; 1; x(t)*i + y(t)*j + z(t)*k; t; a; b" calculates the length of the curve r(t) = ⟨x(t), y(t), z(t)⟩ for a ≤ t ≤ b.
Vector Line Integrals Replacing the scalar function “f(x, y, z)” with a vector field F, one has "lit; F; x(t)i + y(t)j + z(t)k; t; a; b; x; y; z" or "lit(F, x(t)i + y(t)j + z(t)k, t, a, b, x, y, z)" for evaluating the vector line integral of F along the curve the curve r(t) = ⟨x(t), y(t), z(t)⟩. In both scalar or vector line integrals, the parametrization r(t) = ⟨x(t), y(t), z(t)⟩ must be written as a linear combination of the standard basis vectors i, j, and k.
Table 5.5: Line Integrals by “lit” Operation
Q: lit;x-y**2;3*t*i-2*j;t;0;2;x;y A: \(∫_cx−y2ds=−6\) |
Q: lit;x**2+y**2+z**2;cos(t)*i+2*t*j+sin(t)*k;t;0;2;x;y;z A: \(∫_cx^2+y^2+z^2ds=\frac{38\sqrt{5}}{3}\) |
Q: lit;-y*i+x**2*j;t*i+t**2*j;t;0;2;x;y A: \(∫_c−ydx+x^2dy=\frac{16}{3}\) |
Q: lit;1;cos(t)*i+sin(t)*j;t;0;2*pi A: \(∫_c1ds=2π\) |
Q: lit;1;cos(t)*i+sin(t)*j+t*k;t;0;pi A: \(∫_c1ds=\sqrt{2}π\) |
Q: lit;x**3;t*i+t**3*j/3;t;0;1;x A: \(∫_cx^3ds=−\frac{1}{6}+\frac{\sqrt{2}}{3}\) |
Q: lit;x*i+2*y*j;t*i+t**2*j;t;0;1;x;y A: \(∫_cxdx+2ydy=\frac{3}{2}\) |
Q: lit;-y*i+x*j;(t-sin(t))*i+(1-cos(t))*j;t;2*pi;0;x;y A: \(∫_c−ydx+xdy=6π\) |
Q: lit;(-y*i+x*j)/(x**2+y**2);cos(t)*i+sin(t)*j;t;0;2*pi;x;y A: \(∫_c\frac{−y}{(x^2+y^2)}dx+\frac{x}{(x^2+y^2)}dy=2π\) |
Q: lit;(x**2*y-1)*i+(y**2+3*x)*j;t**2*i+t*j;t;1;0;x;y A: \(∫_c−1+x^2ydx+3x+y^2dy=−\frac{13}{21}\) |
Scalar Surface Integrals Let r(u,v) be a parametrization of a surface S defined in a parameter domain. The array "sit; f(x,y,z); x(u,v)*i+y(u,v)*j+z(u,v)*k; u; a; b; v; c; d; x; y; z" or "sit( f(x,y,z), x(u,v)*i+y(u,v)*j+z(u,v)*k, u, a, b, v, c, d, x, y, z)" evaluates the scalar surface integral of a scalar function f(x, y, z) over the surface parametrized by r(u,v) = “x(u,v)i + y(u,v)j + z(u,v)k”, where "u" and "v" are parameters for "u" in the interval [a, b] and "v" in [c, d], and "x", "y" and "z" are the names of the component functions of r(u,v). The operation requires that "x; y; z" in that order, because they represent the component functions x = x(u, v), y = y(u, v), z = z(u, v) of r(u,v) that correspond to the standard basis vectors i, j, k.
Vector Surface Integrals In a similar fashion, "sit; F; r(u, v); u; a; b; v; c; d; x; y; z" or "sit(F, r(u, v), u, a, b, v, c, d, x, y, z)" evaluates the vector surface integral of a vector field F over the surface parametrized by r(u,v) = r(u,v) = x(u,v)i + y(u,v)j + z(u,v)k, where "sit" is the operation name, "u, v" are the parameters for u in the interval [a, b] and v in [c, d], and "x; y; z" are the names of component functions of r(u,v). The names “x; y; z” are required in that order, because they represent the component functions x = x(u, v), y = y(u, v), z = z(u, v) of r(u,v) that correspond to the standard basis vectors i, j, k.
In addition, for vector surface integrals, the “sit” function requires the intervals "u; a; b; v; c; d" (in order) corresponding to the positive surface orientation, and "v; c; d; u; a; b" corresponding to the negative orientation.
Table 5.6: Surface Integrals by “sit” Operation
Q: sit;x+2*y-3*z;cos(u)*i+sin(u)*j+v*k;u;0;2*pi;v;0;4;x;y;z A: \(∬_sx+2y−3zdS=−48π\) |
Q: sit;1;sin(s)*cos(t)*i+sin(s)*sin(t)*j+cos(s)*k;s;0;pi;t;0;2*pi A: \(∬_s1dS=4π\) |
Q: sit;1;4*cos(t)*i+4*sin(t)*j+z*k;t;0;2*pi;z;0;3 A: \(∬_s1dS=24π\) |
Q: sit;i;r*cos(t)*i+r*sin(t)*j;r;0;3;t;0;pi*2 A: \(∬_s⟨1,0,0⟩⋅dS=0\) |
Q: sit;2*j;r*cos(t)*i+r*sin(t)*j;r;0;3;t;0;pi*2 A: \(∬_s⟨0,2,0⟩⋅dS=0\) |
Q: sit;k;r*cos(t)*i+r*sin(t)*j;r;0;3;t;0;pi*2 A: \(∬_s⟨0,0,1⟩⋅dS=9π\) |
Q: sit;2*i+3*j+4*k;r*cos(t)*i+r*sin(t)*j;r;0;3;t;0;pi*2 A: \(∬_s⟨2,3,4⟩⋅dS=36π\) |
Q: sit;x*i+y**2*j+z**3*k;cos(s)*i+sin(s)*j+t*k;s;0;2*pi;t;0;2;x;y;z A: \(∬_s⟨x,y^2,z^3⟩⋅dS=2π\) |
5 Infinite Series
I. Finite and Infinite Sum
Infinite Sum The array "ism; f(n); n; n1; oo" or "ism(f(n), n, n1, oo)" calculates the infinite sum of f(n) for n from n1 to infinity (represented by "oo"), where “f(n)” is the expression of the \(n\)th term, and “n” is a whole number variable.
Finite Sum Replacing “oo” in the above array with “m”, another variable for whole numbers, one gets "ism; f(n); n; n1; m" or "ism(f(n), n, n1, m)" for a finite sum of f(n) from n1 to m. The array returns a formula or function of “m” for the sum. For a finite sum of f(n) from n1 to m1, use "ism; f(n); n; n1; m; m1" or "ism(f(n), n, n1, m, m1)", which is a finite number.
Converge or Diverge Adding the keyword “cv” (for convergence) to the function "ism", one has "ism; f(n); n; n1; oo; cv" or "ism(f(n), n, n1, oo, cv)", which returns True if the sum converges and False otherwise. Replacing “cv” with “ac” (for absolute convergence), one gets the array "ism; f(n); n; n1; oo; ac" or "ism(f(n), n, n1, oo, ac)", which returns True if the sum converges absolutely and False otherwise.
Convergence Interval In addition to the ratio test, use "ism; f(x, n); n; n1; oo" or "ism(f(x, n), n, n1, oo)" to determine the radius and possible convergence interval for a series f(x, n).
Table 6.1: Finite and Infinite Sum, Convergence Interval by “ism” Operation
Q: ism;(j-3)**2;j;5;m;9 A: \(\displaystyle\sum_{j=5}^9(j−3)^2=90\) |
Q: ism;a;i;1;n A: \(\displaystyle\sum_{i=1}^na=an\) |
Q: ism;i;i;1;n A: \(\displaystyle\sum_{i=1}^ni=\frac{n^2}{2}+\frac{n}{2}\) |
Q: ism;i**2;i;1;n A: \(\displaystyle\sum_{i=1}^ni^2=\frac{n^3}{3}+\frac{n^2}{2}+\frac{n}{6}\) |
Q: ism;i**3;i;1;n A: \(\displaystyle\sum_{i=1}^nn^3=\frac{n^4}{4}+\frac{n^3}{2}+\frac{n^2}{4}\) |
Q: ism;i**4;i;1;n A: \(\displaystyle\sum_{i=1}^nn^4=\frac{n^5}{5}+\frac{n^4}{2}+\frac{n^3}{3}−\frac{n}{30}\) |
Q: ism;5;i;1;n;10 A: \(\displaystyle\sum_{i=1}^{10}5=50\) |
Q: ism;(-0.8)**i;i;0;n;500 A: \(\displaystyle\sum_{i=0}{500}(-0.8)^i=0.555555555555556\) |
Q: ism;(-1)**i;i;0;n;10 A: \(\displaystyle\sum_{i=0}^{10}(-1)^i=1\) |
Q: ism;i**2;i;1;n;100 A: \(\displaystyle\sum_{i=1}^{100}i^2=338350\) |
Q: ism;1/(2*n+1)-1/(2*n+3);n;0;m;50 A: \(\displaystyle\sum_{n=0}^{50}\frac{2}{(2n+1)(2n+3)}=\frac{102}{103}\) |
Q: ism;i**3;i;1;n;500 A: \(\displaystyle\sum_{i=1}^{500}i^3=15687562500\) |
Q: ism;n**(-1.5);n;1;oo A: \(\displaystyle\sum_{n=1}^∞n^{-1.5}=2.61237534868549\) |
Q: ism;1/gamma(n+1);n;0;oo A: \(\displaystyle\sum_{n=0}^∞\frac{1}{Γ(n+1)}=e\) |
Q: ism;n**(-2/3);n;1;oo A: \(\displaystyle\sum_{n=1}^∞\frac{1}{n^{\frac{2}{3}}}=\sum_{n=1}^∞\frac{1}{n^{\frac{2}{3}}}\) |
Q: ism;1/n;n;1;oo;cv A: \(\displaystyle\sum_{n=1}^∞\frac{1}{n}=\) False |
Q: ism;(-1)^n/(n+1);n;0;oo;ac A: \(\displaystyle\sum_{n=0}^∞=\frac{(-1)^n}{n+1}=\) False |
Q: ism;2**n/gamma(n+1);n;0;oo;cv A: \(\displaystyle\sum_{n=0}^∞\frac{2^n}{Γ(n+1)}=\) True |
Q: ism;(-1)**n*1/n**2;n;1;oo;ac A: \(\displaystyle\sum_{n=1}^∞\frac{(-1)^n}{n^2}=\) True |
Q: ism;1/n**(1/2);n;1;oo;ac A: \(\displaystyle\sum_{n=1}^∞\frac{1}{\sqrt{n}}=\) False |
Q: ism;x^(2*n)/gamma(n+1);n;0;oo A: \(\displaystyle\sum_{n=0}^∞\frac{x^{2n}}{Γ(n+1)}=e^{x^2}\) |
Q: ism;(-1)**n*2**(2*n)/gamma(2*n+1);n;0;oo A: \(\displaystyle\sum_{n=0}^∞\frac{(−4)^n}{Γ(2n+1)}=\cos(2)\) |
Q: ism;x**n/gamma(n+1);n;0;oo A: \(\displaystyle\sum_{n=0}^∞\frac{x^n}{Γ(n+1)}=e^x\) |
Q: ism;(-1)**n*x**(2*n+1)/gamma(2*n+2);n;0;oo A: \(\displaystyle\sum_{n=0}^∞\frac{(-1)^nx^{2n+1}}{Γ(2n+1)}=\sin(x)\) |
Q: ism;(2*x)^n;n;0;oo A: \(\displaystyle\sum_{n=0}^∞(2x)^n=\begin{cases}\frac{1}{1−2x}\text{ for } 2|x|<1\\ ∑_{n=0}^∞2^nx^n\text{ otherwise}\end{cases}\) |
Q: ism;5*(x/4)^n;n;0;oo A: \(\displaystyle\sum_{n=0}^∞5(\frac{x}{4})^n=5\begin{cases}\frac{1}{1−\frac{x}{4}}\text{ for } \frac{|x|}{4}<1\\ ∑_{n=0}^∞4^{-n}x^n\text{ otherwise}\end{cases}\) |
II. Taylor Series Expansion and Approximation
The array "ses; f(x); x; c; N; n/p" or "ses(f(x), x, c, N, n/p)" expands a function f(x) about the center x = c as a power series, where “x” is the independent variable, “N” the number of terms, 'p' = '+' or 'n' = '-' (positive or negative) is the direction. By default, c = 0, N = 5, and the direction is 'p' (positive).
The array "ses; f(x); x; c; N; n/p; x0" or "ses(f(x), x, c, N, n/p, x0)" approximates the value of f(c + x0) by Taylor polynomials.
Table 6.2: Taylor Series Expansion and Approximation by “ses’ Operation
Q: ses;(1+x)**(1/2);x;0;10 A: \(\sqrt{x+1}=1+\frac{x}{2}−\frac{x^2}{8}+\frac{x^3}{16}−\frac{5x^4}{128}+\frac{7x^5}{256}−\frac{21x^6}{1024}+\frac{33x^7}{2048}−\frac{429x^8}{32768}+\frac{715x^9}{65536}+O(x^{10})\) |
Q: ses(sin(x)/exp(x),x,0,10) A: \(=x(\frac{x^8}{22680}−\frac{x^6}{630}+\frac{x^5}{90}−\frac{x^4}{30}+\frac{x^2}{3}−x+1)\) |
Q: ses;(1-x**2)**(1/2);x;0;10 A: \(\sqrt{1−x^2}=1−\frac{x^2}{2}−\frac{x^4}{8}−\frac{x^6}{16}−\frac{5x^8}{128}+O(x^{10})\) |
Q: ses;sin(x);x;0;10 A: \(\sin(x)=x−\frac{x^3}{36}+\frac{x^5}{120}−\frac{x^7}{5040}+\frac{x^9}{362880}+O(x^{10})\) |
Q: ses;2**x;x A: \(2^x=1+x\log(2)+\frac{x^2\log(2)^2}{2}+\frac{x^3\log(2)^3}{6}+\frac{x^4\log(2)^4}{24}+\frac{x^5\log(2)^5}{120}+O(x^6)\) |
Q: ses(exp(x)*cos(x),x,0,10) A: \(=\frac{x^9}{22680}+\frac{x^8}{2520}+\frac{x^7}{630}−\frac{x^5}{30}−\frac{x^4}{6}−\frac{x^3}{3}+x+1\) |
Q: ses;sinh(x);x A: \(\sinh(x)=x+\frac{x^3}{6}+\frac{x^5}{120}+O(x^6)\) |
Q: ses;x**(1/2);x;2;8 A: \(\sqrt{x}=\sqrt{2}+\frac{\sqrt{2}(x−2)}{4}−\frac{\sqrt{2}(x−2)^2}{32}+\frac{\sqrt{2}(x−2)^3}{128}−\frac{5\sqrt{2}(x−2)^4}{2048}+\frac{7\sqrt{2}(x−2)^5}{8192}−\frac{21\sqrt{2}(x−2)^6}{65536}+\frac{33\sqrt{2}(x−2)^7}{262144}+O((x−2)^8;x→2)\) |
Q: ses;sin(x)/x;x A: \(\frac{\sin(x)}{x}=1−\frac{x^2}{6}+\frac{x^4}{120}+O(x^6)\) |
Q: ses;tan(x);x;pi/6 A: \(\tan(x)=\frac{\sqrt{3}}{3}−\frac{2π}{9}+\frac{4\sqrt{3}(x−\frac{π}{6})^2}{9}+\frac{8(x−\frac{π}{6})^3}{9}+\frac{4\sqrt{3}(x−\frac{π}{6})^4}{9}+\frac{104(x−\frac{π}{6})^5}{135}+4x^3+O((x−\frac{π}{6})^6;x→\frac{π}{6})\) |
Q: ses;cot(x);x;pi/4;5;n A: \(\cot(x)=π^2+1+2(−x+\frac{π}{4})^2+\frac{8(−x+\frac{π}{4})^3}{3}+\frac{10(−x+\frac{π}{4})^4}{3}−2x+O((x−\frac{π}{4})^5;x→\frac{π}{4})\) |
Q: ses;asin(x);x;0;10 A: asin\((x)=x+\frac{x^3}{6}+\frac{3x^5}{40}+\frac{5x^7}{112}+\frac{35x^9}{1152}+O(x^{10})\) |
Q: ses;(1+x)**0.3;x A: \((x+1)^{0.3}=1+0.3x−0.105x^2+0.0595x^3−0.0401625x^4+0.02972025x^5+O(x^6)\) |
Q: ses;1/(1-x**2);x A: \(\frac{−1}{x^2−1}=1+x^2+x^4+O(x^6)\) |
Q: ses;sin(x)/exp(x);x A: \(e^{−x}\sin(x)=x−x^2+\frac{x^3}{3}−\frac{x^5}{30}+O(x^6)\) |
Q: ses;cos(x);x;0;3;p;0.3 A: \(\cos(x)|_{x=0.3}=0.955\) |
Q: ses;exp(x);x;0;6;p;2/3 A: \(e^x|_{x=0.666666666666667}=1.94759945\) |
Q: ses;atan(x);x;0;7;p;1/3 A: atan\((x)|_{x=0.333333333333333}=0.3218107\) |
III. Series Integration and Differentiation
New series can be formed by differentiating or integrating old ones. Combine the functions "dif" with "ses" to have "dif(ses(f(x), x, c, n, p/n), x)" for differentiating the series expansion of f(x), and combine "itg" and "ses" to have itg(ses(f(x), x, c, n, p/n), x, a, b)" for integrating the series expansion of f(x).
Table 6.3: Integrating or Differentiating a Series by “ses” and “dif” (or “itg”)
Q: itg(ses(exp(-t**2/2),t,0,10),t,0,x) A: \(\sqrt{x+1}=1+\frac{x}{2}−\frac{x^2}{8}+\frac{x^3}{16}−\frac{5x^4}{128}+\frac{7x^5}{256}−\frac{21x^6}{1024}+\frac{33x^7}{2048}−\frac{429x^8}{32768}+\frac{715x^9}{65536}+O(x^{10})\) |
Q: dif(ses(cos(x),x,0,10),x) A: \(=x(\frac{x^8}{22680}−\frac{x^6}{630}+\frac{x^5}{90}−\frac{x^4}{30}+\frac{x^2}{3}−x+1)\) |
Q: itg(ses(exp(-x**3),x,0,7),x) A: \(\sqrt{1−x^2}=1−\frac{x^2}{2}−\frac{x^4}{8}−\frac{x^6}{16}−\frac{5x^8}{128}+O(x^{10})\) |
Q: itg(ses(sin(x**2),x,0,10),x) A: \(\sin(x)=x−\frac{x^3}{36}+\frac{x^5}{120}−\frac{x^7}{5040}+\frac{x^9}{362880}+O(x^{10})\) |
6 Vector Algebra and Vector-Valued Function Calculus
I. Vector Algebra
Vector Expressions and Operations Spatial vector (vectors in R3) operations start with "vec; vec_expres", and "vec_expr" (vector expression) must be written as a linear combination of the standard basis vectors i, j, and k. The operators for vector addition, subtraction, dot product, and cross product are “+, -, *, ^ (or **)”, respectively. For simple vector operations such as "i + j", "j**k", "(2*i - j)*(4*j - 5*k)", or "x*i**(y*k)", just enter the expressions. For operations that involves several vectors, write the operation with distinct vector names, and then enter each vector name and its corresponding expression separately. For example, "u**v; u; 2*i - cos(x)*j; v; sin(x)*j - x*k" calculates the cross product of the vectors u and v. Keep in mind that the three letters "i, j, k" are reserved for the standard basis vectors, so do not use them for other vector names.
Note that “vec; expr” can carry out simple or mixed vector operations, for example, "vec;(2*i-3*k)**(-i+4*j-5*k)". For complicated vector operations involving several vectors, also use "vec; F(u, v, w); u; uexpr; v; vexpr; w; wexpr", where F(u, v, w) is the function of the vectors u, v, and w.
In a simple case, “vec; u; u; uexpr” simply returns the entries of the vector u, "vec; lnt(u); u; uexpr" gives the length (magnitude) of u, and "vec; u/lnt(u); u; uexpr" normalizes u to a unit vector.
Examples "vec; 2*u^v + a*w; u; x*i-y*j; v; cos(x)*i - y*j; w; log(y)*i + x*k" simplifies the operation 2u × v + aw among vector functions u, v, and w, where "u; x*i-y*j; v; cos(x)*i - y*j; w; log(y)*i + x*k" are the key-value pairs defining the vectors u = x*i-y*j, v = cos(x)*i - y*j, and w = log(y)*i + x*k.
Table 7.1: Vector Algebra by “vec” Operation
Q: vec;2*i*(3*j+4*k) A: = 0 |
Q: vec;(3*i-2*j+4*k)**(4*j-6*k) A: = ⟨−4, 18, 12⟩ |
Q: vec;(a*i+b*j+c*k)*(x*i+y*j+z*k) A: = ax + by + cz |
Q: vec;u;u;cos(t)*i+sin(t)*j+3^(1/2)*k A: = ⟨cos(t), sin(t), \(\sqrt{3}\)⟩ |
Q: vec;(a*i+b*j+c*k)^(a*i+b*j+c*k) A: = ⟨0,0,0⟩ |
Q: vec;(a*i+b*j+c*k)^(r*i+s*j+t*k)+(r*i+s*j+t*k)^(a*i+b*j+c*k) A: = ⟨0,0,0⟩ |
Q: vec;u**(v+w)-u**v-u**w;u;a*i+b*j+c*k;v;r*i+s*j+t*k;w;f*i+g*j+h*k A: = ⟨0,0,0⟩ |
Q: vec;i^j A: = ⟨0,0,0⟩ |
Q: vec;2*i+2*j+k A: = ⟨2,2,1⟩ |
Q: vec;u*(2*v+3*u);u;sin(x)*i+cos(x)*k;v;x**2*i-x*j A: = 3 + 2x²sin(x) |
Q: vec;u;u;cos(x)*i+sin(x)*j A: = ⟨cos(x), sin(x), 0⟩ |
Q: vec;u**v;u;i+j;v;i-j A: = ⟨0, 0, −2⟩ |
Q: vec;lnt(u/lnt(u));u;x*i+y*j+z*k A: = 1 |
Q: vec;(2*u)*(3*v);u;log(x)*i+x**(-1/2)*j;v;2**x*j+x**(-2)*k A: = \(\frac{6⋅2^x}{\sqrt{x}}\) |
Q: vec;lnt(3*i-4*j) A: = 5 |
Q: vec;lnt((i-2*j+3*k)**(2*i-4*j+5*k)) A: = \(\sqrt{5}\) |
Q: vec;u/lnt(u);u;2*i+3*j+6*k A: = ⟨\(\frac{2}{7},\frac{3}{7},\frac{6}{7}\)⟩ |
Q: vec;lnt(u);u;cos(pi/4)*i+sin(pi/4)*j A: = 1 |
These vector functions "lnt", prj", "cul", "dvg", "grd",'tnv', "ang", "hsd", and "csv" are used for finding vector length, projection, cull, divergence, gradient, tangent vector, angles between two vectors, performing the second derivative test, and checking whether a vector field is conservative.
II. Length, Angle, Projection, Area, Volume, and Orthogonal Decomposition
Calculate the length of a vector u by "lnt(u)", for example, "vec;lnt(3*i+4*j)" or "vec;lnt(u);u;cos(t)*i+sin(t)*j+2*k". The angle θ between two vectors u and v can be found by "vec;ang(uexpr, vexpr)" or "vec; ang(u, v); u; uexpr; v; vexpr", where 'ang' is the function for finding the angle between two vectors u and v, and the key-value pairs "u; uexpr; v; vexpr" define the vectors u and v. Note that the range of θ is 0 ≤ θ ≤ π. Verify the angle by "acos(u*v/(lnt(u)*lnt(v)))".
Replacing "ang" with "prj" for "vec;prj(uexpr, vexpr)", "vec; prj(u, v); u; uexpr; v; vexpr", which finds the projection of the vector u onto v, where “prj” is the function name, and the key-value pairs "u; uexpr; v; vexpr" define the two vectors. For projection, the order of u and v matters here, and "vec;prj(vexpr, uexpr)", “vec;prj(v, u); u; uexpr; v; vexpr” finds the projection of v onto u.
If v is a unit vector, calculate prj(u, v) = (u·v)v by "vec;(u*v)*v", where u·v is the component of u along v. In general, the vector u - prj(u, v) is orthogonal to v by "vec;(u-prj(u,v))*v", which is 0. Use dot product "a*b" (= 0) to verify if any two vectors a and b are orthogonal.
Table 7.2: Angle and Vector Projection by “prj” and "ang" Operations
Q: vec;prj(10*i+2*j-6*k,2*i+2*j+k) A: = ⟨4, 4, 2⟩ |
Q: vec;ang(i,j) A: = \(\frac{π}{2}\) |
Q: vec;ang(10*i+2*j-6*k,2*i+2*j+k) A: = acos\((\frac{3\sqrt{35}}{35})\) |
Q: vec;prj(u,v);u;2*i+j-3*k;v;i+j-k A: = ⟨2, 2, −2⟩ |
Q: vec;prj(j,k) A: = (0, 0, 0) |
Q: vec;ang(2*i+j-3*k,i+j-k) A: = acos\((\frac{\sqrt{42}}{7})\) |
Q: vec;i+prj(3*i-2*j+5*k,-i+4*k) A: = ⟨0, 0, 4⟩ |
Q: vec;prj(u,v);u;x*i+y*j+z*k;v;2*(x*i+y*j+z*k) A: = ⟨x, y, z⟩ |
Q: vec;ang(3*i-2*j+5*k,-i+4*k) A: = acos\((\frac{\sqrt{646}}{38})\) |
Q: vec;u*prj(u,v);u;cos(t)*i+sin(t)*j+t*k;v;cos(t)*i+sin(t)*j A: = 1 |
Q: vec;4*prj(u,v);u;(x*i+y*j+z*k)/4;v;-3*(x*i+y*j+z*k) A: = ⟨x, y, z⟩ |
Q: vec;ang(cos(t)*i+sin(t)*j+k,cos(t)*i+sin(t)*j) A: = \(\frac{π}{4}\) |
Q: vec;2*i+j-3*k-prj(2*i+j-3*k,i+j-k) A: = (0, −1, −1) |
Q: vec;tan(ang(i,-2**(1/2)/2*i+2^(1/2)/2*j)) A: = -1 |
Q: vec;2*i+j-3*k-prj(2*i+j-3*k,i+j-k) A: = \(-j-k\) |
Calculate the area of the triangle by u and v by "vec;lnt(u**v)/2", the area of the parallelogram by u and v by "vec;lnt(u**v)", and the volume by u, v, and w by the triple scalar product "vec;abs(w*(u**v))".
III. Vector-Valued Function Calculus
One can apply the functions “lim”, “dif” and “itg” to a vector-valued function to determine its limit, derivative or integral component-wise by expressing the function as a linear combination of the standard basis vectors i, j, and k, or F1i + F2j + F3k.
Table 7.3: Limits, Derivatives and Integrals of Vector Functions by “lim”, “dif”, and “itg”
Q: lim;x*i+(x**2-1/x)*j+(2-x)*k;x;1 A: \(\lim\limits_{x→1}\frac{j(x^3−1)+x(ix−k(x−2))}{x} =i+k\) |
Q: lim;cos(x)*i+sin(2*x)*j+log(x)*k;x;pi A: \(\lim\limits_{x→π}i\cos(x)+j\sin(2x)+k\log(x)=−i+k\log(π)\) |
Q: itg;i/t**2+t**(1/2)*j-t**2*k;t;1;4 A: \(∫_1^4\frac{i+jt^{\frac{5}{2}}−kt^4}{t^2}dt=\frac{3i}{4}+\frac{14j}{3}−21k\) |
Q: itg(t*i-t*j+5*k,t) A: \(=\frac{t(ti-tj+10k}{2}\) |
Q: itg;2*x*i+(x-3)*j+(x-x**2)*k;x;0;1 A: \(∫_0^12ix+j(x−3)−kx(x−1)dx=i−\frac{5j}{2}+\frac{k}{6}\) |
Q: dif;t**2*i+(1+t)*j+(2*t-3)*k;t A: \(\frac{∂}{∂t}(it^2+j(t+1)+k(2t−3))=j+2k+2it\) |
Q: itg(itg(i-2*j+k,t)-2*i+5*j,t)+4*i-6*j-3*k A: = \((\frac{t^2}{2}-2t-4)i+(5t-t^2-6)j+(\frac{t^2}{2}-3)k\) |
Q: dif(itg(i-2*j+k,t)-2*i+5*j,t)+i-2*j+5*k A: = 2i - 4j + 6k |
(1) Tangent and Normal Vectors
The array “vec;tnv(u,t); u; uexpr” or “vec;tnv(r(t), t)” finds the tangent vector of a curve parametrized by r(t) = x(t)i + y(t)j + z(t)k, where “tnv” is the operation name, and “t” is the parameter. Use the array “vec; tnv(r(t),t)/lnt(tnv(r(t),t))” to normalize the tangent vector and obtain the unit tangent vector T. Get the normal vector N by repeating the above array one more time, or use "vec; tnv(tnv(r(t),t)/lnt(tnv(r(t),t)),t)/lnt(tnv(tnv(r(t),t)/lnt(tnv(r(t),t)),t))".
One can also use "dif; r(t); t; n" or "dif(r(t), t, n)" to find the \(n\)th derivative of r(t) = x(t)i + y(t)j + z(t)k. The default n = 1 is optional. Both arrays "dif(r(t), t)" and “tnv(r(t), t)” yield the same tangent vector. It is more convenient for finding the second and third derivatives r’’(t) and r’’’(t) by "dif; r(t); t; 2" and "dif; r(t); t; 3". However, the function "tnv" returns a vector that can be used along with other vector operations.
Table 7.4: Tangent Vectors by “tnv” or “dif” Operations
Q: dif;t^3*i+t*sin(2*t)*j+log(3*t)*k;t;2 A: \(\frac{∂^2}{∂t^2}(it^3+jt\sin(2t)+k\log(3t))=6it+4j\cos(2t)−\frac{k}{t^2}−4jt\sin(2t)\) |
Q: vec;tnv((t**2-t)*i+t**2*j+(t**2+t)*k,t) A: = ⟨−1 + 2t, 2t, 1 + 2t⟩ |
Q: vec;dif((t*i+t**2*j+t**3*k)*(sin(t)*i+sin(t**2)*j+sin(t**3)*k),t) A: \(=3t^5\cos(t^3)+2t^3\cos(t^2)+3t^2\sin(t^3)+2t\sin(t^2)+t\cos(t)+\sin(t)\) |
Q: vec;dif((t*i+t**2*j+t**3*k)*(sin(t)*i+sin(t**2)*j+sin(t**3)*k),t,2) A: \(=−9t^7\sin(t^3)−4t^4\sin(t^2)+24t^4\cos(t^3)+10t^2\cos(t^2)−t\sin(t)+6t\sin(t^3)+2\sin(t^2)+2\cos(t)\) |
Q: vec;tnv(exp(x)*i+exp(-2*y)*j+x**2*k,x)**tnv(exp(x)*i+exp(-2*y)*j+x**2*k,y) A: = ⟨\(4xe^{-2y},0,-2e^{x-2y})\)⟩ |
Q: vec;tnv(cos(t)*i+t*j+sin(t)*k,t)/lnt(tnv(cos(t)*i+t*j+sin(t)*k,t)) A: = ⟨\(\frac{-\sqrt{2}\sin t}{2},\frac{\sqrt{2}}{2},\frac{\sqrt{2}\cos t}{2}\)⟩ |
Q: vec;tnv(tnv((2*t-1)*i+3*t*j+(4-5*t)*k,t),t) A: = ⟨0, 0, 0⟩ |
Q: vec;tnv(3*t*i+4*t*j+k,t)/lnt(tnv(3*t*i+4*t*j+k,t)) A: = ⟨\(\frac{3}{5},\frac{4}{5},0\)⟩ |
Example Let r(t) = ti + cos(t)j + sin(t)k. The array “vec;tnv(t*i+cos(t)*j+sin(t)*k,t)/lnt(tnv(t*i+cos(t)*j+sin(t)*k,t))” finds the unit tangent vector T(t) for r(t). To find the unit normal vector N(t), apply the same operation to T(t) by “vec;tnv(tnv(t*i+cos(t)*j+sin(t)*k,t),t)/lnt(tnv(tnv(t*i+cos(t)*j+sin(t)*k,t),t))” or “tnv; T(t); t”. For the binormal vector B(t) of r(t), use “vec” to calculate T(t) × N(t) by “vec;t**n;t;i/2**(1/2)-sin(t)*j/2**(1/2)+cos(t)*k/2**(1/2);n;-cos(t)*j-sin(t)*k”, which returns \(⟨\frac{\sqrt{2}}{2},\frac{\sqrt{2}\sin t}{2},\frac{-\sqrt{2}\cos t}{2}⟩\).
Q: vec;tnv(t*i+cos(t)*j+sin(t)*k,t) A: = ⟨1, sin(t), cos(t)⟩ |
Q: vec;tnv(tnv(t*i+cos(t)*j+sin(t)*k,t),t) A: = ⟨0, -cos(t), -sin(t)⟩ |
Q: vec;tnv(t*i+cos(t)*j+sin(t)*k,t)/lnt(tnv(t*i+cos(t)*j+sin(t)*k,t)) A: = ⟨\(\frac{\sqrt{2}}{2},\frac{-\sqrt{2}\sin t}{2}, \frac{\sqrt{2}\cos t}{2}\)⟩ |
Q: vec;tnv(tnv(t*i+cos(t)*j+sin(t)*k,t),t)/lnt(tnv(tnv(t*i+cos(t)*j+sin(t)*k,t),t)) A: = ⟨0, -cos(t), -sin(t)⟩ |
(2) Tangential and Normal Components of Acceleration
To find the tangential and normal components of the acceleration for a particle moving along a path parametrized by r(t) = x(t)i + y(t)j + z(t)k, one needs to find r’(t) and r’’(t), and then apply to the formula aT = a·T = \(\frac{\bf{a⋅v}}{||\bf{v}||}\), and aN = a·N = \(\frac{||\bf{v × a}||}{||\bf{v}||}\), where the velocity is v(t) = r’(t) by “tnv; x(t)*i + y(t)*j + z(t)*k; t”, and the acceleration is a(t) = r’’(t) by “dif; x(t)*i + y(t)*j + z(t)*k; t; 2”.
Example let r(t) = ⟨2t, t2, et⟩. Enter "vec;tnv(2*t*i+t**2*j+exp(t)*k,t)*tnv(tnv(2*t*i+t**2*j+exp(t)*k,t),t)/lnt(tnv(2*t*i+t**2*j+exp(t)*k,t))" for the tangential component, which is \(\frac{4t+e^{2t}}{\sqrt{4+4t^2+e^{2t}}}\). Enter "vec;lnt(tnv(tnv(2*t*i+t**2*j+exp(t)*k,t),t)**tnv(2*t*i+t**2*j+exp(t)*k,t))/lnt(tnv(2*t*i+t**2*j+exp(t)*k,t))" for the normal component, which is \(\frac{2\sqrt{4+e^{2t}+(t-1)^2e^{2t}}}{\sqrt{4+4t^2+e^{2t}}}\).
(3) Curvature
To find the curvature for a curve parametrized by r(t) = x(t)i + y(t)j + z(t)k, obtain r’(t) and r’’(t) by “dif” or “tnv” operation, and then apply the curvature formula \(κ(t) = \frac{||\boldsymbol{r}'(t) × \boldsymbol{r}''(t)||}{||\boldsymbol{r}'(t)||^3}\).
Example If r(t) = ⟨cos(t), sin(t), t⟩, "vec;lnt(tnv(cos(t)*i+sin(t)*j+t*k,t)^tnv(tnv(cos(t)*i+sin(t)*j+t*k,t),t))/lnt(tnv(cos(t)*i+sin(t)*j+t*k,t))^3" finds the curvature (κ = 0.5) of the helix r(t) for all t.
(4) Normal Vectors at Points on Space Surfaces
Combining the functions "grd" and "vec", one can find the partial derivatives ru and rv and the normal vector ru × rv at a point (u, v) on a space surface parametrized by r(u, v) = x(u, v)i + y(u, v)j + z(u, v)k.
For instance, let r(u, v) = ⟨u + v, 2u + 3v, u - v⟩. Find ru = ⟨1, 2, 1⟩ by "vec;tnv((u+v)*i+(2*u+3*v)*j+(u-v)*k,u)", and rv = ⟨1, 3, -1⟩ by “vec;tnv((u+v)*i+(2*u+3*v)*j+(u-v)*k,v)”. Thus, the normal vector is ru × rv = ⟨-5, 2, 1⟩ by “vec;(i+2*j+k)**(i+3*j-k)”.
The operation "vec; grd(F(x,y,z), x, y, z)" calculates the gradient vector for a scalar field F(x, y, z), and "vec; grd(F(x,y,z),x,f(u,v,w),y,g(u,v,w),z,h(u,v,w))*tnv(f(u,v,w)*i+g(u,v,w)*j+h(u,v,w)*k,u)" finds the derivative Fu (or Fv, Fw) by the chain rule.
Q: vec;tnv((u+v)*i+(2*u+3*v)*j+(u-v)*k,u) A: = ⟨1, 2, 1⟩ |
Q: vec;tnv((u+v)*i+(2*u+3*v)*j+(u-v)*k,v) A: = ⟨1, 3, -1⟩ |
Q: vec;tnv((u+v)*i+(2*u+3*v)*j+(u-v)*k,u)**tnv((u+v)*i+(2*u+3*v)*j+(u-v)*k,v) A: = ⟨−5, 2, 1⟩ |
Q: vec;grd(x^3-2*x*y*z+z^3,x,u+v,y,u-v,z,u*v)*tnv((u+v)*i+(u-v)*j+u*v*k,u) A: = \(6uv−6u^2v+3u^2v^3+3u^2+3v^2+2v^3\) |
Q: vec;grd(x^2*y-y^3*x+z,x,y,z) A: = ⟨\(2xy-y^3,x^2-3y^2,1\)⟩ |
Q: vec;tnv((u+v)*i+(2*u+3*v)*j+(u-v)*k,u)**tnv((u+v)*i+(2*u+3*v)*j+(u-v)*k,v) A: = ⟨−5, 2, 1⟩ |
(5) Curl, Divergence, Conservative and Laplacian Fields
The array “vec;cul(F, x, y, z)” calculates the curl of a vector field F, where “cul” is the function name, and F = f(x, y, z)i + g(x, y, z)j + h(x, y, z)k is the expression of a vector field, and x; y; z are the independent variables of F.
Replace “cul” with “dvg” to find the divergence of F, and replace “cul” with “csv” to determine if the field F is conservative.
Table 7.5: Curl, Divergence, Conservative Fields by “cul”, “dvg”, “csv” Operations
Q: vec;dvg(-(x*i+y*j+z*k)/(x**2+y**2+z**2)**(3/2),x,y,z) A: dvg \(=0\) |
Q: vec;dvg(x*y*i+y*z*j+x*z*k,x,y,z) A: dvg \(x+y+z\) |
Q: vec;csv(y*i+x*j,x,y) A: True |
Q: vec;csv(y*i-x*j,x,y) A: False |
Q: vec;csv(x/(x**2+y**2)*0.5*i+y/(x**2+y**2)*0.5*j,x,y) A: True |
Q: vec;csv(y*k,x,y) A: False |
Q: vec;cul(-y*i/(x**2+y**2)+x*j/(x**2+y**2),x,y) A: curl \(=⟨0,0,0⟩\) |
Q: vec;cul(2*x*i-y*j+(x-3*z)*k,x,y,z) A: curl \(=⟨0,-1,0⟩\) |
(6) Properties of Curl, Divergence and Laplace Operators
Combine the functions “cul”, “dvg” and “grd” to find a Laplacian field and verify the properties of curl and divergence: (1) curl(∇f) = ∇ × (∇f) = 0; (2) dvg(curl(F)) = ∇ · (∇ × F) = 0.
Table 7.6: Properties of Curl and Divergence, and Laplace Operators
Q: vec;dvg(grd(atan(y/x),x,y),x,y) A: dvg \(=0\) |
Q: vec;dvg(grd(cos(x)+sin(y),x,y),x,y) A: \(-\sin(y)-\cos(x)\) |
Q: vec;dvg(cul(x*y*i+y*z*j+x*z*k,x,y,z),x,y,z) A: \(=0\) |
Q: vec;dvg(cul(u*cos(t)*i+u*sin(t)*j+u*k,u,t),u,t) A: \(=0\) |
Q: vec;cul(grd(x*y**2+y*z**2+z*x**2,x,y,z),x,y,z) A: = (0, 0, 0) |
Q: vec;cul(grd(x*cos(y)+y*sin(x)+z*sin(x*y),x,y,z),x,y,z) A: = (0, 0, 0) |
Q: vec;cul(grd(e**(x*y*z),x,y,z),x,y,z) A: = ⟨0, 0, 0⟩ |
Q: vec;dvg(cul(grd(e**(x*y*z),x,y,z),x,y,z),x,y,z) A: = 0 |
7 Differential Equations
I. Ordinary Differential Equations
The operation “ode” is for solving an ordinary differential equation (ODE), and the array "ode; expr; iv" or "ode(expr, iv)" helps find a general solution to an ODE, where "expr" is an ODE expression, and "iv" is the independent variable of the unknown function in the ODE.
Since an ODE must include derivatives of an unknown function, a valid ODE expression (“expr”) must also include expressions of derivatives. Let y be a function of x. Then the “ode” operation requires the first derivative y' of y to x to be written as "y_1", the second derivative y'' as "y_2", and the \(n\)th derivative y(n) as "y_n".
If an ODE involves a function f(x), g(y), or h(z) and their derivatives, use a single letter to represent these functions. For instance, rewrite g(x) + 3*g'(x) = 2 as y + 3*y_1 = 2 or g + 3*g_1 = 2, and then enter the array “ode; y + 3*y_1 - 2; x” or “ode(g + 3*g_1 - 2, x)” for the general solution of g(x).
Also use the function “dif” to write an ODE "y_2 - 2*y_1" as "dif(y(x), x, 2) - 2*dif(y(x), x)", and enter the array "ode(dif(y(x), x, 2) - 2*dif(y(x), x))" for the solution of y(x). In this case, rewrite the unknown function y as y(x), y'(x) as dif(y(x), x), and y''(x) as dif(y(x), x, 2). Notice that given y(x) is function of x, there is no need to specify the independent variable x in the array for the general solution.
Q: ode;y_2-2*y_1;x A: solve \(−2\frac{d}{dx}y(x)+\frac{d^2}{dx^2}y(x)=0\) for \(y(x)=C_1+C_2e^{2x}\) |
Q: ode(dif(y(x),x,2)-2*dif(y(x),x)) A: \(=y(x)=C_1+C_2e^{2x}\) |
Table 8.1: Ordinary Differential Equations by “ode” Operation
Q: ode;y+3*y_1-2;x A: solve \(y(x)+3\frac{d}{dx}y(x)−2=0\) for \(y(x)=C_1e^{−\frac{x}{3}}+2\) |
Q: ode;y_2+9*y;z A: solve \(9y(z)+\frac{d^2}{dz^2}y(z)=0\) for \(y(z)=C_1\sin(3z)+C_2\cos(3z)\) |
Q: ode;g_2-g_1-z;z A: solve \(−z−\frac{d}{dz}g(z)+\frac{d^2}{dz^2}g(z)=0\) for \(g(z)=C_1+C_2e^z−\frac{z^2}{2}−z\) |
Q: ode(dif(g(z),z,2)-dif(g(z),z)-z) A: \(=g(z)=C_1+C_2e^z−\frac{z^2}{2}−z\) |
Q: ode;y_1-k*y;x A: solve \(−ky(x)+\frac{d}{dx}y(x)=0\) for \(y(x)=C_1e^{kx}\) |
Q: ode;y_2+2*y_1+3*y-sin(x);x A: solve \(3y(x)−\sin(x)+2\frac{d}{dx}y(x)+\frac{d^2}{dx^2}y(x)=0\) for \(y(x)=(C_1\sin(\sqrt{2}x)+C_2\cos(\sqrt{2}x))e^{−x}+\frac{\sin(x)}{4}−\frac{\cos(x)}{4}\) |
Q: ode;x*y_1-y-x*y**2;x A: solve \(−xy^2(x)+x\frac{d}{dx}y(x)−y(x)=0\) for \(y(x)=−\frac{2x}{C_1+x^2}\) |
Q: ode;y_2-4*y_1+5*y-x*exp(2*x);x A: solve \(−xe^{2x}+5y(x)−4\frac{d}{dx}y(x)+\frac{d^2}{dx^2}y(x)=0\) for \(y(x)=(C_1\sin(x)+C_2\cos(x)+x)e^{2x}\) |
Q: ode;y_2+2*y_1+2*y-exp(x)*cos(x);x A: solve \(2y(x)−e^x\cos(x)+2\frac{d}{dx}y(x)+\frac{d^2}{dx^2}y(x)=0\) for \(y(x)=(C_1\sin(x)+C_2\cos(x))e^{−x}+\frac{(\sin(x)+\cos(x))e^x}{8}\) |
Q: ode;y_2+2*y_1-3*y-1;x A: solve \(−3y(x)+2\frac{d}{dx}y(x)+\frac{d^2}{dx^2}y(x)−1=0\) for \(y(x)=C_1e^{−3x}+C_2e^x−\frac{1}{3}\) |
Q: ode;y_1-y-x*y**(-1);x A: solve \(−xy(x)−y(x)+\frac{d}{dx}y(x)=0\) for \([y(x)=−\frac{\sqrt{C_1e^{2x}−4x−2}}{2}, y(x)=\frac{\sqrt{C_1e^{2x}−4x−2}}{2}]\) |
Q: ode;y_3-x-y;x A: solve \(−x−y(x)+\frac{d^3}{dx^3}y(x)=0\) for \(y(x)=C_3e^x−x+(C_1\sin(\frac{\sqrt{3}x}{2})+C_2\cos\frac{\sqrt{3}x}{2}))e^{−\frac{x}{2}}\) |
Q: ode;3*y_4-4*x;x A: solve \(−4x+3\frac{d^4}{dx^4}y(x)=0\) for \(y(x)=C_1+C_2x+C_3x^2+C_4x^3+\frac{x^5}{90}\) |
II. Partial Differential Equations
Suppose z = f(x, y) is a function of x and y. The first-order partial differential equation (PDE) involves the partial derivatives zx(x, y) or zy(x, y). Use the array “pde; expr; x; y” or “pde(expr, x, y)” to find the general solution to z(x, y), where “expr” represents a PDE expression, “x” and “y” are the independent variables of the unknown function “z(x, y)”. In the “pde” operation, the partial derivatives zx(x, y) and zy(x, y) are written as “z_x” and “z_y”, respectively.
In general, the array "pde; expr; iv1; iv2" or "pde(expr, iv1, iv2)" helps find the general solution to an unknown function of two variables in the first-order linear PDE.
Also use the "dif" function to write the partial derivative fx as "dif(f(x, y), x)", and fy as "dif(f(x, y), y)" in a PDE, and find the general solution to f(x, y). For example, the array "pde(dif(f(x,y),x))" gives the same result as "pde;f_x;x;y".
Table 8.2: Partial Differential Equations by “pde” Operation
Q: pde;f_x;x;y A: solve \(\frac{∂}{∂x}f(x,y)=0\) for \(f(x,y)=F(−y)\) |
Q: pde;f_x-y^3;x;y A: solve \(\frac{∂}{∂x}f(x,y)−y^3=0\) for \(f(x,y)=xy^3+F(−y)\) |
Q: pde;z_x+y;x;y A: solve \(y+\frac{∂}{∂x}z(x,y)=0\) for \(z(x,y)=−xy+F(−y)\) |
Q: pde;y*z_x-x;x;y A: solve \(−x+y\frac{∂}{∂x}z(x,y)=0\) for \(z(x,y)=\frac{x^2}{2y}+F(y)\) |
Q: pde;w_u-w_v;u;v A: solve \(\frac{∂}{∂u}w(u,v)−\frac{∂}{∂v}w(u,v)=0\) for \(w(u,v)=F(−u−v)\) |
Q: pde;z_y-x*y**2;x;y A: solve \(−xy^2+\frac{∂}{∂y}z(x,y)=0\) for \(z(x,y)=\frac{xy^3}{3}+F(x)\) |
Q: pde;w_x+w_y;x;y A: solve \(\frac{∂}{∂x}w(x,y)+\frac{∂}{∂y}w(x,y)=0\) for \(w(x,y)=F(x−y)\) |
Q: pde;f_x-x*y;x;y A: solve \(−xy+\frac{∂}{∂x}f(x,y)=0\) for \(f(x,y)=\frac{x^2y}{2}+F(−y)\) |
III. Systems of Ordinary Differential Equations
The array "ods; iv; equ1; equ2; ... " or "ods(iv, equ1, equ2, ...)" helps solve a system of the first-order linear ODEs, where "ods" is the operation name, "iv" the independent variable of unknown functions to be solved in the system, and "equ1; equ2; ..." each represents an ODE in the system.
Table 8.3: Systems of Ordinary Differential Equations by “ods” Operation
Q: ods;t;x_1-3*x+2*y;y_1-2*x+y A: solve \([−3x(t)+2y(t)+\frac{d}{dt}x(t)=0, −2x(t)+y(t)+\frac{d}{dt}y(t)=0]\) for \([[x(t)=2C_1te^t+(C_1+2C_2)e^t, y(t)=2C_1te^t+2C_2e^t]]\) |
Q: ods;t;x_1+y+z;y_1+x+z;z_1+x+y A: solve \([y(t)+z(t)+\frac{d}{dt}x(t)=0, x(t)+z(t)+\frac{d}{dt}y(t)=0, x(t)+y(t)+\frac{d}{dt}z(t)=0]\) for \([[x(t)=C_1e^{−2t}−(C_2+C_3)e^t, y(t)=C_1e^{−2t}+C_2e^t, z(t)=C_1e^{−2t}+C_3e^t]]\) |
8 Linear Algebra
I. Vectors and Matrices Manipulations
Here all matrix operations must start with the module name "mat" to distinguish it from other modules (calculus) and operations. A typical pattern for matrix or vector operation is "mat; f(A); A; matAarray", where "f(A)" represents the operation for matrix A, and the subsequent pair "A; matArray" defines the m × n matrix A with entries included in the square bracket [(a11, ···, a1n), ···, (am1, ···, amn)].
If f(A) = A, the pattern "mat; A; A; matAarray" just simply displays the entries of A. Other patterns like "mat; elf(A); A; matAarray" reduces A to an echelon form, and "mat; A*tsp(A); A; matArray" calculates the product AAT. This basic pattern can be extended to two or more matrices for more complicated operations such as "mat; f(A, B); A; matAarray, B; matBarray", "mat; f(A, B, C); A; matAarray, B; matBarray; C; matCarray", and so on. For example, "mat; inv(P)*A*P; A; matAarray; P; matParray" gives the product P-1AP, which are typically used for computing similar matrices or diagoalization if the columns of P have the full set of eigenvectors of A.
Row Vectors, Column Vectors, and Matrices For a row vector v = (a, b, c), "mat; v; v; [(a,b,c)]" displays v as a 1 × 3 matrix. For a column vector, "mat; v; v; [a, b, c]" displays v as a 3 × 1 matrix. The elements of a row or column are separated by a comma (,) and included in a square parenthesis. A row or column vector is a special form of a matrix. In particular, "mat; A; A; [c]" returns a 1 × 1 matrix with the only entry c.
A matrix consists of multiple rows or columns and can be entered in a similar fashion. A 2 × 2 matrix A can be entered and displayed by "mat; A; A; [(a, b), (c, d)]" with the first row "(a, b)" and the second row "(c, d)". Similarly, "mat; A; A; [(a, b, c), (x, y, z), (1, 2, 3)]" shows a 3 × 3 matrix with three rows in the order within the square bracket. The entries of each row are within a separate parathesis, and each row is seperated by a comma (,).
It is more convenient to enter a matrix row by row in order. Use the transpose function "tsp(A)" if columns are of concern.
Table 9.1.1: Row Vectors, Column Vectors, Matrices
Q: mat;a;a;[(2,2/3,-5^(1/2),pi,c^2)] A: \(=\begin{bmatrix}2&\frac{2}{3}&-\sqrt{5}&π&c^2\end{bmatrix}\) |
Q: mat;b;b;[5,-3,7] A: \(=\begin{bmatrix}5\\-3\\7\end{bmatrix}\) |
Q: mat;A;A;[(2,3,5,2+3*I),(0,1/2^(1/2),-1,0),(2,-1,3,-5*I)] A: \(=\begin{bmatrix}2&3&5&2+3i\\0&\frac{\sqrt{2}}{2}&-1&0\\2&-1&3&-5i\end{bmatrix}\) |
Echelon Form and Reduced Row Echelon Form The function "elf(A)" reduces a matrix A to echelon form, and the function "rref(A)" gives the reduced row echelon form of A.
Table 9.1.2: Echelon Forms and Reduced Row Echelon Forms
Q: mat;rref(A);A;[(1,3,-2,0,2,0,0),(2,6,-5,-2,4,-3,-1),(0,0,5,10,0,15,5),(2,6,0,8,4,18,6)] A: rref \(=\begin{bmatrix}1&2&0&4&2&0&0 \\0&0&1&2&0&0&0\\ 0&0&0&0&0&1&\frac{1}{3}\\0&0&0&0&0&0&0\end{bmatrix}\) |
Q: mat;rref(A);A;[(1,2,2),(2,5,7),(3,6,8)] A: rref \(=\begin{bmatrix}1&0&0\\0&1&0\\0&0&1\end{bmatrix}\) |
Q: mat;elf(A);A;[(1,2,1,3,3),(2,4,0,4,4),(1,2,3,5,5),(2,4,0,4,7)] A: elf \(=\begin{bmatrix}1&2&1&3&3\\0&0&-2&-2&-2\\0&0&0&0&6\\0&0&0&0&0\end{bmatrix}\) |
Augmented Matrices Matrices with compatible dimensions can be merged to form a new matrix. The augmented matrix [A | b] of the linear system \(A{\bf x}={\bf b}\) can be obtained by the function "mrg(A, b)" that adds \({\bf b}\) as a column to the right of A, where A is the coefficient matrix and \({\bf b}\) is the constant vector (column). With the option "1", "mrg(A,B,1)" adds the matrix B as rows under A and form a new matrix with the same number of columns.
Table 9.1.3: Augmented Matrices
Q: mat;mrg(A,b);A;[(2,3,-2),(1,0,5),(3,1,-2)];b;[a,b,c] A: \(=\begin{bmatrix}2&3&-2&a\\1&0&5&b\\3&1&-2&c\end{bmatrix}\) |
Q: mat;mrg(A,B);A;[(1,2,3),(1,0,4)];B;[(a,b),(c,d)] A: \(=\begin{bmatrix}1&2&3&a&b\\1&0&4&c&d\end{bmatrix}\) |
Q: mat;mrg(A,B,1);A;[(2,1,3),(5,1,0)];B;[(a,b,c),(x,y,z)] A: \(=\begin{bmatrix}2&1&3\\5&1&0\\a&b&c\\x&y&z\end{bmatrix}\) |
Rotation Matrices For a given angle θ measured in radian, the functions "rtm(θ, 1)", "rtm(θ, 2)", and "rtm(θ, 3)" returns the the rotation matrices Rx, Ry, and Ry that correspond to the rotation about the x-axis, y-axis, and z-axis, respectively. They are 3 × 3 orthogonal matrices.
Table 9.1.4: Rotation Matrices
Q: mat;rtm(pi/4,1) A: Rx \(=\begin{bmatrix}1&0&0\\0&\frac{\sqrt{2}}{2}&\frac{\sqrt{2}}{2}\\0&-\frac{\sqrt{2}}{2}& \frac{\sqrt{2}}{2}\end{bmatrix}\) |
Q: mat;rtm(pi/2,2) A: Ry \(=\begin{bmatrix}0&0&-1\\0&1&0\\1&0&0\end{bmatrix}\) |
Q: mat;rtm(pi/3,3) A: Rz\(=\begin{bmatrix}\frac{1}{2}&\frac{\sqrt{3}}{2}&0\\-\frac{\sqrt{3}}{2}&\frac{1}{2}&0\\0&0&1\end{bmatrix}\) |
Jacobian Matrices In vector calculus, the Jacobian matrix is the first partial derivatives of a vector-valued function f(x, y, z) taken with respect to their parameters u, v, and w (for instance). The array "mat; jcb(a, b); a; [x(u,v,w), y(u,v,w), z(u,v,w)]; b; [u, v, w]" calculates the Jacobian matrix of f(x, y, z) = x(u, v, w)i + y(u, v, w)j + z(u, v, w)k", where "a" is the components vector "⟨x(u, v, w), y(u, v, w), z(u, v, w)⟩" of f(x, y, z), and "b" is a vector "⟨u, v, w⟩" consisting of the (symbolic) variables u, v, and w. The function "det(jcb(a,b))" calculates the determinant of the Jacobian matrix jcb(a,b).
Table 9.1.5: Jacobian Matrix and Determinant
Q: mat;jcb(a,b);a;[u-2*v,3*u+v];b;[u,v] A: \(=\begin{bmatrix}1&-2\\3&1\end{bmatrix}\) |
Q: mat;jcb(a,b);a;[2*u-3*v, u*v];b;[u,v] A: \(=\begin{bmatrix}2&-3\\v&u\end{bmatrix}\) |
Q: mat;jcb(u,v);u;[x^2*y,5*x+sin(y)];v;[x,y] A: \(=\begin{bmatrix}2xy&x^2\\5&\cos y\end{bmatrix}\) |
Q: mat;det(jcb(a,b));a;[u-2*v,3*u+v];b;[u,v] A: \(=7\) |
Q: mat;det(jcb(a,b));a;[2*u-3*v, u*v];b;[u,v] A: Jacobian \(=2u+3v\) |
Q: mat;det(jcb(u,v));u;[x^2*y,5*x+sin(y)];v;[x,y] A: \(=2xy\cos y-5x^2\) |
Q: mat;det(jcb(x,y));x;[r*cos(t),r*sin(t)];y;[r,t] A: Jacobian \(=r\) |
Q: mat;det(jcb(u,v));u;[r*cos(t),r*sin(t),z];v;[r,t,z] A: Jacobian \(=r\) |
Q: mat;det(jcb(u,v));u;[r*sin(s)*cos(t),r*sin(s)*sin(t),r*cos(s)];v;[r,s,t] A: Jacobian \(=r^2\sin(s)\) |
Q: mat;jcb(x,y);x;[r*cos(t),r*sin(t)];y;[r,t] A: Jacobian \(=\begin{bmatrix}\cos t&-r\sin t\\\sin t&r\cos t\end{bmatrix}\) |
Q: mat;jcb(u,v);u;[r*cos(t),r*sin(t),z];v;[r,t,z] A: Jacobian \(=\begin{bmatrix}\cos t&-r\sin t&0\\\sin t&r\cos t&0\\0&0&1\end{bmatrix}\) |
Q: mat;jcb(u,v);u;[r*sin(s)*cos(t),r*sin(s)*sin(t),r*cos(s)];v;[r,s,t] A: Jacobian \(=\begin{bmatrix}\sin s\cos t&r\cos s\cos t&-r\sin s\sin t\\\sin s\sin t&r\sin t\cos s&r\sin s\cos t\\\cos s&-r\sin s&0\end{bmatrix}\) |
Special Matrices The function "diag(a, b, c)" returns a diagonal matrix with diagonal entries a, b, and c, "eye(m)" returns an m × m identity matrix, "ones(m)" returns an m × m matrix with all ones, and "zeros(m) returns an m × m matrix with all zeros.
Random Matrices The function "rdm(m)" returns an m-square random matrix. In general, "rdm(m, n, type, seed, lower, upper)" returns an m × n random matrix with optional parameters "n, type, seed, lower, upper". There are 6 types of matrices indicated from 0 to 6: 0 - random matrix; 1 - diagonal matrix; 2 - upper triangular matrix; 3 - lower triangular matrix; 4 - symmetric triangular; 5 - Jordan block.
Examples "mat;rdm(4)" returns a 4 × 4 random matrix, "mat;rdm(3,2)" returns a 3 × 2 random matrix, "mat;rdm(3,3,2)" returns a 3 × 3 random upper triangular matrix, "mat;rdm(4,4,4,100,-5,5)" returns a 4 × 4 random symmetric matrix with the seed = 100 and entries randomly selected integers from -5 to 5, and "mat;rdm(4,4,5,1.5)" returns a 4 × 4 Jordan block with eigenvalue equal to 1.5.
Table 9.1.6: Special and Random Matrices
Q: mat;diag(1,2,3) A: \(=\begin{bmatrix}1&0&0\\0&2&0\\0&0&3\end{bmatrix}\) |
Q: mat;ones(3) A: \(=\begin{bmatrix}1&1&1\\1&1&1\\1&1&1\end{bmatrix}\) |
Q: mat;eye(3) A: \(=\begin{bmatrix}1&0&0\\0&1&0\\0&0&1\end{bmatrix}\) |
Q: mat;A;A;rdm(2,3,0,345,0,9) A: \(=\begin{bmatrix}4&0&2\\6&1&3\end{bmatrix}\) |
Q: mat;rdm(3,3,4,20) A: \(=\begin{bmatrix}-6&-2&10\\-2&-7&0\\10&0&8\end{bmatrix}\) |
Q: mat;rdm(3,3,2,30) A: \(=\begin{bmatrix}-7&-1&9\\0&9&10\\0&0&-9\end{bmatrix}\) |
II. Determinant, Trace, Norm, Rank, Definiteness, Diagonalizable, Nilpotent
Determinant, Trace, Norm, Rank, Condition Number For a given matrix A, the function "norm(A)" returns the Frobenius norm, "rank(A)" returns the rank, and "cnd(A)" returns the condition number.
The "norm" function has an option for different types of norms. By default, "norm(A)" returns the 2-norm of A (Frobenius). The function "norm(A,1)" returns the 1-norm of A, "norm(A,2)" returns 2-norm, and "norm(A,oo)" returns infinity norm.
For a square matrix, the function "det(A)" returns its determinant. The matrix A is singular if det(A) = 0, and nonsingular otherwise. This can be used to test if a matrix is invertiable. The "trace(A)" returns the sum of the diagonal entries of A.
Table 9.2.1: Determinant, Norm, Rank, and Condition Number
Q: mat;norm(A);A;[(1,1,1),(1,2,2),(1,2,3)] A: = \(\sqrt{26}\) |
Q: mat;rank(B);B;[(1,2,1,2,2),(0,3,1,-2,2),(4,-2,0,1,1),(3,0,1,-1,4)] A: = 4 |
Q: mat;det(A);A;[(2,-1,0),(1,2,1),(0,-1,2)] A: = 12 |
Q: mat;cnd(A);A;[(1.85,2.36),(-3.71,5.4)] A: = 2.34264621295597 |
Q: mat;norm(B,1);B;[(1,2,1,2),(0,3,1,-2),(4,-2,0,1),(3,0,1,-1)] A: = 8 |
Q: mat;norm(A,oo);A;[(2,-1,0),(1,2,1),(0,-1,2)] A: = 4 |
True or False The function "tof(A)" (True or False) tests whether a square matrix is positive definite by default. Options can be added to the function as "tof(A, type)", and there are seven types indicated by integers from 0 to 6: 0 - diagonalizable, 1 - positive definite; 2 - negative definite; 3 - positive semidefinite; 4 - negative semidefinite; 5 - indefinite; 6 - nilpotent. To test definiteness indicated from 1 to 5, the matrix A must be symmetric or Hermitian.
Table 9.2.2: Diagonalizable, Positive Definite, and Nilpotent
Q: mat;tof(A,0);A;[(2,-1,0),(1,2,1),(0,-1,2)] A: = True |
Q: mat;tof(B);B;[(1,2,1,2),(0,3,1,-2),(4,-2,0,1),(3,0,1,-1)] A: = False |
Q: mat;tof(A,6);A;[(5,-3,2),(15,-9,6),(10,-6,4)] A: = True |
Minors, Cofactors and Adjugate Matrix For the determinant (minor) of the submatrix after deleting the \(i\)th row and \(j\)th column of A, the function "mno(A, i, j)" returns the minor corresponding to the entry (i, j), and the function "cfm(A)" returns the cofactor (signed minor) matrix of A (for all entries). The transpose of the cofactor matrix of A is the ajugate (classic adjoint) of A. Note that the minor corresponds to the entry (1, 1) of A is obtained by mno(A,0,0), rather than mno(A,1,1).
Table 9.2.3: Minor, Cofactor and Adjugate Matrices
Q: mat;mno(C,1,2);C;[(1,6,-1),(2,5,3),(2,1,4)] A: \(=-11\) |
Q: mat;cfm(A);A;[(2,-1,0),(1,2,1),(0,-1,2)] A: \(=\begin{bmatrix}5&-2&-1\\2&4&2\\-1&-24&5\end{bmatrix}\) |
Q: mat;tsp(cfm(A));A;[(2,3,1),(1,0,-4),(5,-1,6)] A: \(=\begin{bmatrix}-4&-19&-12\\-26&7&9\\-1&17&-3\end{bmatrix}\) |
III. Matrix and Vector Operations
Addition, Subtraction, Multiplication, and Power The operators +, -, * also apply to matrix addition, subtraction, scalar and matrix multiplication. For multiplying two matrices A and B, "A*B" and "B*A" calculate the products of AB and BA, respectively, provided they are defined. Enter "A**n" or "A^n" for the power of a matrix A, where "A" must be a square matrix and "n" is a whole number exponent.
For example, the "A+3*B" gets the sum of A + 3B, "A**2-2*A*B + B**2" returns the result of A2 - 2AB + B2.
Transpose, Conjugate, and Conjugate Transpose: The function "tsp(A)" returns AT, the transpose of A. For complex matrices, "tsp(A)" returns the conjugate transpose of A, and "cjg(A)" just returns the conjugate of A.
Matrix Inverse Both "inv(A)" and "A^(-1)" return the inverse of a nonsingular matrix A. If A is not square, "inv(A)" returns the Moore-Penrose pseudoinverse, but "A^(-1)" is not defined.
Note that matrix power with integer exponents only applies to square matrices. The result of "A^(-2)" can be understood as the squared inverse of A. Thus, "A*B**(-1)" gives the result for AB-1, and "3*A*B**3+4*C**(-2)" for 3AB3 + 4C-2, provided they exist.
Matrix Polynomials A matrix polynomial is a polynomial with square matrices as variables. Given an ordinary scalar-valued polynomial \(f(t)=a_0+a_1t+a_2t^2+\cdots+a_nt^n\), the matrix polynomial is \(f(A)=a_0I+a_1A+a_2A^2+\cdots+a_nA^n\). For example, "A^2-3*A+2*eye(2)" calculates the matrix polynomial \(f(A)=A^2-3A+2I_2\).
Table 9.3: Matrix Operations (Transpose, Addition, Subtraction, Multiplication, and Power)
Q: mat;A*B;A;[(1,2,3),(4,5,6)];B;[3,-1,2] A: \(=\begin{bmatrix}7\\19\end{bmatrix}\) |
Q: mat;F*tsp(G);F;[(2,-1,3),(-4,1,2),(0,-1,5)];G;[(1,0,1),(2,3,1)] A: \(=\begin{bmatrix}5&4\\-2&-3\\5&2\end{bmatrix}\) |
Q: mat;A*B;A;[1,2,3];B;[(4,5,6)] A: \(=\begin{bmatrix}4&5&6\\8&10&12\\12&15&18\end{bmatrix}\) |
Q: mat;A*tsp(B);A;[1+I,2,3];B;[4-3*I,5*I,6+I] A: \(=19-6i\) |
Q: mat;a*A*b;a;[(x,y,z)];A;[(2,-1,0),(1,2,1),(0,-1,2)];b;[x,y,z] A: \(=\begin{bmatrix}2x^2+2y^2+2z^2\end{bmatrix}\) |
Q: mat;P*D*inv(P);P;[(1,1,-1),(1,1,0),(1,0,3)];D;diag(1,2,2) A: \(=\begin{bmatrix}-1&3&-1\\-3&5&-1\\-3&3&1\end{bmatrix}\) |
Q: mat;A*tsp(A);A;[(1,2,3),(4,5,6)] A: \(=\begin{bmatrix}14&32\\32&77\end{bmatrix}\) |
Q: mat;tsp(A)*A;A;[(1,2,3),(4,5,6)] A: \(=\begin{bmatrix}17&22&27\\22&29&36\\27&36&45\end{bmatrix}\) |
Q: mat;tsp(A*B)-tsp(B)*tsp(A);A;[1,2,3];B;[(4,5,6)] A: \(=\begin{bmatrix}0&0&0\\0&0&0\\0&0&0\end{bmatrix}\) |
Q: mat;C^2-5*C+6*B;C;[(1,-2),(1,4)];B;eye(2) A: \(=\begin{bmatrix}0&0\\0&0\end{bmatrix}\) |
Q: mat;2*A+3*A**2;A;[(2,-1,0),(1,2,1),(0,-1,2)] A: \(=\begin{bmatrix}13&-14&-3\\14&10&14\\-3&-14&13\end{bmatrix}\) |
Q: mat;(A-2*B)*(A^2-4*A+6*B);A;[(2,-1,0),(1,2,1),(0,-1,2)];B;eye(3) A: \(=\begin{bmatrix}0&0&0\\0&0&0\\0&0&0\end{bmatrix}\) |
IV. Linear System, Linear Independence, and Vector Coordinates
Solve a Linear System Many problems in linear algebra reduce to finding the solutions of a system of linear equations, and solving a linear system is an important part of linear algebra. To solve a nonhomogeneous system of linear equations Ax = b, form the augmented matrix M = [A, b], and use the function "rref(M)" to obtain the solution, where "A" represents the coefficients matrix and "b" the constant vectors (column). The same results can be obtained by "rref(mrg(A,b))", where "mrg(A,b)" adds b as a column to the right of A. If the system has a unique solution, the solution is in the rightmost column of "rref(M)" or "rref(mrg(A,b))".
If there is a "0 = 1" row in rref(mrg(A,b)), the system has no solution. If there is a free variable in A, the system has infinitely many solutions. The corresponding homogeneous linear system Ax = 0 always has a zero solution. Use "rref(A)" to solve the homogeneous system. It has the zero solution if rref(A) is an identity matrix. If there is a free variable, the system has nonzero solutions. The number of free variables is the dimension of null space of A. The general solution of Ax = b can be expressed as the sum of a particular solution of Ax = b and the null space of A.
Table 9.4: Solving System of Equations
Q: mat;rref(mrg(A,b));A;[(2,1),(3,-2)];b;[5,4] A: Solution \(=[2,1]\) |
Q: mat;rref(mrg(A,b));A;[(1,2,2),(2,5,7),(3,6,8)];b;[1,0,-2] A: Solution \(=\begin{bmatrix}-5&5.5&2.5\end{bmatrix}\) |
Q: mat;rref(mrg(A,b));A;[(2,-1,3,5),(1,0,-1,2),(1,1,-2,3),(0,1,1,1)];b;[1,2,5,-3] A: \(=\begin{bmatrix}-13&-6&-3&6\end{bmatrix}\) |
Q: mat;rref(mrg(A,b));A;[(1,3,-2,0),(2,6,-5,-2),(0,0,5,10)];b;[2,0,1] A: (no solution) rref \(=\begin{bmatrix}1&3&0&4&0\\0&0&1&2&0\\0&0&0&0&1\end{bmatrix}\) |
Q: mat;rref(mrg(A,b));A;[(1,2,-3),(3,0,1),(2,-2,4)];b;(1,2,1) A: (infinitely many solutions) rref \(=\begin{bmatrix}1&0&\frac{1}{3}&\frac{2}{3}\\0&1&\frac{-5}{3}&\frac{1}{6}\\0&0&0&1\end{bmatrix}\) |
Q: mat;rref(A);A;[(1,2,0,3),(2,-4,3,0),(1,2,3,1)] A: (unique solution) rref \(=\begin{bmatrix}1&0&0&2\\0&1&0&\frac{1}{2}\\0&0&1&\frac{-2}{3}\end{bmatrix}\) |
Determine Linear Independence To show a set of vectors S = \(\{{\bf v}_1,{\bf v}_2,\cdots,{\bf v}_n\}\) is linearly independent, form a matrix A = [\({\bf v}_1,{\bf v}_2,\cdots,{\bf v}_n\)] whose columns are the given vectors in S, and reduces A to echelon form by by "elf(A)". The set is linearly dependent if there is a zero row in elf(A), and independent otherwise.
Or solve the homogeneous system Ax = 0 by "rref(A)". The set is linearly dependent if rref(A) has a free column, and independent otherwise.
Determine a Vector in a Span Given a spanning set S = \(\{{\bf v}_1,{\bf v}_2,\cdots,{\bf v}_n\}\), to determine if a vector b is in span(S), solve the linear system Ax = b by "rref(mrg(A,b))", where the columns of A are the vectors in S. The b is not in span(S) if rref(mrg(A,b)) has a row "0 = 1", which means the system does not have a solution.
Find Coordinate Vectors Given a basis S = \(\{{\bf v}_1,{\bf v}_2,\cdots,{\bf v}_n\}\) of a vector space V, to obtain the coordinate vector of a vector b ∈ V relative to S, solve the linear system Ax = b by "rref(mrg(A,b))", where the columns of A are the vectors in S. The unique solution is the coordinate vector [b]S.
Obtain a Vector Orthogonal to a Subspace Given a set S = \(\{{\bf v}_1,{\bf v}_2,\cdots,{\bf v}_n\}\) of vectors, to obtain a vector x that is orthogonal to the vectors in S, solve the linear system Ax = 0 by "rref(A)", where the rows of A are the vectors in the set. This is because the null space of A is perpendicular to the row space of A.
Obtain Eigenvectors For a given n-square matrix A, to obtain the eigenvectors (or a basis of the eigenspace) belonging to an eigenvalue λ, solve the linear system (A - λI)x = 0 by "rref(A-λ*eye(n))", where "eye(n)" gives an n × n the identity matrix.
Least Squares Method is used for a linear system \(A{\bf x}={\bf b}\) that has more equations than unknowns and the system has no solutions. The method is used for solving \(A^TA\hat{\bf x}=A^T{\bf b}\) for the best solution \(\hat{\bf x}\). If \(A\) has \(n\) independent columns, \(A^TA\) is invertible, and \(\hat{\bf x}=(A^TA)^{-1}A^T{\bf b}\) by "inv(tsp(A)*A)*tsp(A)*b" minimizes the errors \(||{\bf b}-A{\bf x}||\), where \(A\hat{\bf x}=A(A^TA)^{-1}A{\bf b}\) is the projection of \({\bf b}\) onto the column space of \(A\).
V. Vector Space, Dimension, and Basis of Subspaces
Four Fundamental Subspaces For an m × n matrix A, the function "nsp(A)" returns a list of row vectors (or basis) that span the null space of A, and "nsp(tsp(A))" returns a list of vectors (row) that span the null space of AT (left null space), where "nsp" (null space) is the function for finding a basis of the null space (or kernel of a linear mapping with matrix A).
The function "rsp(A)" returns a list of vectors (row) that span the row space of A, and "rsp(tsp(A))" returns a list of vectors (row) that span the column space of A, where "rsp" (row space) is the function for finding a basis for a row space of A.
Also use "rref(A)" to obtain the dimension and a basis for each subspace. The nonzero rows of rref(A) form a basis for the row space, and the number of the nonzero rows is the dimension of the row space or the rank of the matrix A. The columns in A that correspond to the pivot columns in rref(A) form a basis of the column space. If the number of pivots is r, the dimension of N(A) is n - r, and the dimension of N(AT) is m - r.
Dimension and Basis of a Vector Space Given a set of vectors \(S=\{{\bf v}_1,{\bf v}_2,\cdots,{\bf v}_n\}\) that spans a subspace W, form a matrix A whose rows are the vectors in S, and evaluate the echelon matrix "elf(A)" to determine the dimension and a basis of W. The number of the nonzero rows in echelon form is the dimension of W, and the nonzero rows form a basis of W.
Kernel and Image of Linear or Matrix Mapping Since an \(m×n\) matrix \(A\) can be viewed as a linear mapping, the image of the mapping is the column space of \(A\) by "rsp(tsp(A))", and the kernel of the mapping is the null space of \(A\) by "nsp(A)".
Rank and Nullity of Linear or Matrix Mapping If A is the matrix for a linear mapping \({\bf T}:V→U\), the rank of the mapping is the dimension of the image of \({\bf T}\) (or the column space of A), and the nullity of the mapping is the dimension of kernel of \({\bf T}\) (or the null space of A). Reduce the matrix A to echelon form by "elf(A)". The number of pivots is the rank of \({\bf T}\), the number of non-pivot columns is the nullity of \({\bf T}\), and the sum of the rank and nullity is the dimension of \(V\).
Table 9.5: Row and Column Spaces, Null Space, Dimensions and Basis
Q: mat;rsp(A);A;[(2,4,2),(1,2,1),(0,1,0)] A: \(=\begin{bmatrix}2&4&2\\0&1&0\end{bmatrix}\) |
Q: mat;rsp(tsp(A));A;[(2,-1,2),(2,2,4),(2,-1,2)] A: \(=\begin{bmatrix}2&2&2\\0&6&0\end{bmatrix}\) |
Q: mat;nsp(tsp(A));A;[(2,3,1),(3,-4,5),(5,-1,6)] A: \(=\begin{bmatrix}-1\\-1\\1\end{bmatrix}\) |
Q: mat;rank(rsp(B));B;[(1,2,1,2),(0,3,1,-2),(-1,1,0,-4),(3,0,1,-1)] A: \(=3\) |
Q: mat;rank(nsp(B));B;[(1,2,1,2),(0,3,1,-2),(-1,1,0,-4),(3,0,1,-1)] A: \(=1\) |
Q: mat;rank(rsp(tsp(B)));B;[(1,2,1,2),(0,3,1,-2),(-1,1,0,-4),(3,0,1,-1)] A: \(=3\) |
VI. Linear Mappings, Matrix Representations, and Change of Basis
Determine the Matrix for a Linear Operator Given a linear operator \({\bf T}:R^n→R^n\), there is a matrix A such that \({\bf T}({\bf v})=A{\bf v}\) relative to the standard basis of \(R^n\). If \(S=\{{\bf v}_1,{\bf v}_2,\cdots,{\bf v}_n\}\) is a non-standard basis of \(R^n\), the columns of the matrix \([{\bf T}]_S\) for \({\bf T}\) relative to the basis \(S\) are the solution to each linear system \(B{\bf x}={\bf T}({\bf v}_i)\), where the columns of \(B\) are the basis vectors in \(S\).
Instead of solving each linear system one at a time, use "rref(mrg(B,A*B))" to get the matrix for \({\bf T}\), where \(A\) is the matrix for \({\bf T}\) relative to the standard basis, the columns of \(B\) are the basis vectors in S, and the matrix for \({\bf T}\) relative to the basis \(S\) is on the right of the reduced row echelon form. The main concern is to choose a basis that gives the best matrix (diagonal) for \({\bf T}\).
Matrix for General Linear Transformation Any linear mapping \({\bf T}:R^n→R^m\) is assigned an \(m×n\) matrix \(A\) by \({\bf T}({\bf v})=A{\bf v}\) relative to the standard bases of \(R^n\) and \(R^m\). But both spaces \(R^n\) and \(R^m\) have non-standard bases. If \(V=\{{\bf v}_1,{\bf v}_2,\cdots,{\bf v}_n\}\) is a basis for \(R^n\) and \(W=\{{\bf w}_1,{\bf w}_2,\cdots,{\bf w}_m\}\) is a basis for \(R^m\). The matrix for \({\bf T}\) relative to the bases \(V\) and \(W\) can be obtained by "rref(mrg(W, A*V))", where \(A\) is the matrix for \({\bf T}\) relative to the standard bases, the columns of \(V\) are the basis vectors of \(R^n\), the columns of \(W\) are the basis vectors of \(R^m\), and the matrix \([{\bf T}]_{V,W}\) for \({\bf T}\) relative to the bases \(V\) and \(W\) is on the right of the reduced row echelon form.
Change of Basis Matrix Given two different bases \(V=\{{\bf v}_1,\cdots,{\bf v}_n\}\) and \(W=\{{\bf w}_1,\cdots,{\bf w}_n\}\) of \(R^n\), the change of basis matrix from \(V\) to \(W\) is \(P=[[{\bf w}_1]_V,\cdots,[{\bf w}_n]_V]\), where the columns \([{\bf w}_i]_V\) are the coordinate vectors of \({\bf w}_i\) relative to the basis \(V\) for each \(i\). This means to express each basis vector \({\bf w}_i\) in the basis of \(V\), and the question equals to find the coordinate vector \([{\bf w}_i]_V\) by solving the linear system \(V{\bf x}={\bf w}_i\). Thus, the change of basis matrix \(P\) can be obtained by "ref(mrg(V, W))", where the columns of matrix \(V\) are the basis vectors in \(V\) and the columns of \(W\) are the basis vectors in \(W\). If \(V\) is the standard basis of \(R^n\), then \(P=[{\bf w}_1,\cdots,{\bf w}_n] = W\).
The change of basis matrix \(Q\) from \(W\) to \(V\) is \(Q=P^{-1}=[[{\bf v}_1]_W,\cdots,[{\bf v}_n]_W]\). It can be obtained by "rref(mrg(W, V))", or find the inverse of \(P\) directly by "ivs(P)".
VII. Inner Product Space, Projection, and Orthogonality
Inner Product on \(R^n\) or \(C^n\) For vectors u and v in \(C^n\), "tsp(v)*u" returns the inner product of ⟨u, v⟩, and "tsp(u)*v" returns the inner product of ⟨v, u⟩. Note that the results of "tsp(v)*u" and "tsp(u)*v" are a single-entry matrix instead of a scalar.
The function "dot(u,v)" or "dot(v,u)" returns a scalar of the dot product ⟨u, v⟩ or ⟨v, u⟩. For complex vectors, "tsp(u)" gives the conjugate transpose of u, and "dot(tsp(u),v)" or "dot(u,tsp(v))" calculates the dot product of complex vectors.
Projection of v onto w If w is nonzero, the component (Fourier coefficient) \(c\) of v along w can be calculated by "dot(v,w)/dot(w,w)", and the projection of v along w is \(c\)w by "w*dot(v,w)/dot(w,w)".
Projection of v along a Subspace W Suppose W = span\(\{{\bf w}_1,{\bf w}_2,\cdots,{\bf w}_k\}\) is a subspace of \(R^n\). The projection of a vector \({\bf v}∈R^n\) in W equals \(A(A^TA)^{-1}A^T{\bf v}\) by "A*inv(tsp(A)*A)*tsp(A)*v", where the columns of \(A\) are the the vectors \({\bf w}_1,{\bf w}_2,\cdots,{\bf w}_k\). The matrix \(A(A^TA)^{-1}A^T\) is called projection matrix. If W = \({\bf w}\) is a nonzero vector, the projection matrix is \(\frac{{\bf w}{\bf w}^T }{{\bf w}^T{\bf w} }\).
Gram-Schmidt Orthogonalization Process Given a basis \(S=\{{\bf v}_1,{\bf v}_2,\cdots,{\bf v}_n\}\), the function "grs(A)" returns a set of orthogonal vectors from \(S\), where the rows of \(A\) consists the vectors in \(S\) and the rows of grs(A) are orthogonal vectors corresponding to \(S\). The function "grs(A,1)" further normalizes the orthogonal vectors to form an orthonormal set.
Verify Orthogonal Matrix Check if the result of "inv(P)*P" is an identity matrix. If it is an identity matrix, \(P\) is orthogonal. To verify if \(P\) is orthogonal is to verify that each row or column has unit length and that each pair of rows or columns is orthogonal.
Table 9.7: Inner Product, Vector Orthogonalization by Gram-Schmidt Process
Q: mat;B*A;A;[1,2,1+I];B;[(2-3*I,2*I,3+2*I)] A: \(=[3+6i]\) |
Q: mat;cjg(B)*A;A;[1,2,1+I];B;[(2-3*I,2*I,3+2*I)] A: \(=[7]\) |
Q: mat;tsp(a)*b;a;[1+I,2-3*I,4*I];b;[8*I,-4*I,-5*I] A: \(=[0]\) |
Q: mat;grs(A);A;[(1,2,-1),(0,-1,0),(1,1,1)] A: \(=\begin{bmatrix}1&2&-1\\\frac{1}{3}&\frac{-1}{3}&\frac{1}{3}\\1&0&1\end{bmatrix}\) |
Q: mat;grs(A,1);A;[(2,1,2),(0,-1,2),(2,1,1)] A: \(=\frac{1}{3}\begin{bmatrix}2&1&2\\-1&-2&2\\2&-2&-1\end{bmatrix}\) |
Q: mat;grs(A,1)*tsp(grs(A,1));A;[(1,2,3),(0,1,0),(1,1,1)] A: \(=\begin{bmatrix}1&0&0\\0&1&0\\0&0&1\end{bmatrix}\) |
VIII. Eigenvalues/Eigenvectors, Singular Values/Vectors, Quadratic Forms, and Diagonalization
Characteristic Polynomials The function "chp(A)" returns the characteristic polynomial \(p(λ)\) of a matrix \(A\), which is defined by det\((A-λI)\).
Eigenvalues and Eigenvectors The function "eig(A)" returns the eigenvalues and eigenvectors of a matrix \(A\). The output of "eig(A)" (eigenvalues or eigenvectors) displays each eigenvalue, its algebraic multiplicity and the corresponding eigenvectors.
The eigenvalues of \(A\) are the roots of the characteristic polynomial \(f(λ)=\) det\((A-λI)\) and can be obtained by solving the equation det\((A-λI)\) = 0 using "slv;f(λ);λ". The eigenvector with eigenvalue \(λ\) can be obtained by solving the linear system \((A-λI){\bf x}={\bf 0}\) using the "rref" function.
Normal Matrices \(A\) is normal if \(A\) commutes to its transpose. To verify if a square matrix \(A\) is normal is to verify the equality \(AA^{T}=A^{T}A\) by "A*tsp(A) - tsp(A)*A". If the result is a zero matrix, then \(A\) is normal. Hermitian (symmetric), skew-Hermitian (skew-symmetric), positive (definite) matrices are normal matrices.
Table 9.8.1: Eigenvalues and Eigenvectors
Q: mat;chp(A);A;[(0,1,1),(1,0,0),(1,1,1)] A: \(=λ(λ-2)(λ+1)\) |
Q: mat;A*tsp(A)-tsp(A)*A;A;[(2,3*I),(3*I,2)] A: \(=\begin{bmatrix}0&0\\0&0\end{bmatrix}\) |
Q: mat;eig(A);A;[(0,1,1),(1,0,0),(1,1,1)] A: \(=\left[\left((-1, 1),\ \left[\left[\begin{matrix}-1\\1\\0\end{matrix}\right]\right]\right),\ \left((0, 1),\ \left[\left[\begin{matrix}0\\-1\\1\end{matrix}\right]\right]\right),\ \left((2, 1),\ \left[ \left[\begin{matrix}\frac{2}{3}\\\frac{1}{3}\\1\end{matrix}\right]\right]\right)\right]\) |
Q: mat;eig(A);A;[(1,2),(2,1)] A: \(=\left[ \left((-1,1),\ \left[ \left[\begin{matrix}-1\\1\end{matrix}\right]\right]\right), \ \left((3, 1), \ \left[ \left[\begin{matrix}1\\1\end{matrix}\right]\right]\right)\right]\) |
Diagonalization All normal matrices (or linear operators on a complex finite-dimensional inner product space) are diagonalizable. To determine if a matrix is diagonalizable, use "tof(A,0)" and it returns "True" or "False", where the option 0 in the function "tof" is used to test whether a square matrix is diagonalizable.
The function "dgl(A)" returns two matrices \(P\) and \(D\) such that \(D=P^{-1}AP\) and \(D\) is diagonal, where the function "dgl" (diagonalization) has two optional parameters dgl(A, normalize, PD). By default, "dlg(A)" returns two matrices \(P,D\) and the columns of \(P\) are not normalized (normalize = 0). If normalize = 1, the columns of \(P\) are normalized. The function returns the matrix \(P\) if PD = 1, and it return \(D\) if PD = 2. For example, the array "mat; inv(dgl(A,0,1))*A*dgl(A,0,1); A; matAarray" verifies the relation \(P^{-1}AP=D\).
The diagonal matrix \(D\) is similar to \(A\). If the n-square matrix \(A\) has a full set of eigenvectors, choose the eigenvectors as the basis of \(R^n\) by "eig(A)", form a matrix \(P\) with the eigenvectors as its columns, and then the diagonal entries of \(D=P^{-1}AP\) are the eigenvalues of \(A\).
Table 9.8.2: Diagonalization
Q: mat;dgl(A);A;[(4,1,-1),(2,5,-2),(1,1,2)] A: P \(=\begin{bmatrix}-1&1&0\\1&0&2\\0&1&1\end{bmatrix}\) D \(=\begin{bmatrix}3&0&0\\0&3&0\\0&0&5\end{bmatrix}\) |
Q: mat;dgl(A,1);A;[(4,1,-1),(2,5,-2),(1,1,2)] A: P \(=\begin{bmatrix}\frac{-\sqrt{2}}{2}&\frac{\sqrt{2}}{2}&\frac{\sqrt{6}}{6}\\\frac{\sqrt{2}}{2}&0&\frac{\sqrt{6}}{3}\\0&\frac{\sqrt{2}}{2}&\frac{\sqrt{6}}{6}\end{bmatrix}\) D \(=\begin{bmatrix}3&0&0\\0&3&0\\0&0&5\end{bmatrix}\) |
Q: mat;inv(dgl(A,0,1))*A*dgl(A,0,1); A;[(4,1,-1),(2,5,-2),(1,1,2)] A: \(=\begin{bmatrix}3&0&0\\0&3&0\\0&0&5\end{bmatrix}\) |
Diagonalizing Quadratic Forms A quadratic form determines a symmetric matrix \(A\). Use the function "dgl(A)" to find the orthogonal matrix \(P\) such that \(D=P^TAP\). Check the example "mat;dgl(A);A;[(8,3),(3,2)]".
Matrix Exponential and Power If \(A=PDP^{-1},e^{At}=I+A+\frac{(At)^2}{2!}+\cdots+\frac{(At)^n}{n!}+\cdots=Pe^{Dt}P^{-1}\), where the diagonals of \(D\) are the eigenvalues of \(A\), and the columns of \(P\) are the full set of eigenvectors of \(A\). For example, A = [(1,2),(1,0)], expt(A) can be obtained by "eig(A)", and "mat;P*D*inv(P);P;[(2,1),(-1,1)];D;exp(diag(2,-1))" for t = 1. The matrix power \(A^k=XD^kA^{-1}\) can be obtained by "PD^kP^(-1)".
Singular Values and Singular Vectors Any \(m×n\) matrix \(A\) can be factorized as \(A=UΣV^T\) (singular value decomposition), where \(U=[{\bf u}_1,\cdots,{\bf u}_r], V=[{\bf v}_1,\cdots,{\bf v}_r]\) are orthogonal matrices consisting of orthonormal vectors (called singular vectors), and \(Σ=\) diag\((σ_1,\cdots,σ_r)\) for singular values \(σ_1≥σ_2≥\cdots≥σ_r>0\). The singular values \(σ_i\) and singular vectors \({\bf v}_i\) can be obtained by "eig(tsp(A)*A)" because \(A^TA{\bf v}_i=σ_i^2{\bf v}_i\). Since \(A[{\bf v}_1,\cdots,{\bf v}_r]=[{\bf u}_1,\cdots,{\bf u}_r]Σ\) or \(A{\bf v}_i=σ_i{\bf u}_i\), the singular vectors \({\bf u}_i=\frac{A{\bf v}_i}{σ_i}\).
Difference Equations In a difference equation \({\bf u}_{k+1}=A{\bf u}_k\), each step multiplies by \(A\), and the solution is \({\bf u}_k=A^k{\bf u}_0=PD^kP^{-1}{\bf u}_0\), where the columns of \(P\) are the full set of eigenvectors \(\{{\bf x}_1,\cdots,{\bf x}_n\}\) of \(A\). If \({\bf u}_0=c_1{\bf x}_1+\cdots+c_n{\bf x}_n,{\bf u}_k=c_1λ_1^k{\bf x}_1+\cdots+c_nλ_n^k{\bf x}_n\). For example, the Fibonacci sequence \({\bf u}_k=[F_{k+1},F_k]^T=A^k{\bf u}_0\) can be obtained by "mat;a*b*inv(a)*u;a;[((1-sqrt(5))/2,(1+sqrt(5))/2),(1,1)];b;diag((1-sqrt(5))/2,(1+sqrt(5))/2);u;[0,1]", where \(A\) = [(1,1),(1,0)], and the eigenvalue and eigenvectors can be obtained by "mat;eig(A);A;[(1,1),(1,0)]".
System of Differential Equations Extend a 1 by 1 single differential equation (DE) \(u'=u\) or \(u'=λu\) to a system of n by n linear constant-coefficient DEs \(\frac{d{\bf u}}{dt}=A{\bf u}\) or \({\bf u}'=A{\bf u}\). The general solution is \({\bf u}(t)=c_1e^{λ_1t}{\bf x}_1+\cdots+c_ne^{λ_nt}{\bf x}_n\), where \(λ_1,\cdots,λ_n\) and \(\{{\bf x}_1,\cdots,{\bf x}_n\}\) are the eigenvalues and the full set of eigenvectors of \(A\) by "eig(A)". For example, the system \(x'=y+z,y'=x+z,z'=x+y\) with \({\bf u}=[x,y,z]^T, A\) = [(0,1,1),(1,0,1),(1,1,0)]. The general solution is \({\bf u}(t)=c_1e^{-1}[-1,1,0]^T+c_2e^t[-1,0,1]^T+c_3e^{2t}[1,1,1]^T\). If \({\bf u}_0=[2,3,1]^T, [c_1,c_2,c_3]=[1,-1,2]\) by "mat;rref(mrg(P,u));P;[(-1,-1,1),(1,0,1),(0,1,1)];u;[2,3,1]".
IX. Matrix Decomposition
Common matrix decomposition methods are implemented. They are (1) QR-decomposition ("qrd"), (2) LU-decomposition ("lud"), (3) singular value decomposition ("svd"), (4) Cholesky decomposition ("chl"), (5) rank decomposition ("rkd"), and (6) LDL-decomposition ("ldl").
The function "qrd(A)" factors A as A = QR; "lud(A)" factors A as A = LU. In a similar fashion, the function "ldl(A)" returns matrices L and D for which A = LDL*; "cho(A)" returns matrix L for A = LL\(^*\); "svd(A)" returns matrices U, Σ and V for A = UΣV; "rkd(A)" returns matrices C and F for A = CF.
Table 9.9: Matrix Decomposition
Q: mat;qrd(A);A;[(1,1,1),(1,1,3),(2,3,4)] A: Q \(=\begin{bmatrix}\frac{\sqrt{6}}{6} & - \frac{\sqrt{3}}{3} & - \frac{\sqrt{2}}{2}\\\frac{\sqrt{6}}{6} & - \frac{\sqrt{3}}{3} & \frac{\sqrt{2}}{2}\\\frac{\sqrt{6}}{3} & \frac{\sqrt{3}}{3} & 0\end{bmatrix}\) R = \(\begin{bmatrix}\sqrt{6} & \frac{4 \sqrt{6}}{3} & 2 \sqrt{6}\\0 & \frac{\sqrt{3}}{3} & 0\\0 & 0 & \sqrt{2}\end{bmatrix}\) |
Q: mat;lud(A);A;[(4,3,2),(1,6,3),(2,5,1)] A: L \(=\begin{bmatrix}1 & 0 & 0\\\frac{1}{4} & 1 & 0\\\frac{1}{2} & \frac{2}{3} & 1\end{bmatrix}\) U \(=\begin{bmatrix}4 & 3 & 2\\0 & \frac{21}{4} & \frac{5}{2}\\0 & 0 & - \frac{5}{3}\end{bmatrix}\) |
Q: mat;ldl(A);A;((25,15,-5),(15,18,0),(-5,0,11)) A: L \(=\begin{bmatrix}1 & 0 & 0\\\frac{3}{5} & 1 & 0\\- \frac{1}{5} & \frac{1}{3} & 1\end{bmatrix}\) D \(=\begin{bmatrix}25 & 0 & 0\\0 & 9 & 0\\0 & 0 & 9\end{bmatrix} \) |
Q: mat;cho(A);A;[(25,15,-5),(15,18,0),(-5,0,11)] A: L \(=\begin{bmatrix}5 & 0 & 0\\3 & 3 & 0\\-1 & 1 & 3\end{bmatrix}\) |
Q: mat;svd(A);A;[(1,2),(2,1)] A: U \(=\begin{bmatrix}\frac{\sqrt{2}}{2} & \frac{\sqrt{2}}{2}\\- \frac{\sqrt{2}}{2} & \frac{\sqrt{2}}{2}\end{bmatrix}\) Σ \(=\begin{bmatrix}1 & 0\\0 & 3\end{bmatrix}\) V \(=\begin{bmatrix}- \frac{\sqrt{2}}{2} & \frac{\sqrt{2}}{2}\\\frac{\sqrt{2}}{2} & \frac{\sqrt{2}}{2}\end{bmatrix}\) |
Q: mat;rkd(A);A;[(1,1,1),(1,2,2)] A: C \(=\begin{bmatrix}1&1\\1&2\end{bmatrix}\) F \(=\begin{bmatrix}1&0&0\\0&1&1\end{bmatrix}\) |
9 Probability and Statistics
Modules starting with "plt" are for data visualization and exploration (e.g., histograms, scatter plots, boxplots, and graphs of cdfs, pdfs, and ecdfs); modules starting with "stt" are for symbolic computing, data analysis and hypothesis testing (e.g., mean, variance, probabilities, statistical models, hypothesis testing, and random processes).
I. Common Distributions
1. Discrete distributions Discrete distribution modules include Bernoulli (ber), binomial (bin), Poisson (poi), geometric (geo), negative binomial (nbn), hypergeometric (hyp), and discrete uniform (die). Check stt;ber(0.6);v || stt;poi(10);std | stt;bin(10,0.5);P(x>2) || stt;geo(0.7);m || stt;nbn(8,0.6);m || stt;hyp(20,5,12);rvs || stt;die(10);cdf(x) ||. Note that you need to provide appropriate parameter(s) for each discrete distribution. Some distributions have one parameter, and some have two or more parameters.
2. Continuous distributions Continuous distribution modules include normal (n), exponential (epn), uniform (uni), Gamma (gam), Beta (bet), Cauchy (cau), F-distribution (f), Student-t distribution (t), Chi-square (chi). Check stt;n(3,1);q(0.8) || stt;epn(0.5);svf(1.2) || stt;uni(0,2);V(x) || stt;gam(2,3);P(x>2&x<4) || stt;bet(0.5,2);E(x) || stt;cau(0,1);cdf(x) || stt;f(8,11);P(x>13) || stt;t(2);P(x>2@x<-2) || stt;chi(1);q(0.975) ||.
3. User defined distributions Use "drv" (discrete random variable) to create a discrete random variable (r.v.). For example, stt;drv(0.75^x/3);P(x>2) creates a geometric random variable with probability mass function (pdf) \(f(x)=\frac{1}{3}(\frac{3}{4})^x\) for \(x=1,2,\cdots\), and \(\sum_{x=1}^∞f(x)=1\). For a finite discrete random variable, list the probability mass function in two different rows. For example, stt;drv((0,1,2),(2/4,1/4,1/4));cdf(x) ||. The first row lists the possible values the random variable can take, and the second lists their corresponding probabilities that must sum to 1.
Use "crv" (continuous random variable) to create a continuous random variable with specified pdf and interval (range). In this example "stt;crv(3*x^2/26,1,3);E(x)", the pdf is \(f(x)=\frac{3x^2}{26}\) and the range or interval the r.v. can take is [1, 3]. Note that the pdf must be integrated to 1 over this interval.
4. Compute probabilities Use the function "P(.)" for computing probabilities. For example, "P(2)" standards for the probability \(P(X=2)\), "P(x!=2)" for \(P(X≠2)\), "P(x>2)" for \(P(X>2)\), and "P(x<=2)" for \(P(X≤2)\). For compound inequalities, "P(y>2&y<=5)" or "P(2< y<=5)" stands for the probability \(P(2< Y≤5)\) or \(P(Y>2\text{ and }Y≤5)\), and "P(z>=6@z<3)" standards for the probability \(P(Z≥6∪Z<3)\) or \(P(Z≥6\text{ or }Z<3)\). Use similar combinations to compute probabilities. Check stt;bin(10,0.5);P(x>=6) || stt;epn(0.8);P(x<1) || stt;geo(0.7);P(y!=2) || stt;n(0,1);P(x>1.96@x<-1.96) || stt;n(0,1);P(x>-1&x<1) || stt;poi(6);P(2@5) || stt;bin(10,0.5);P(3<=w<=7) ||.
Use the function "P(.|.)" to compute conditional probabilities. For example, "P(x>5|x>=2)" represents the conditional probability \(P(X>5|X≥2)\). Similarly, "P(x<=4|x<8)" represents the probability \(P(X≤4|X<8)\). Check stt;poi(8);P(x<=4|x<8) || stt;poi(8);P(x>4|x>2) || stt;epn(1.2);P(x>2|x>1) || stt;geo(0.6);P(x>5|x>4) ||.
5. Compute mean, variance, skewness, kurtosis, entropy and moments Use the letter "m, v, s, k, h" to obtain the mean, variance, skewness, kurtosis, and entropy of the r.v., respectively. Use "std, med" to get the standard deviation and median of the r.v., respectively. Use "M(r)" for computing moments, where "r" is a positive integer representing the r-th moment. Check stt;ber(0.6);h || stt;bin(20,0.4);m || stt;poi(9);med || stt;n(3,1.5);s || stt;epn(2);k || stt;gam(4,3);std || stt;uni(1,4);v || stt;poi(3);M(3) || stt;n(4,2);M(4) || stt;epn(4);s ||.
You can obtain the above quantities by "E(x), V(x), s(x), k(x), H(x), std(x), med(x)", which calculate mean, variance, skewness, kurtosis, entropy, standard deviation and median, respectively. You can also compute the means and variances of linear combinations of the r.v.. For example, "E(2*x+1)", "V(2x+1)" compute the mean \(E(2X+1)\) and and \(\text{Var}(2X+1)\). In particular, "E(exp(t*x));x" returns the moment generating function for the r.v. ("x"), "E(exp(w*I*x));x" give the characteristic function of the r.v. ("x"). Ensure to add "x" to the end to tell the program that letter "x" represents the r.v. (instead of others letters (like "t", "w" or "I") in the expression). For example, stt;n(0,1);E(2*x+1) || stt;n(2,1.5);V(2*x+1) || stt;n(0,1);E(exp(t*x));x || stt;epn(3);E(exp(t*x));x || stt;n(0,1);E(exp(w*x*I));x || stt;crv(3*x^2/26,1,3);E(x) || stt;crv(3*x^2/26,1,3);std(x) ||.
6. Compute cdf, pdf, percentile, and (inverse) survival function Use "pdf(a), cdf(a), svf(a), isf(p), q(p)" to compute the value of pdf, cdf, survival function, inverse survival function, and the p-th percentile (quantile), respectively, for a given number "a" or "p" (for p ∈ [0, 1]). For example, stt;bin(10,0.7);cdf(6) || stt;poi(12);pdf(10) || stt;t(8);q(0.95) || stt;epn(0.8);svf(1) || stt;epn(2);isf(0.6) ||.
Use "pdf(x)" and "cdf(x)" to show the formulas for the pdf and cdf of the r.v. "x". For example, stt;n(0,1);pdf(x) || stt;epn(1);cdf(x) ||.
7. Simulating samples Use "rvs(n)" for simulating a random sample of size "n" from common distributions or user-defined distributions. For example, stt;chi(1);rvs(3) || stt;t(8);rvs(20) || stt;hyp(15,4,8);rvs(20) ||.
Use keyword "d" to obtain some summary statistics from simulated samples. Observe how these statistics change as the sample size n increases and examine the relationship between the sample statistics and population parameters. For example, stt;poi(20);rvs(30);d || stt;poi(20);rvs(300);d ||.
II. Descriptive Statistics
For a data set with one row of numbers, you can get the following statistics by keyword "d" (descriptive): sample size, min, max, mean, standard deviation (std), variance, skewness, kurtosis, median, inter-quantile range, and the standard error for mean estimate. Check stt;dat(5,1,10,5,6,10,9,9,4,8);d || stt;dat(1.99,-0.29,-0.93,-0.82,1.73,-0.57,-0.91,0.2,-0.42,0.2);d ||.
Use keyword "z" for the z score of each value in the sample, relative to the sample mean and standard deviation. For example, stt;dat(11.73,13.93,12.79, 13.92,12.34,11.15,13.14,11.86,16.61,13.2);z ||.
Compute the p-th quantile or 100p% percentile by function "q(p)", where "p" is a number between 0 and 1. For example, stt;dat(5,1,10,5,6,10,9,9,4,8);q(0.6) ||. You can also compute the empirical cumulative density function for any number "a" by the function "ecdf(a)". For example, stt;dat(5,1,10,5,6,10,9,9,4,8);ecdf(2) || stt;dat(5,1,10,5,6,10,9,9,4,8);ecdf(6.7) ||.
III. Data Visualization and Exploration
To obtain a graph, start with "plt" rather than "stt". Use the form "plt;dat(one row);ecdf" to obtain the graph of the empirical cumulative density function, use form "plt;dat(one rwo);kde" to obtain the graph of Gaussian kernel density estimate for a continuous random variable, use "plt;dat(one rwo);pt" or "plt;dat((rowX),(rowY));pt" to obtain the scatter plot of your data (one or two rows for variables X and Y), and use form "plt;dat((row1),(row2),...,(rowk));box" to obtain the boxplot for one or multiple rows of your data. Check the examples: plt;dat((-1,2,1,0.5,4,3),(-2.8,3,2,0.8,7,5));pt || plt;dat(3,12,5,5,6,9,7,7,5,6,10,12,6,7,8,7,8,10,7,6);ecdf || plt;dat(4.97,4.96,6.38,4.85,5.89,5.13,6.38);box || plt;dat(3,12,5,5,6,9,7,7,5,6,10,12,6,7,8,7,8,10,7,6);kde || plt;dat((3,12,5,5,6,9,7,7,5,6,10,12,6),(2,8,5,9,-5,4,7,7,8,7,8,10,7));box ||.
You can plot the probability density function (pdf), cumulative density function (cdf) and histogram (hist) of samples randomly generated from some common distributions. For example, plt;n(2,1);pdf || plt;n(2,1);cdf || plt;n(2,1);hist || plt;poi(5);cdf || plt;poi(5);hist ||. Note that "n(2,1)" standards a normal distribution with mean 2 and standard deviation 1, and "poi(5)" for a Poisson distribution with mean 5.
IV. Hypothesis Testing
1. Student-t test Use "t1" for one-sample t-test, "t2" for two-samples t-test, and "pt" for paired-samples t-test. For example, stt;dat(2.84,3.76,2.61,4.29,2.15,1.98,3.21,4.38,2.9,3.11,2.89,2.55,3.74,3.93,2.95);t1;3 || tests the mean equals 3; stt;dat((4,2,1,5,0,5,1,1,3,3,0,7,2,3,7),(6,2,6,5,2,0,4,3,8,1,3,7,4,5,5));t2 || tests if the two means are significantly different; stt;dat((5,2,8,4,1),(7,3,6,5,3));pt || tests if the two means are significantly different before and after some treatment.
2. Goodness of fit test Use "chi" to determine whether there is a statistically significant difference between the expected frequencies and the observed frequencies in one or more categories of a contingency table (test of homogeneity). For example, stt;dat((5,8,9,2,1,7),(6,6,6,4,4,6));chi ||, where the first row is the observed counts and the second row gives the expected frequencies. When just observed frequencies are given, it is assumed that the expected frequencies are uniform and given by the mean of the observed frequencies. For example, stt;dat(5,8,9,2,1,7);chi ||.
Use "n" to test normality. Use "ks1" (Kolmogorov-Smirnov test one sample) to test if a sample comes from a certain population distribution, and use "ks2" (Kolmogorov-Smirnov test one sample) to test if two samples come from the same distribution. For example, stt;dat(6.03,5.41,4.01,6.17,3.93,5.24,5.97,6.4,4.58,6.11,5.43,5.65,6,4.31,4.42);n || stt;dat((1,7,9,7,12,9,12,9,6,12),(3,7,7,8,9,10,8,7,6,13));ks2 ||. To use "ks1", specify the distribution by keyword such as "n", "t", "f", "chi", "exp", "poi", "cau", "gam", "bet", and "uni", followed by its necessary parameter(s). For example, stt;dat(6.03,5.41,4.01,6.17,3.93,5.24,5.97,6.4,4.58,6.11,5.43,5.65,6,4.31,4.42);ks1;n;3;1 || stt;dat(6.03,5.41,4.01,6.17,3.93,5.24,5.97, 6.4,4.58,6.11,5.43,5.65,6,4.31,4.42);ks1;n;5;1 || stt;dat(12,4,5,9,8,10,5,9,1,5,9,9,6,7,3);ks1;poi;7 || stt;dat(1.27,2.3,1.56,0.48,4.44,1.52,1.09,0.19, 1.5,1.27,2.2,0.59,2.43,1.67,0.45);ks1;epn;0.8 ||.
3. Analysis of variance (ANOVA) Use "f1" for one-way ANOVA and "f2" for two-way ANOVA. For example, a factor of three levels by stt;dat((2,3,4,5),(3,4,5,6),(4,3,5,7));f1 ||. Two factors A and B with 3 levels for A and 2 levels for B by stt;dat(((2,3,4,5),(8,9,8,8)),((3,4,5,6),(7,7,8,8)),((4,3,5,7),(9,10,11,9)));f2 ||. For two-way ANOVA, use "n" for interaction. Check stt;dat(((2,3,4,5),(8,9,8,8)),((3,4,5,6),(7,7,8,8)),((4,3,5,7),(9,10,11,9)));f2;n ||.
4. Nonparametric test Use "mw" (Mann-Whitney U-test) to determine if two samples come from the same population in a nonparametric way. Kruskal-Wallis H-test by "kw" extends Mann-Whitney U-test to more than two samples (analogue to one-way ANOVA). Use "w" (Wilcoxon signed-rank test) to test the null hypothesis that two related paired samples come from the same distribution (nonparametric version of paired-samples t-test). When using the Wilcoxon signed-rank test, input the differences of each pair in one row. For example, stt;dat((1,7,9,7,12,9,12,9,6,12),(3,7,7,8,9,10,8,7,6,13));mw || stt;dat((2,3,4,5),(3,4,5,6),(4,3,5,7));kw || stt;dat(-2,-1,2,-1,-2);w ||.
5. Test of independence Use "cnt" (contingency table) for test of independence. For example, check the observed counts in a
3 × 2 table by stt;dat((32,43,25),(27,30,30));cnt ||.
V. Generalized Linear Models
Use "ols" for both simple or multiple linear regression. Note that the response variable is listed in the last row and explanatory variable(s) are listed before the response variable. For example, stt;dat((2,3,6,8,1,3,5,9,2),(8,10,9,12,4,6,8,13,3));ols || stt;dat((2,3,6,8,1,3,5,9,2),(0,0,0,0,1,1,1,1,1),(8,10,9,12,4,6,8,13,3));ols ||. For predicted values and residuals, use "ols;pr"; for the predicted value given a new observation, use "ols;p(a)" or "ols;p(a,b)". For example, stt;dat((2,3,6,8,1,3,5,9,2),(8,10,9,12,4,6,8,13,3));ols;pr || stt;dat((2,3,6,8,1,3,5,9,2),(8,10,9,12,4,6,8,13,3));ols;p(4) || stt;dat((2,3,6,8,1,3,5,9,2),(0,0,0,0,1,1,1,1,1),(8,10,9,12,4,6,8,13,3));ols;pr || stt;dat((2,3,6,8,1,3,5,9,2),(0,0,0,0,1,1,1,1,1),(8,10,9,12,4,6,8,13,3));ols;p(4,1) ||.
Use "glm;b" for logistic regression, where "b" indicates the binomial family and logit link function. Note that the response variable, which is binary, must be listed in the last row in the data set. For example, stt;dat((3.78,2.44,2.09,0.14,1.72,1.65,4.92,4.37,4.96,4.52,3.69,5.88),(0,0,0,0,0,0,1,1,1,1,1,1));glm;b ||.
Use "pr;n" (polynomial regression) for polynomial regression, where "n" is a positive integer for the order of degree. For example, stt;dat((3,2,3,1,7,5,2,9),(12,5,8,2,38,28,5,90));pr;2 ||. Check the scatter plot by plt;dat((3,2,3,1,7,5,2,9),(12,5,8,2,38,28,5,90));pt ||.
Use "log" for log linear models. For three-way tables, add model generators such as "12", "23", "13", "12+23", "12+13", "13+23", "12+13+23" to the end. Note that the row and column indicators are listed as explanatory variables before the counts, which are listed in the last row as response variable. For example; stt;dat((1,1,1,1,0,0,0,0),(0,1,0,1,0,1,0,1),(0,1,0,1,0,1,0,1),(35,59,47,112,42,77,26,76));log || stt;dat((1,1,1,1,0,0,0,0),(0,1,0,1,0,1,0,1),(0,1,0,1,0,1,0,1),(35,59,47,112,42,77,26,76));log;12+23 ||.
VI. Random Process
Use "dmc" (discrete Markov chain) to create a finite discrete time-homogeneous Markov chain. The first row "(1,2,3)" in the example "stt;dmc((1,2,3),[(0.2,0.3,0.5),(0.3,0.5,0.2),(0.5,0.3,0.2)]);tp" lists the discrete state space, and the second portion is a 3 × 3 (constant) one-step transition matrix. Note that each row of the transition matrix must sum to 1. The keyword "tp" (transition probability) displays the state space and the transition matrix.
Use keyword "pn;n" for n-step transition matrix, where "n" is a positive integer for "n-step". Use "ld" for limiting distribution, "fm" for fundamental matrix, "cc" for communication class, "ap" for absorbing probabilities, and "dc" for decomposing transition matrix into submatrices with special properties. Use "md;n;(p1, ..., pk)" for n-step marginal distribution with initial distribution "(p1, ..., pk)" that sums to 1. For example, stt;dmc((0,1,2,3,4),[(1/2,1/2,0,0,0),(2/5,1/5,2/5,0,0), (0,0,1,0,0),(0,0,1/2,1/2,0),(1/2,0,0,0,1/2)]);dc || stt;dmc((0,1,2,3,4),[(1/2,1/2,0,0,0),(2/5,1/5,2/5,0,0), (0,0,1,0,0),(0,0,1/2,1/2,0),(1/2,0,0,0,1/2)]);tp || stt;dmc((1,2,3),[(0.2,0.3,0.5),(0.3,0.5,0.2),(0.5,0.3,0.2)]);pn;7 || stt;dmc((1,2,3),[(0.2,0.3,0.5),(0.3,0.5,0.2),(0.5,0.3,0.2)]);ld || stt;dmc((0,1,2,3,4),[(1/2,1/2,0,0,0),(2/5,1/5,2/5,0,0), (0,0,1,0,0),(0,0,1/2,1/2,0),(1/2,0,0,0,1/2)]);cc || stt;dmc((0,1,2,3,4),[(1/2,1/2,0,0,0),(2/5,1/5,2/5,0,0), (0,0,1,0,0),(0,0,1/2,1/2,0),(1/2,0,0,0,1/2)]);fm || stt;dmc((1,2,3),[(0.2,0.3,0.5),(0.3,0.5,0.2),(0.5,0.3,0.2)]);md;7;(1,0,0) ||.
Use "cmc" for continuous-time Markov chain. For example, stt;cmc((0,1),((-1,1),(1,-1)));P(x(1.96),0|x(0.78),1) ||.
Compute transition probabilities The expression "P(x(3),1|x(0),1)" represents the probability that the process starts 1 at time 0 and moves to 1 at time 3. Similarly, "P(x(5)>=1|x(2)>1)" means the probability that the process takes values greater than 1 at time 2 and takes values greater or equal to 1 at time 5. For example, stt;dmc((1,2,3),[(0.2,0.3,0.5),(0.3,0.5,0.2),(0.5,0.3,0.2)]);P(x(3),1|x(0),1) || stt;dmc((1,2,3),[(0.2,0.3,0.5),(0.3,0.5,0.2),(0.5,0.3,0.2)]);P(x(3),1|x(0)>=2) || stt;dmc((1,2,3),[(0.2,0.3,0.5),(0.3,0.5,0.2),(0.5,0.3,0.2)]);P(x(6)!=1|x(2)<=2) || stt;cmc((1,2,3),((-6,3,3),(4,-12,8),(15,3,-18)));P(x(3.12),3|x(1)>1) ||.