# Solve an ODE by NDSolve an Interpolating function

Posted 6 months ago
915 Views
|
8 Replies
|
2 Total Likes
|
 I want to solve an ODE when it appears an Interpolating Function. First I obtain the function y[s] (or Y[s]) aa = .4; sol = NDSolve[{-4 + 4/y[s]^2 - y[s]^2 + y[s]^4 + y'[s]^2 == 0, y[0] == 1.207}, y[s], {s, 0, aa}]; ParametricPlot [Evaluate[{s, y[s]} /. sol[[2]]], {s, 0, aa}, PlotRange -> All] Y[s_] = y[s] /. sol[[2]]; (with the function Y[s] I can plot the solution y[s])Now, I want to solve the ODE w'[s]= Sqrt[y[s]^2 + 2] with initial condition w[0] = 0. My first attempt is w1 = NDSolve[{w'[s] == Sqrt[Y[s]^2 + 2], w[0] == 0}, w[s], {s, 0, aa}] Next, I put W[s_] = w[s] /. w1[[1]] and I plot the function W[s] by means of Plot[W[s], {s, 0, aa}]Is it right? (thanks)enter code here
8 Replies
Sort By:
Posted 6 months ago
 That's hardly a question. Right in what way? Right as Mathematica syntax usage?
Posted 6 months ago
 I would just include the ODE for w in your first ODE: aa = .4; sol = NDSolve[{-4 + 4/y[s]^2 - y[s]^2 + y[s]^4 + y'[s]^2 == 0, y[0] == 1.207, w'[s] == Sqrt[y[s]^2 + 2], w[0] == 0}, {y[s], w[s]}, {s, 0, aa}]; Plot[Evaluate[{y[s], w[s]} /. sol[[1]]], {s, 0, aa}] 
Posted 6 months ago
 I think that the solution w[s] given by Mathematica is wrong. By the plot of w[s] (it seems a straight-line), I suppose that Mathematica solves the ODE for w[s] by taking ONLY the first value for y[s], namely, y[0]=1.207 and solves the ODE w'[s]=Sqrt[1.207^2+2], w[0]=0. I have computed this differential equation: p1 = NDSolve[{p'[s] == Sqrt[1.207^2 + 2], p[0] == 0}, p[s], {s, 0, aa}] and the functions p[s] and w[s] are 'very similar' (see the attached file). Attachments:
Posted 6 months ago
 I plotted it and DSolve can solve it and shows slightly different graph for the first solution but the same for the second - i didn't know if that was a question.I cannot comment if one needs to check for extraneous solution of differential equations, as I know little of what the underlying code does and does not do. I just assume one should check the answer is "correct" by hand, ask questions about particular abilities, to "know the tool" they work with.I know NDSolve uses one of many numerical approximation methods (if it needs to), which may have limitations. I'm unsure why you would start with NDSolve then ask backwardly if the solution is extraneous or partial when DSolve shows the solution.You didn't test all initial values, ie if y[x0]=y0, y'[x0]=y1 (noting I didn't check if your equation is linear nor if each part of the equation in the linear combination of solutions is linear).In all: I cannot do all that at the moment. but it's safe to say you should thoroughly check the initial equation and solution and check for every possible hole. This is just expected for solving by hand.It all depends if you are getting solutions that satisfy your need. If it is in the neighborhood and works, use it.
Posted 6 months ago
 (Restating that: my guess is NDSolve will leave out some solutions (perhaps a whole line or more - as the person above suggests, which I didn't verify). you should check that guess with other forum users who know more about which approximations show what existence theorems. I'm sure some methods do miss "some particular solutions" - but unsure which mm uses).
Posted 6 months ago
 I see carl wolf's graph doesn't change your answer (it shows both your graphs combined but doesn't answer if there is another solution line or points in another region to your 2nd diff eq). You said specifically you wished the solution of the second equation to operate using the interpolation function of the first, which the example removes. but it's a good idea to keep things together.