# Question:Define variable as the solution to a differential equation

## Question:Define variable as the solution to a differential equation

Maple 2019

Hey I’m trying to define a variable as the solution to a second order nonhomogeneous differential equation with an initial value problem.

I have tried the method below, but it doesn’t work.

N__1 := dsolve([diff(y(x), x, x) + 3*diff(y(x), x) + 2*y(x) = x^2 + 5, eval(y(x), x = 0) = 1, eval(diff(y(x), x), x = 0) = 1], y(x))

It kind of works it gives me the expression below

N__1 = y(x) = (3*exp(-2*x))/4 + 17/4 - (3*x)/2 + x^2/2 - 4*exp(-x)

But I need the expression for N__1 to define some initial values for N__2 and so on, what I have tried that doesn’t work is.

C := eval(N__1, x = 200)

N__2 := C   - Just because nothing much is happing on this interval

And it gives me the following expression for N2

N__2 := y(200) = (3*exp(-400))/4 + 78817/4 - 4*exp(-200)

I then make a piecewise function to make a function which I can plot, which use to work.

N := piecewise(0 <= x and x <= 200, N__1, 200 <= x and x <= 1000, eval(N__2, x = x - 200))

But when I’m trying to plot N maple gives me a warning message.

plot(N, x = 0 .. 1000)

Warning, expecting only range or variable x in expression piecewise ………………..  to be plotted but found name y.

If I define N__1 as the solution to the differential equation, then it works just fine.

N__1 := (3*exp(-2*x))/4 + 17/4 - (3*x)/2 + x^2/2 - 4*exp(-x)

But that I’m not interested in, because that will require a lot of copy paste all the time.