%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% i41CX+ CAS Examples
%
% This file contains a number of
% examples in the areas of algebra,
% linear algebra, calculus, 2D and
% 3D plots to demonstrate the CAS
% capabilities and for use as
% templates for your own CAS
% computations. It should be noted
% that the CAS is much more powerful
% than the simple examples contained
% in this file. In fact, the full
% documentation for REDUCE which is
% the core of the i41CX+ CAS
% comprises over 600 pages and can
% handle extremely complex
% computations such as those
% performed in higher level
% Mathematics and Quantum Physics.
% The examples contained here barely
% exercise the capabilities of this
% incredibly powerful CAS.
%
% The Usage & Examples table one the
% back view of i41CX+ also contains
% several examples, including CAS
% programming examples.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% FOR MORE INFORMATION
%
% Please see the i41CX+ FAQ's CAS
% section or the Mini-Manual that
% are available under the i41CX+
% product web page at:
%
% http://alsoftiphone.com/i41CXplus.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ALGEBRA (SOLVE)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Use blue for input
color("Blue");
% enable input echo
on echo;
% solve quadratic equation
solve(x^2+8x+15, x);
% solve simultaneous equations
solve({x+3y=7, y-x=1},{x,y});
% solve a system with parameters
solve({x=a*z+1, y=b*z},{z,x});
% turn off input echo
off echo;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% LINEAR ALGEBRA
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% load linear algebra package
load_package linalg$
% define complex 3x3 matrix
m1 := mat((1+i*3, 2-i*5, 7-i), (4-i*2, 6+i*9,-8+i*4), (-3-i*7, 3+i*2, -1+i*6));
% determinant of matrix
write "|m1| = ", det(m1);
% trace of matrix
write "trace(m1) = ", trace(m1);
% characteristic polynomial
write "characteristic polynomial of m1:";
char_poly(m1,eta);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CALCULUS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% enable input echo
on echo;
% Differentiation
% df/dx
df(x^x,x);
% df/((dx)(dy^2)(dz))
df(x*exp(i*y)*log(z), x, 1, y, 2, z, 1);
% Integration
% indefinite integral with respect to x
int(x^2 + x*sin(x), x);
% integral in interval {-oo, oo}
int(exp(-x^2), x,-infinity,infinity);
% integral with logarithms
int(log(log(x)),x);
% turn off input echo
off echo;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ARBITRARY PRECISION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Use real arithmetic
on rounded$ % <- TIP
% TIP: Terminating a line with $
% suppresses output and reduces
% output size.
% Set precision to 50 digits
precision(50)$
% Print Pi
pi;
% turn off input echo
off echo$
% Set precision back to default (12)
precision(12)$
% Go back to precise arithmetic
off rounded$
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PLOTTING
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plots of sine and cosine combined
% in one plot
plot(sin(x), title="sin(x) and cos(x)", output="Sine and Cosine");
plot(cos(x), title="sin(x) and cos(x)");
% Superposition of polynomials
plot((x^2+y^2-9)*x*y=0, title="Polynomials", output="Polynomials");
% 3D surface plot
plot(cos sqrt(x**2+y**2),x=(-10 .. 10),y=(-10 .. 10),hidden3d, title="cos sqrt(x^2+y^2)", points=30, output="3D Plot");
% Super-Ellipsoid
on rounded;
ax:=3$
ay:=3$
az:=4$
ns:=4/5$
ew:=1$
for all w,m let c(w,m) = sign(cos(w))*abs(cos(w))**m$
for all w,m let s(w,m) = sign(sin(w))*abs(sin(w))**m$
for all u,v let x(u,v) =ax * c(v, ns)*c(u, ew)$
for all u,v let y(u,v) =ay * c(v, ns)*s(u, ew)$
for all u,v let z(u,v) =az * s(v, ns)$
dd:=pi/15$
w:=for u:=-pi step dd until pi collect
for v:=-pi/2 step dd until pi/2 collect
{x(u,v),y(u,v),z(u,v)}$
gnuplot(set, ticslevel, 0)$
gnuplot(set, xtics, -4, 1, 4)$
gnuplot(set, ytics, -4, 1, 4)$
gnuplot(set, ztics, -4, 1, 4)$
plot (w, hidden3d, title="Super Egg", output="Super-Ellipsoid")$