I'm working on a homework problem that asks me to use ode45
to find an approximate solution on the interval (-0.5,0.5) and plot it with plot
.
The given homogeneous first order linear order differential equation is Dy = (9*t^2-3*y)/t
or $\frac{dy}{dt} = \frac{9t^2 - 3y}{t}$ if you prefer the prettier version.
I'm not given a condition in the form of $y(0) = y1$, so what do I do? Doesn't ode45
need such a condition? I tried finding the general solution and setting t = 0 to get a y-value from it, but the solution is not defined at t = 0.
The only other information that's given is from a previous question that's part of the same problem. It states that an initial condition is $y(-0.5) = 3.15)$.
The problem actually admits a simple solution. That's probably not what you are supposed to do, but it can serve as a check.
After multiplying with $t$, the problem becomes $t\frac{dy}{dt} + 3y = 9t^2$ or $\frac{d}{dt} \left( t^3y \right) = 9t^4$. Therefore $$ t^3 y(t) = \frac{9}{5}t^5 + C $$ and the constant of integration must be zero. Thus $y(t) = \frac{9}{5}t^2$. In particular $y(\pm .5) = .45$. With any other initial condition at $t = -.5$, the solution cannot be continued past $t = 0$. If you try ode45 to solve it anyway, you will probably get an error message (stepsize becomes effectively zero).