Solve the following differential equation, i.e. solve for y:

dy/dx - y/x = 1/x + y + 1

I have this so far,

1. dy/dx= (y + 1 + xy + x)/x
2. x dy = (y + 1 + xy + x)dx
3. Integrate both sides...
xy + c = xy + x + .5x^2y + .5x^2 + k
where c and k are constants
4. c = x + .5x^2 (y + 1) + k
5. .5x^2 (y + 1) = c - k -x
6. y = 2(C- x)x^-2 - 1
where C = c - k

but I have been told this is wrong. so can soneone please direct me in the error of my method and show me the correct working out.

What is wrong is this: In step 3, you cannot treat x as a constant in the dy integration (on the left), nor can your treat y as a constant in the dy integration (on the right). You need to totally separate y and x variables on opposite sides somehow, or find some other trick.

This is a first order linear differential equation that can be written as
dy/dx - Py = Q
where P and Q are functions of x.
Equations of this type can be solved by the "integrating factor" method. I suggest you familiarize yourself with the method. It goes like this:
Compute the function
rho(x) = exp(integral of P dx)
The solution will be
rho*y = [Integral of rho*Q(x)dx] + C

I should have written the standard form as dy/dx + P(x)y = Q(x)

I got the sign wrong on the P.
In your case, Q = -P = (1/x) + 1
The form of the solution which I wrote should be correct.

For the first step, I get

rho(x) = 1/(x*e^x)

The final step would be to solve
y(x) = (x*e^x)*(Integral)[(1/x^2)*e^-x + (1/x)*e^-x] dx + C

Yes, I worked it through mostly the same way and got

y = c x e^x - 1

By the way, having gotten interested, I also solved this by brute force trial and error.

I assumed an exponential type solution:
y = Ae^x + Bxe^x+ C
then
dy/dx = Ae^x + Bxe^x + Be^x
plug that in
Ae^x + Bxe^x + Be^x - Ae^x/x - Be^x - C/x = 1/x + 1 + Ae^x + Bxe^x+ C
combine like terms
-Ae^x/x - C/x = 1/x + 1+ C
then
-Ae^x -C = 1 + x + Cx
well now, A = 0 because we have no other term in e^x
C(x+1)= -(x+1)
so
C = -1
B can be any constant
so
y = B e^x - 1
same answer

Whoops, correct last line

y = B xe^x - 1

To solve the differential equation, let's carefully go through each step and find the error in your method.

Starting from the given differential equation:

dy/dx - y/x = 1/x + y + 1

Step 1 is correct. We rearrange the terms to separate the variables:

dy/dx = (y + 1 + xy + x)/x

Now, let's find the error in step 2. You have multiplied both sides by "x" and obtained:

x dy = (y + 1 + xy + x)dx

This step is incorrect. Instead of multiplying both sides by "x," we need to multiply both sides by dx to keep the separation of variables intact.

Correcting the error in step 2, we have:

dy = ((y + 1)dx + xy dx)/x

Now, let's simplify the equation using common denominators:

dy = (ydx + dx + xydx)/x

Next, factor out the dx term:

dy = (y + 1 + xy)dx/x

Now, multiply both sides by x:

x dy = (y + 1 + xy) dx

So, the corrected equation after step 2 is:

x dy = (y + 1 + xy) dx

Now, let's move on to step 3, where we integrate both sides with respect to x:

∫x dy = ∫(y + 1 + xy) dx

The integral on the left side is simply y:

xy + C1 = ∫(y + 1 + xy) dx

Integrating the right side:

xy + C1 = ∫y dx + ∫1 dx + ∫xy dx

The integral of y dx gives yx, the integral of 1 dx gives x, and the integral of xy dx gives (1/2)x^2y:

xy + C1 = yx + x + (1/2)x^2y + C2

Combining the constants into a single constant, let's rewrite the equation as:

xy - yx + (1/2)x^2y = x + C

Now, let's rearrange terms to isolate y:

xy - yx + (1/2)x^2y - (1/2)x^2y = x + C

yx = x + C

y = (x + C) / x

So, the correct solution to the differential equation is:

y = (x + C) / x

where C is the constant of integration.