5
$\begingroup$

I am newbie at Mathematica but I need to solve differential equation so I took my chances and tried to use this powerful tool to solve this equation: $$\frac{d}{dx}\left([\cos(2\pi x)+1]\frac{du(x)}{dx}\right) = 0$$ $$x \in[0,1]$$ $$\frac{du(0)}{dx}+u(0)=1$$ $$u(1)=0$$

So I read that I should use NDSolve to solve differential equations.

I wrote:

eqn = {(D[((Cos[2*Pi*x] + 1)*D[y[x], x]), x] == 0), 
  D[y[0], x] + y[0] == 1, y[1] == 0}
sol = NDSolve[eqn, y, {x, 0, 1}]

But I am getting: NDSolve::mxst: Maximum number of 10000 steps reached at the point x == 0.49999990622587265. >> NDSolve::berr: "There are significant errors {0.,0.017511} in the boundary value residuals. Returning the best solution found" NDSolve::mxst: Maximum number of 10000 steps reached at the point x == 0.4999999052334023.

How to avoid this errors and my program run and succeed?

$\endgroup$
  • $\begingroup$ You can use MaxSteps ->100 instead of 100 you can use other numbers. $\endgroup$ – MOON Dec 27 '14 at 22:39
  • 1
    $\begingroup$ Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. $\endgroup$ – bbgodfrey Dec 27 '14 at 22:43
  • $\begingroup$ @yashar I am still getting NDSolve::mxst: Maximum number of 100 steps reached at the point x == 0.46504538392462047. >> $\endgroup$ – Marcin Majewski Dec 27 '14 at 22:46
  • $\begingroup$ NDSolve is encountering a singularity where Cos[2*Pi*x] + 1 is equal to zero. $\endgroup$ – bbgodfrey Dec 27 '14 at 22:49
  • $\begingroup$ @bbgodfrey Hmm, I see. How to avoid that, and make this run ? $\endgroup$ – Marcin Majewski Dec 27 '14 at 22:52
5
$\begingroup$

Use DSolve instead of NDSolve.

eqn = {D[(Cos[2*Pi*x] + 1)*D[y[x], x], x] == 0, y'[0] + y[0] == 1, y[1] == 0};
sol = DSolve[eqn, y[x], {x, 0, 1}][[1]]

The solution is Tan[Pi*x]/Pi.

Note: The original equation in the question contained D[y[0], x], which evaluates to zero, because y[0] is a constant. I presume that y'[0] is meant and made that replacement.

$\endgroup$
  • $\begingroup$ Now I am getting : DSolve::dsvar: 0 cannot be used as a variable. $\endgroup$ – Marcin Majewski Dec 27 '14 at 23:10
  • $\begingroup$ Are you using exactly what I have in the answer? Please also see the note that I just added to the bottom of my answer. $\endgroup$ – bbgodfrey Dec 27 '14 at 23:17
  • $\begingroup$ Yes I copied and used exactly the same code (link) $\endgroup$ – Marcin Majewski Dec 27 '14 at 23:23
  • $\begingroup$ Strange I used the same code in Mathematica 10 (instead of Mathematica 8) and it worked ! Thank you $\endgroup$ – Marcin Majewski Dec 27 '14 at 23:27
  • 2
    $\begingroup$ If you look at the code in this answer you see it is using DSolve and it is giving the independent variable as {x,0,1}. That would be fine if it were NDSolve, where you must give upper and lower bounds on the independent variable, or if it is for version 10 which introduces this new ability to solve exactly within a domain, but for DSolve in versions prior to 10 changing {x,0,1} to just x makes the error go away. I wonder if that change is mentioned in the new features list in V10. $\endgroup$ – Bill Dec 28 '14 at 4:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.