%% Glossary
% There are many input lines here that won't evaluate -- e.g., because they
% are really options to a command that does not precede them, or because
% parameters are missing, or they are programming commands or whatever.
% They conform to entries in the published Glossary so they are included 
% here. But in the MATLAB Operators, MATLAB Commands and Graphics Commands
% sections, they are preceded by a percent sign so that the mfile 
%(or cells in it) can be evaluated without causing errors. Virtually all of
% the entries in the MATLAB Programming section will not evaluate as given,
% so no percent signs are used there. 

%% MATLAB Operators

A = [1 0; 2 1]; B = [3; 5];
A\B
a = [1 2 3]; b = [4 -6 8];
a.*b
syms x y; solve(x + y - 2, x - y); ans.x
X = 0:0.1:30;
% [1; 2; 3]
1 + 3 + 5 + 7 + 9 + 11 ...
       + 13 + 15 + 17
['This is a way to create very long strings that ', ...
'span more than one line.  Note the square brackets.']
% took following command line out because it generates an error message
% !C:\Programs\program.bat
fminbnd(@cos, 0, 2*pi)
f = @(x) x.^2 - x

%% MATLAB Built-In Functions
conj(1 - 5*i)

%% MATLAB Commands
% Next two commented because they don't evaluate
% addpath C:\my_mfiles
% cd C:\mydocs\mfiles
syms x y
f = inline(char(sin(x)*sin(y)))
clear
clear f g
syms x y; collect(x^2 - 2*y*x^2 + 3*x + x*y, x)
syms x y; f = exp(x); g = sin(y); h = compose(f, g)
A = [1 3 i]
A'
dsolve('x*Dy + y = sin(x)', 'x')
% delete <filename> ; doesn;t evaluate
det([1 3; 4 5])
V = [2 3 4 5]; diag(V)
X = [2 3; 4 5]; diag(X)
% diary <filename>; doesn't evaluate
% diary off; doesn't evaluate
syms x; diff(x^3)
diff('x*y^2', 'y')
syms y(x); dsolve(x*diff(y) + y == sin(x))
x = 5.6; disp(x)
syms x; disp(x^2)
disp('This will print without quotes.')
doc print
z = sym('pi'); double(z)
double('think')
syms y(x); dsolve(diff(y) + y == 0)
dsolve(diff(y, 2) + y == 0)
dsolve('Dy + y^2 = 0', 'y(0) = 1', 'x')
[x, y] = dsolve('Dx = 2x + y', 'Dy = - x')
% edit mymfile
eig([2, 3; 4, 5])
[e, v] = eig([1, 0, 0; 1, 1, 1; 1, 2, 4])
v(end)
eval('cos(x)')
evalin(symengine, 'numlib::fibonacci(100)')
syms x y; expand((x - y)^2)
eye(5)
syms x y; factor(x^4 - y^4)
feval('exp', 1)
X = [2 0 5]; find(X)
fminbnd(@(x) x^4 - x^2 + 1, 0, 1)
format long
fzero(@(x) cos(x) - x, 1)
fzero(@cos, [-pi 0])
guide
help factor
f = inline('x^5 - x'); f(3)
int('1/(1 + x^2)', 'x')
format long; integral(@(x) sin(exp(x)), 0, 1)
syms x; int(exp(-x), x, 0, Inf)
inv([1 2; 3 5])
syms x y; f = x^2*y^3; jacobian(f)
sys1=x*(1-x-y); sys2=y*(1-x+2*y); jacobian([sys1, sys2], [x,y])
length('abcde') 
syms x; limit(sin(x)/x, x, 0)
syms x; limit(1/x, x, Inf, 'left')
linspace(0, 2*pi, 30)
% load filename
lookfor ode
X = [3 5 1 -6 23 -56 100]; max(X)
X = [3 5 1 -6 23 -56 100]; mean(X)
X = [3 5 1 -6 23 -56 100]; median(X)
X = [3 5 1 -6 23 -56 100]; min(X)
more on, help print
more off
mupad mynotebook.mn
notebook
notebook -setup
disp(['The value of pi is ', num2str(pi)])
[t, y] = ode45(@(t, y) t^2 + y, [0 10], 1);
plot(t, y)
ones(3)
ones(3, 1)
% open myfigure.fig
syms x y; expr = x/(x - 3)/(x + 2/y)
pretty(expr)
X = [3 5 1 -6 23 -56 100]; prod(X)
% publish('mymfile', 'latex')
A = [2 3 5; 4 6 8]; rank(A)
roots([1 2 2])
% save filename
syms x y; [expression, how] = simple(sin(x)*cos(y) + cos(x)*sin(y))
syms x; simplify(1/(1 + x)^2 - 1/(1 - x)^2)
A = [1 3 2; 4 1 5]
[r, c] = size(A)
solve('2*x^2 - 3*x + 6')
[x, y] = solve('x + 3*y = 4', '-x - 5*y = 3', 'x', 'y')
syms x y; [x, y] = solve(x+y==0, x^2+y^2==1)
sound(sin((0:0.1:1000)*pi))
constant = 'a7'
index = str2num(constant(2))
subs('x^3 - 4*x + 1', 'x', 2)
subs('sin(x)^2 + cos(x)', 'sin(x)', 'z')
syms x y z; z = x^2 - y^3; subs(z, x, 6)
k = 1:10; sum(k)
sym pi
x = sym('x')
constant = sym('1/2')
syms x y z
syms x real; solve(x^2 + x + 1 == 0)
syms x clear; solve(x^2 + x + 1 == 0)
syms x k n; symsum(x^k, k, 0, n)
syms n; symsum(n^(-2), n, 1, Inf)
syms x; taylor(cos(x), 8, 0)
taylor(exp(1/x), x, Inf, 'Order', 10)
A = [1 3 4]
A.'
% type myfile.m
syms x; expr=x^2-1/x; f = @(x) eval(vectorize(expr))
vpa('1/3', 20)
web('http://www.mathworks.com')
which ezplot
which ezplot -all
zeros(10)
zeros(3, 1)

