Question Sheet 8 - Challenge Problem Example Answers

1.a) Solve the following 1st order ODE using Mathematica: x*(dy/dx)=(x^2)+3y.

DSolve[x*y'[x]==(x^2)+3y[x],y[x],x]

b) What command can be used to clear the value of y if ‘=’ is used instead of ‘==’?

DSolve[x*y'[x]=(x^2)+3y[x],y[x],x]

Remove[y[x]]

c) Now solve it using the boundary condition y(1)=0.

DSolve[{x*y'[x]==(x^2)+3y[x],y[1]==0},y[x],x]

d) Now solve it using y(0)=0.

DSolve[{x*y'[x]==(x^2)+3y[x],y[0]==0},y[x],x]

e) You should get the following error message:

Why has this error message appeared? Why is the output the same as in part d?

The initial condition we have given is, ‘when x=0, then y(0)=0. If we look at our answer in part a, the general solution is y(x)= -(x^2) + (Cx^3) . Thus, we are not actually giving Mathematica any more information about the constant C, by specifying that y(x) is zero when x is zero. It is important when coding to try and determine if the error you are receiving is due to a mathematical error or a coding error.