%Mfile for Chapter 4: Beyond the Basics
delete chap4.txt
diary chap4.txt
echo on
clear all

syms x 
y = x + 7

z = x + 7;
z
pause

x = 7;
disp(x)

disp(solve('x + tan(y) = 5', 'y'))
pause

a = 10; b = 5; factor(a^2 - b^2)
pause

more on 
help factor
help sym/factor
pause

eqn =['left hand side of equation = ', ...
'right hand side of equation']
pause

a = 1
b = a/sym(2)
c = sqrt(3)
sym(c)
sym('1 + sqrt(3)')
pause

f = 'x^3 - 1';
f(7)
%Typing f(-1) does yield the predicted error message 

h = inline('t.^3','t');
int('h(t)','t')
syms t
int(h(t),'t')
pause

syms a x y
a = x^2 + y^2;
subs(a, x, 2)
subs(a, [x, y], [3, 4])
pause

%Typing scriptex2 produces an error message
scriptex1
scriptex2

x = 4; z = 'junk';
sq(3)
polarcoordinates(3, 4)
[r, theta] = polarcoordinates(3, 4)
r = polarcoordinates(3, 4)
theta = polarcoordinates(3, 4)
pause

solve('x^2 + 2*x + 2 = 0')
log(-1)
(2 + 3*i)*(4 - i)
pause

A = [3 -2 0; 2 -2 0; 0 1 1];
eig(A)
[U, R] = eig(A)
[U, R] = eig(sym(A))
pause

syms x; diff(x^3)
f=inline('x^3', 'x'); diff(f(x))
diff(f(x), 2)
syms y z
diff(x^2*y, y)
diff(diff(sin(x*y/z), x), y)
dsolve('x*Dy + 1 = y', 'x')
pause

int('x^2', 'x')
syms x; int(asin(x), 0, 1)
int(exp(-x^4), 0, 1)
quadl(vectorize(exp(-x^4)), 0, 1)
syms y; int(int(x^2 + y^2, y, 0, sin(x)), 0, pi)
pause

syms x; limit(sin(x)/x, x, 0)
limit(abs(x)/x, x, 0, 'left')
limit((x^4 + x^2 - 3)/(3*x^4 - log(x)), x, Inf)
pause

X = 1:7;
sum(X)
prod(X)
syms k n; symsum(1/k - 1/(1 + k), 1, n)
symsum(1/n^2, 1, Inf)
syms a k; symsum(a^k, 0, Inf)
pause

syms x; taylor(sin(x), x, 10)
taylor(exp(x), 4, 2)
taylor(exp(1/x^2), 6, Inf)
pause

syms t; diff(sin(t^2))
solve('x + y = 3')
syms w z; diff(w*z)
echo off
diary off
