# Plotting 2 arrays against each other on mathematica

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?

• 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]. – bill s May 3 '16 at 13:30
• @bills Though probably not good practice in this case, etastore[i] can be used... – xzczd May 3 '16 at 13:41

## 1 Answer

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


• Thanks... ur code was more concise! and better :) thanks! – Prasad May 3 '16 at 14:22