Skip to content

Instantly share code, notes, and snippets.

@csvance
Created January 27, 2019 23:04
Show Gist options
  • Save csvance/44f2df0c00bac9465262bad82a020912 to your computer and use it in GitHub Desktop.
Save csvance/44f2df0c00bac9465262bad82a020912 to your computer and use it in GitHub Desktop.
syms t;
syms C;
syms y;
syms r;
syms y;
syms x;
syms Y;
syms X;
hw_problem = '2.1 #24';
crange = 0:0;
ode = @(y, t) (y+t)/(y-t);
no_general = 1;
general_solution = 1/3 * t^2 + C/t;
xlab = 't';
ylab = 'y(t)';
trange = -5:0.2:5;
yrange = -5:0.2:5;
[tm, ym] = meshgrid(trange, yrange);
dt = trange(2) - trange(1);
odev = vectorize(ode);
if isa(ode,'function_handle')
odev = eval(odev);
end
slope = feval(odev,ym,tm);
hold on
slopet(1:length(yrange), 1:length(trange)) = dt;
slopey = slope * dt;
L = sqrt(slopet.^2 + slopey.^2);
quiver(trange, yrange, slopet./L, slopey./L, 0.5);
leg = {'Direction'};
if no_general == 0
i = 2;
for c = crange
fsol = matlabFunction(subs(general_solution, C, c));
fplot(fsol);
leg{i} = strcat('C=', num2str(c));
i = i + 1;
end
end
legend(leg, 'FontSize', 12)
xlabel(xlab, 'FontSize', 14)
ylabel(ylab, 'FontSize', 14)
if no_general == 0
description = strcat(hw_problem, ' ODE: ', char(ode), ' General: ', char(general_solution));
else
description = strcat(hw_problem, ' ODE: ', char(ode));
end
title(description, 'FontSize', 18)
grid
axis([trange(1) trange(length(trange)) yrange(1) yrange(length(yrange))])
hold off
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment