clear all % clears workspace (also resets the MuPAD engine)
% Can declare variable as symbolic:
syms x
% Build a symbolic expression for F of question 5.3:
F = 2*x^2 - x^4
% Look at its symbolic derivative:
f = diff(F)  
% for (debatably) better looks try
pretty(f)
% is this a valid pdf - is its integral 1 (over wherever it's defined)?
int(f, 0, 1)



% miscellania
s =simple(sym('13/7 + 17/23'))
subs(sin(x), x, sym(pi)/6)
% ezplot lets you plot a graph of a function from its defining symbolic
% expression. The 
figure(1)
ezplot(f,[0 1])
figure(2)
ezplot(F,[0 1])
% Often, cdfs/pdfs will be peicewise functions and we can use matlab's
% heaviside function to plot these:
figure(3)
f1 = -heaviside(x+2)*heaviside(-x)+heaviside(x)*heaviside(2-x)
% this is not a pdf of any f-n, but you could multiply this by some other
% suitalble f-n to obtain a pdf and plot it.
ezplot(f1,[-2 2])
title('graph of a piecewise linear dude')
subs(f1, x, -2)
subs(f,x,0)
I = int(f1, -2, 2)
figure(4)
syms x y
f = sin((x^2 + y)/2)/(x^2 - x +2)
ezsurfc(f)