1
$\begingroup$
n = 1;
num = (1 - 0.01)/0.01
phi = 0;
For[i = 0, i < num, i++ ,  
    phi = phi + 0.01;
 a = NDSolve[{y''[x] - phi*y[x]^n == 0, y'[0] == 0, y[1] == 1}, 
   y, {x, 0, 1}];
   diff = Evaluate[y'[1] /. a];
 eta = Evaluate[(diff/phi^2)*((n + 1)/2)];
 etastore[i] = eta;

 phistore[i] = phi;
 ]

How do I plot etastore versus phistore?

$\endgroup$
  • $\begingroup$ First, you would have to actually define etastore and phistore. In your code, they are not assigned anything. For instance, you would need to use etastore[[i]] instead of etastore[i]. $\endgroup$ – bill s May 3 '16 at 13:30
  • $\begingroup$ @bills Though probably not good practice in this case, etastore[i] can be used... $\endgroup$ – xzczd May 3 '16 at 13:41
1
$\begingroup$

If you insist on coding based on the existing code:

Table[{phistore[i], etastore[i][[1]]}, {i, num}] // ListLinePlot

But why not:

Clear@phi
asol[phi_][x_] = 
 y[x] /. First@DSolve[{y''[x] - phi*y[x]^n == 0, y'[0] == 0, y[1] == 1}, y, x]

Plot[asol[phi]'[1]/phi^2 (n + 1)/2, {phi, 0, 1}]

If you need a numeric solution:

sol = ParametricNDSolveValue[{y''[x] - phi*y[x]^n == 0, y'[0] == 0, y[1] == 1}, 
  y, {x, 0, 1}, phi]

Plot[sol[phi]'[1]/phi^2 (n + 1)/2, {phi, 0, 1}]

enter image description here

$\endgroup$
  • $\begingroup$ Thanks... ur code was more concise! and better :) thanks! $\endgroup$ – Prasad May 3 '16 at 14: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.