# Approximate solution for ODE

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} // 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}];

• 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. – Michael E2 Apr 14 at 21:01
• 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 – user62716 Apr 14 at 21:05
• 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. – Michael E2 Apr 14 at 21:50
• Thank you Michael E2. – user62716 Apr 15 at 10:42

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;
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[], a]
uu1[t_] = u[t] /. First@sol1 /. First@sol2 // Normal // Simplify
pl = Plot[uu1[t], {t, 0, 6},
PlotStyle -> {Blue}]

• 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 – user62716 Apr 15 at 10:48
• 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. – Akku14 Apr 15 at 11:22
• So it can not done for any m, n, a? right? – user62716 Apr 15 at 13:14
ClearAll["Global*"]
ode = u'[t] - u[t]^2 - 1;
ic = u == 0;
sol = u[t] /. First@DSolve[{ode == 0, ic}, u[t], t] Series[sol, {t, 0, 10}] AsymptoticDSolveValue[{ode == 0, ic}, u[t], {t, 0, 10}]
` 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: • Thank you Naser, I highly appreciate your help. – user62716 Apr 15 at 10:39