2
$\begingroup$

I am trying to find approximate solution for nonlinear ODE(I know there are are ways to do it in mathematica) but I really want why is not working(I modified the code base on some codes suggest by expert here for system):

 ClearAll["Global`*"]
  eq = {u'[t] == u[t]^2 + 1, u[0] == 0} // Simplify


   u[t_] = Sum[ t^s, {s, 0, 6}] + O[t]^7;

   le = LogicalExpand[#] & /@ eq;

   sol1 = NSolve[And @@ le, Flatten[Table[s, {s, 0, 6}], 1]];

    uu1[t_] = Normal[{u[t]} /. First@sol1] // Simplify;

    uu1[t] // TableForm
     pl = Plot[Evaluate[{uu1[t]}, {t, 0, 6}], 
         PlotStyle -> {Blue}];
$\endgroup$
  • 1
    $\begingroup$ NDSolve is used to solve ODEs, not NSolve. You might want to study some examples in its documentation, because I'm not sure how to fix your code. $\endgroup$ – Michael E2 Apr 14 at 21:01
  • $\begingroup$ Dear MichaelE2, the above code I modified it, it was suggested by Akku14 for system, I am new here I do not know how to contact the expert directly....thanks $\endgroup$ – user62716 Apr 14 at 21:05
  • 1
    $\begingroup$ Maybe if you gave the mathematical formulation of the problem -- but maybe Nasser has guessed correctly what you wanted in his answer, in which case I guess there's no further need for explanation. $\endgroup$ – Michael E2 Apr 14 at 21:50
  • $\begingroup$ Thank you Michael E2. $\endgroup$ – user62716 Apr 15 at 10:42
2
$\begingroup$

If you want to use the method i showed in other example, do it exactly the way. (Don't leave things or change arbitrarilly.)

    ClearAll["Global`*"]
eq = u'[t] == u[t]^2 + 1; ic = u[0] == 0;
u[t_] = Sum[a[s]*t^s, {s, 0, 6}] + O[t]^7
le = LogicalExpand[eq]
sol1 = Solve[le, Table[a[s], {s, 1, 6}]]
sol2 = Solve[ic /. sol1[[1]], a[0]]
uu1[t_] = u[t] /. First@sol1 /. First@sol2 // Normal // Simplify
pl = Plot[uu1[t], {t, 0, 6}, 
    PlotStyle -> {Blue}]
| improve this answer | |
$\endgroup$
  • $\begingroup$ Dear Akku14, many thanks for the correct answer, can we do the same for x y''(x)+2y'(x)+a x^(m+1) y(x)^n=0, y(0)=1, y'(0)=0 $\endgroup$ – user62716 Apr 15 at 10:48
  • $\begingroup$ You can only do it, if you insert integer numbers for m and n. e.g. m -> 1, n -> 2. Try it. Solve only for y(0)=1 The y'(0)=0 is satisfied with the given a. $\endgroup$ – Akku14 Apr 15 at 11:22
  • $\begingroup$ So it can not done for any m, n, a? right? $\endgroup$ – user62716 Apr 15 at 13:14
2
$\begingroup$
ClearAll["Global`*"]
ode = u'[t] - u[t]^2 - 1;
ic = u[0] == 0;
sol = u[t] /. First@DSolve[{ode == 0, ic}, u[t], t]

Mathematica graphics

Series[sol, {t, 0, 10}]

Mathematica graphics

 AsymptoticDSolveValue[{ode == 0, ic}, u[t], {t, 0, 10}]

Mathematica graphics

If you want to do the above yourself, then you would need to plug in Taylor series for $u(t)$ using rules given below on Wikpedia and this gives you a recursive relation to solve for the coefficients. the $c_0$ is found from initial conditions, which then leads to all the other coefficients being known due to recusive relation.

See https://en.wikipedia.org/wiki/Power_series_solution_of_differential_equations under the section A simpler way using Taylor series and follow the example given:


Mathematica graphics

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thank you Naser, I highly appreciate your help. $\endgroup$ – user62716 Apr 15 at 10:39

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.