MATLAB: Help with figuring out how to plot implicit functions with initial conditions

differential equationsezplotimplicit solutionsinitial conditions

Okay so the problem given goes like: "The solution of the differential equation y'=((2y-t)/(2t-y)) is given implicitly by abs(t-y)=c*abs(t+y)^3. (This is not what dsolve produces, which is more complicated explicit solution for y in terms of t, but it's what you get by making the substitution v=y/t, y=tv, y'=tv'+v and separating variables. You do not need to check this answer.) However, it is difficult to understand the solutions directly from this algebraic information" a.) Use meshgrid and quiver to plot the direction field of the differential equation
– this one I did and my code looks like
clear all
[T,Y]= meshgrid (-5:.5:5,-5:.5:5);
S=((2.*Y-T)./(2.*T-Y));
L=sqrt(1+S.^2);
quiver(T,Y, 1./L, S./L, .50), axis equal tight
xlabel 't', ylabel 'y'
title 'Direction Field for (2*Y-T)/(2*T-Y)'
but part b says: "use ezplot to plot the solutions with initial conditions y(2)=1 and y(0)=-3. (once you determine the sign of the quantity (t-y)/(t+y)^3, you can get rid of the absolute values) Use hold on to put these plots and the vector field plot on the same graph."
I know how to use hold on, but I can't for the life of me figure out how to plot the implicit solution with those initial conditions. I've tried using dsolve and it gives me an error. So please try to help me out here. By the way, anything in bold means you HAVE to do it like that.

Best Answer

Well, the initial conditions are presumably what you would use to determine 'c' in the implicit equation
abs(t-y)=c*abs(t+y)^3.
Just plug in y(2)=1 and solve for c. Once you have c, the implicit equation is fully determined and you can just use the ezplot syntax
fun2=@(t,y) abs(t-y)-c*abs(t+y)^3.
ezplot(fun2,[tmin,tmax,ymin,ymax])
See also "doc ezplot".
Related Question