%% Graphics Commands
X = (0:0.01:4)*pi; Y = sin(X); area(X, Y)
% axis([xmin xmax ymin ymax])
% axis tight 
% axis equal 
% axis square
% axis off
bar([2, 7, 1.5, 6])
ezmesh sin(x)*cos(y); colormap cool
t = (0:0.01:4)*pi; comet(t.*cos(t), t.*sin(t))
[X, Y] = meshgrid(-3:0.1:3, -3:0.1:3);
contour(X, Y, X.^2 - Y.^2)
[X,Y] = meshgrid(-2:0.1:2, -2:0.1:2);
contourf(X, Y, X.^2 - Y.^3);
colormap autumn
ezcontour('x^2 - y^2')
syms x y; ezcontour(x - y^2)
ezmesh('x^2 + y^2')
syms x y; ezmesh(x*y)
ezplot('exp(-x^2)', [-5, 5])
syms x; ezplot(sin(x))
ezplot3('cos(t)', 'sin(t)', 't')
syms t; ezplot3(1 - cos(t), t - sin(t), t, [0 4*pi])
ezsurf('(x^2 + y^2)*exp(-(x^2 + y^2))')
syms x y; ezsurf(sin(x*y), [-pi pi -pi pi])
fill([0 1 1 0], [0 0 1 1], 'b'); axis equal tight
findobj('Type', 'Line')
get(gcf)
%% getframe and movie
T = (0:0.01:2)*pi;
for j = 1:12
    plot(5*cos(j*pi/6) + cos(T), 5*sin(j*pi/6) + sin(T));
    axis equal; axis([-6 6 -6 6]);  
    M(j) = getframe;
end
movie(M)
[X, Y] = ginput
gtext('Region of instability')
hist(rand(200, 1))
hold on
hold off
image(ones(50,100))
imagesc(randn(50,100))
% A = imread('myimage.jpg');
% imwrite(A, 'picture.jpg')
t = (0:0.01:2)*pi;
plot(t, cos(t), t, sin(t))
legend('cos(t)', 'sin(t)')
x = 0.0001:0.1:12; loglog(x, x.^5)
[X,Y] = meshgrid(-2:.1:2, -2:.1:2);
mesh(X, Y, sin(pi*X).*cos(pi*Y))
[X, Y] = meshgrid(0:0.1:1, 0:0.1:2)
contour(X, Y, X.^2 + Y.^2)
t = (0:1:5)*2*pi/5; patch(cos(t), sin(t), 'r'); axis equal
Z = [34 5 32 6]; pie(Z)
X = [0:0.1:2];
plot(X, X.^3)
t = [0:0.1:30];
plot3(t, t.*cos(t), t.*sin(t))
theta = (0:0.01:2)*pi; rho = theta; polar(theta, rho)
% print -deps picture.eps
[x, y] = meshgrid(-4:0.5:4, -4:0.5:4);
quiver(x, y, x.*(y - 2), y.*x); axis tight
x = 0:0.1:12; semilogy(x, exp(x))
set(gcf, 'Color', [0, 0.8, 0.8])
%% subplot
subplot(2, 2, 1), ezplot('x^2')       
subplot(2, 2, 2), ezplot('x^3')
subplot(2, 2, 3), ezplot('x^4')
subplot(2, 2, 4), ezplot('x^5')
[X,Y] = meshgrid(-2:.1:2, -2:.1:2);
surf(X, Y, sin(pi*X).*cos(pi*Y))
syms x; ezplot(x^2); text(0, 0, 'low point')
title 'Nice Picture'
xlabel('Year')
ylabel('Population')
ezsurf('(x^2 + y^2)*exp(-(x^2 + y^2))'); view([0 0 1])
syms x y; ezmesh(x*y); view([1 0 0])
zoom
zoom(4)
%% Programming Commands
if any(imag(x) {\baretilde= 0); error('Inputs must be real.'); end
dbclear all
dbstop in <filename> at <linenumber>
n = find(isspace(mystring));
if ~isempty(n)
    firstword = mystring(1:n(1)-1);
    restofstring = mystring(n(1)+1:end);
end
close; axes; hold on
t = -1:0.05:1;
for k = 0:10
    plot(t, t.^k)
end
%function y = myfunction(x)
%if (x >= 0)
%    sqrt(x)
%else
%    error('Invalid input.')
%end
answer = input('Please enter [x, y] coordinates: ')
isa(x, 'sym')
isequal([1 2], [1 2 3])
isfinite([1 0 1]./[1 0 0])
isinf([1 0 1]./[1 0 0])
str = 'remove my spaces'; str(isletter(str))
isnan([-1 0 1]/0)
mlint mymfile
if (nargin < 2); error('Wrong number of arguments'); end 
if abs(err) < tol; return; end
%% swich and case
switch num
case 1
    disp('Yes.')
case 0
    disp('No.')
otherwise
    disp('Maybe.')
end
%% warning
warning('Taking the square root of negative number.')
%% while
mysum = 0;
x = 1;
while x > eps
    mysum = mysum + x;
    x = x/2;
end
mysum
%% Simulink Commands
find_system(gcs, 'Type', 'block')
sim('model', [0 20])
simlp([-1 -1], [1 4; 2 3; 4 1], [3; 2; 3])
