Electric field of a line of Charge on it axis using electric potential

We have a line of charge with length $$L$$ and charge density $$\lambda$$ and we want to find its Electric field on a point $$p$$ with distance $$d$$ from one end of it using potential. I drew a picture like this and for voltage evaluated this integral $$V =\int \frac{dq}{r} = \int_0^L (\frac{\lambda dx}{(d+x)} = \lambda ~~ln(l+d/d)$$

and for Electric field (by substituting $$x$$ instead of $$d$$) we get:

$$E = \partial V /\partial x = \lambda \frac{x-(l+x)}{x^2} \frac{x}{x+l}$$ which is negative. But it actually should get positive because the Electric field is in direction of $$+i$$. What is my mistake?

• $E=-dV/dx$, not $+dV/dx$. – ZeroTheHero Apr 21 at 21:40
• Is the line of charge positive or negative charge? The field from $d$ to $P$ will be positive for positive charge and negative for negative charge since, by convention, the direction of the field is the direction of the force that a positive charge would experience if placed in the field. – Bob D Apr 21 at 22:53