%% Chapter m-File for MuPAD Chapter 8
clear all
close all

%% Additional Options to Matlab Commands

syms x y; 
[x y] = solve(x^2 + y == 0, x + y == 0)

help VectorFormat

%% ODE and Matlab vs MuPAD
% vector field for y' + ty = 1
[T, Y] = meshgrid(-4:0.2:4, -4:0.2:4);
S = 1 - T.*Y;
L = sqrt(1 + S.^2);
quiver(T, Y, 1./L, S./L, 0.5), axis equal tight
xlabel 't', ylabel 'y'
title 'Direction Field for dy/dt = 1 - ty'

%% Attempted symbolic solution and symbolic plot
syms c t y(t)
sol = dsolve(diff(y,t) == 1 - t*y, y(0) == c);
hold on
for cval = -2:0.5:2
    ezplot(subs(sol, c, cval), [-3 3])
end

%% The nature of the symbolic Solution
dsolve(diff(y,t) == 1 - t*y, y(0) == c)

%% Numerical solution that works from Jon

syms c t y(t) yy(t, c) real
tt = sym(-3:0.01:3);
yy(t, c) = dsolve(diff(y,t) == 1 - t*y, y(0) == c);
figure; hold on
for d = -4:4
    plot(tt, eval(strrep(vectorize(yy(t,d/2)), 't', 'tt')))
end
