-1
$\begingroup$

OK, so here I got the solution of a numerically-solved PDE. I wish to plot in a graph, for a given time, the point x where the solution reaches 1/2. So here's the relevant string of code:

eps=5/9;
phi6m = NDSolveValue[{
    D[u[t, x], t, t] - D[u[t, x], x, x] == 
           -6 u[t, x]^5 + (8 + 4 eps) u[t, x]^3 - (2 + 4 eps) u[t, x],
    u[0, x] == Tanh[x], 
    Derivative[1, 0][u][0, x] == 0, 
    u[t, -7] == -1, u[t, 7] == 1
                     }, u, {t, 0, 6}, {x, -7, 7}];
Do[
    phi62 = phi6m[k/10, x];
    phi6plus[[k]] = FindRoot[phi62 == 1/2, {x, k/10}],
 {k, 1, 55}]
ListLinePlot[phi6plus, PlotRange -> All]

But when I run that code, I get all the values of x where the solution is worth 1/2 for the sampled time points instead of a plot. It also says that ListLinePlot is called with no argument. How am I to make a graph with the values of phi6plus for the given values of k?

If possible, I'd also like to interpolate the data contained in the phi6plus array.

$\endgroup$
  • 2
    $\begingroup$ You've asked five questions and gotten answers to all but one of them. You've had several questions asked of you about some of your questions. You've accepted an answer to your first question, but for the most part you have not responded to the effort people have given you or the interest they have shown in helping, not even to say, "Thanks, but no, that's not what I'm after." This is a community and participants are expected to show respect for other members' time and effort. $\endgroup$ – Michael E2 Mar 16 '14 at 1:22
  • $\begingroup$ The question title is misleading - your problem is not with `ListLinePlot´ at all. $\endgroup$ – Yves Klett Mar 16 '14 at 8:13
1
$\begingroup$

Try this:

phi6plus = Table[phi62 = phi6m[k/10, x];
        x /. FindRoot[phi62 == 1/2, {x, k/10}], {k, 1, 55}]

FindRoot returns substitution rules of the form x->nn so you need to apply the rule to x to get the value.

Also your original code only works if the phi6plus array already exists.

To your second part:

g = Interpolation[phi6plus]
Plot[g[x], {x, 1, 55}]
$\endgroup$

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.