Plotting Quantum Harmonic Oscillator in Mathematica - math

How can I make the plot for quantum harmonic oscillator using Mathematica?
I would like to draw similar looking plot like the attached figure.

Energy[n_] := (2 n + 1) ℏ/2 ω;
ψ[z_, n_] :=
1/2 1/Sqrt[2^n n!] ((m ω)/(π ℏ))^(1/4)
Exp[-((m ω z^2)/(2 ℏ))] HermiteH[n, Sqrt[(m ω)/ℏ] z];
m = 1;
ω = 1;
ℏ = UnitConvert[Quantity[1, "PlanckConstant"], "SIBase"];
ℏ = QuantityMagnitude[ℏ];
ℏ = 1;
Plot[{Evaluate#Table[Energy[n] + ψ[z, n], {n, 0, 5}],
Evaluate#Table[Energy[n], {n, 0, 5}], z^2/2}, {z, -5, 5},
PlotRange -> {0, 7},
PlotStyle ->
Join[{Red, Yellow, Green, Blue, Purple, Cyan},
Table[{Gray, Opacity[0.3]}, {n, 0, 5}], {Black}],
Filling -> {1 -> Energy[0], 2 -> Energy[1]}]

Related

Scaled figure multiplied by perspective matrices gives an incorrect figure

I have a grid. Which should be in 3d space. The grid must be dimensionless. That is, when the camera is rotated 90 degrees in x, the edge of the grid should not be visible. To solve the problem, before multiplying by the look at and perspective matrix, I increase it in scale, that is:
scale grid
matrix representation:
typedef std::array<std::array<double, 4>, 4> M4x4;
I implemented the code for working with matrices:
M4x4 Matrix::multiply(const M4x4 &a, const M4x4 &b)
{
M4x4 m;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
m[i][j] = a[i][0] * b[0][j] +
a[i][1] * b[1][j] +
a[i][2] * b[2][j] +
a[i][3] * b[3][j];
}
}
return m;
}
M4x4 Matrix::getTranslation(double dx, double dy, double dz)
{
return {
std::array<double, 4>{1, 0, 0, dx},
std::array<double, 4>{0, 1, 0, dy},
std::array<double, 4>{0, 0, 1, dz},
std::array<double, 4>{0, 0, 0, 1}
};
}
M4x4 Matrix::getLookAt(const Vector &eye, const Vector &target, const Vector &up)
{
Vector vz = Vector::substruct(eye, target).normalize();
Vector vx = Vector::crossProduct(up, vz).normalize();
Vector vy = Vector::crossProduct(vz, vx).normalize();
CoorVector eyeCoor = eye.getCoorVector();
CoorVector vzCoor = vz.getCoorVector();
CoorVector vxCoor = vx.getCoorVector();
CoorVector vyCoor = vy.getCoorVector();
M4x4 m = {
std::array<double, 4>{vxCoor.x, vxCoor.y, vxCoor.z, 0},
std::array<double, 4>{vyCoor.x, vyCoor.y, vyCoor.z, 0},
std::array<double, 4>{vzCoor.x, vzCoor.y, vzCoor.z, 0},
std::array<double, 4>{0, 0, 0, 1}
};
return Matrix::multiply(
Matrix::getTranslation(-eyeCoor.x, -eyeCoor.y, -eyeCoor.z),
m
);
}
M4x4 Matrix::getGeneralScale(double val)
{
return {
std::array<double, 4>{1, 0, 0, 0},
std::array<double, 4>{0, 1, 0, 0},
std::array<double, 4>{0, 0, 1, 0},
std::array<double, 4>{0, 0, 0, 1 / val}
};
}
M4x4 Matrix::getScale(double sx, double sy, double sz)
{
return {
std::array<double, 4>{sx, 0, 0, 0},
std::array<double, 4>{0, sy, 0, 0},
std::array<double, 4>{0, 0, sz, 0},
std::array<double, 4>{0, 0, 0, 1}
};
}
M4x4 Matrix::getRotationZ(double angle)
{
return {
std::array<double, 4>{std::cos(angle), -std::sin(angle), 0, 0},
std::array<double, 4>{std::sin(angle), std::cos(angle), 0, 0},
std::array<double, 4>{0, 0, 1, 0},
std::array<double, 4>{0, 0, 0, 1}
};
}
Vector Matrix::multiplyVector(const M4x4 &m, const Vector &v)
{
CoorVector coorV = v.getCoorVector();
return Vector({
m[0][0] * coorV.x + m[0][1] * coorV.y + m[0][2] * coorV.z + m[0][3] * coorV.w,
m[1][0] * coorV.x + m[1][1] * coorV.y + m[1][2] * coorV.z + m[1][3] * coorV.w,
m[2][0] * coorV.x + m[2][1] * coorV.y + m[2][2] * coorV.z + m[2][3] * coorV.w,
m[3][0] * coorV.x + m[3][1] * coorV.y + m[3][2] * coorV.z + m[3][3] * coorV.w
});
}
M4x4 Matrix::getPerspectiveProjection(double fovy, double aspect, double n, double f)
{
const double PI = 3.141592653589793238463;
const double radians = PI / 180 * fovy;
const double sx = (1 / std::tan(radians / 2)) / aspect;
const double sy = (1 / std::tan(radians / 2));
const double sz = (f + n) / (f - n);
const double dz = (-2 * f * n) / (f - n);
return {
std::array<double, 4>{sx, 0, 0, 0},
std::array<double, 4>{0, sy, 0, 0},
std::array<double, 4>{0, 0, sz, dz},
std::array<double, 4>{0, 0, -1, 0}
};
}
M4x4 Matrix::getFrustum(double left, double right, double bottom, double top, double near, double far)
{
return {
std::array<double, 4>{2 * near / (right - left), 0, (right + left) / (right - left), 0},
std::array<double, 4>{0, 2 * near / (top - bottom), (top + bottom) / (top - bottom), 0},
std::array<double, 4>{0, 0, -(far + near) / (far - near), -2*far*near/(far- near)},
std::array<double, 4>{0, 0, -1, 0}
};
}
vector representation:
struct CoorVector {
double x = 0;
double y = 0;
double z = 0;
double w = 1;
};
Working with vectors:
Vector Vector::substruct(const Vector &v1, const Vector &v2)
{
CoorVector coorV1 = v1.getCoorVector();
CoorVector coorV2 = v2.getCoorVector();
return Vector({coorV1.x - coorV2.x, coorV1.y - coorV2.y, coorV1.z - coorV2.z, 1});
}
Vector Vector::crossProduct(const Vector &v1, const Vector &v2)
{
CoorVector coorV1 = v1.getCoorVector();
CoorVector coorV2 = v2.getCoorVector();
return Vector({coorV1.y * coorV2.z - coorV1.z * coorV2.y,
coorV1.z * coorV2.x - coorV1.x * coorV2.z,
coorV1.x * coorV2.y - coorV1.y * coorV2.x});
}
double Vector::getLength()
{
return std::sqrt(
coorV.x * coorV.x + coorV.y * coorV.y + coorV.z * coorV.z
);
}
Vector Vector::normalize()
{
const double length = getLength();
coorV.x /= length;
coorV.y /= length;
coorV.z /= length;
return *this;
}
CoorVector Vector::getCoorVector() const
{
return coorV;
}
And I use matrices to multiply the vertices when drawing:
void Grid::customMatrixFrustum(QPainter &p)
{
M4x4 m = Matrix::getRotationZ(degreesToRadians(gridData.rotationZ));
//does not work with getPerspectiveProjection function
double scale = gridData.scale;
m = Matrix::multiply(
Matrix::getScale(scale, scale, scale),
m);
//or
// m = Matrix::multiply(
// Matrix::getGeneralScale(scale),
// m);
m = Matrix::multiply(
Matrix::getTranslation(0, 0, gridData.height),
m);
m = Matrix::multiply(
Matrix::getLookAt(
Vector({0, 0, 0, 1}), // where is the observer
Vector({-degreesToRadians(gridData.x), degreesToRadians(gridData.y), -1, 1}), // where to look
Vector({0, 1, 0, 1})
),
m);
m = Matrix::multiply(
Matrix::getPerspectiveProjection(
90, 1, -1, -1000),
m);
m = Matrix::multiply(
Matrix::getFrustum(-1, 1, -1, 1, -1, -1000),
m
);
//doesn't work as it should. the camera's view goes beyond the grid.
// m = Matrix::multiply(
// Matrix::getScale(scale, scale, scale),
// m);
QList<Vector> sceneVertices;
for (int i = 0; i < vertices.size(); i++) {
Vector vertex = Matrix::multiplyVector(
m,
vertices[i]);
CoorVector coorVertex = vertex.getCoorVector();
coorVertex.x = coorVertex.x / coorVertex.w * (this->width() / 2);
coorVertex.y = coorVertex.y / coorVertex.w * (this->width() / 2);
sceneVertices.append(Vector({coorVertex}));
}
for (int i = 0, l = edges.size(); i < l; i++) {
std::array<int, 2> e = edges[i];
CoorVector coorP1 = sceneVertices[e[0]].getCoorVector();
CoorVector coorP2 = sceneVertices[e[1]].getCoorVector();
if (e[0] == 2 && e[1] == 3) {
qDebug() << "points:" << e[0] << e[1]
<< coorP1.x << coorP1.y << coorP1.w
<< coorP2.x << coorP2.y << coorP2.w;
qDebug() << "lines:" << e[0] << e[1]
<< QPoint(coorP1.x + this->width() / 2, -(coorP1.y - this->height() / 2)) << coorP1.w
<< QPoint(coorP2.x + this->width() / 2, -(coorP2.y - this->height() / 2)) << coorP2.w;
}
p.drawLine(coorP1.x + this->width() / 2, coorP1.y + (this->height() / 2),
coorP2.x + this->width() / 2, coorP2.y + (this->height() / 2));
}
}
I create mesh vertices using the following algorithm:
void Grid::init()
{
//create vertices - points
countHorizontal = 100;//number of cells horizontally (counting from top to bottom)
countVertiacal = 100;//number of cells vertically (counting from left to right)
const int pointHorizontal = countHorizontal * 2 + 2;
const int pointVertiacal = countVertiacal * 2 - 2;
const int pointCount = pointHorizontal + pointVertiacal;
const double intervalHorizontal = 2 / (double)countHorizontal;
const double intervalVertical = 2 / (double)countVertiacal;
double currentIntHor = 1;// Descent from top to bottom
double currentIntVer = -1 + intervalVertical;//descent from left to right
for (int i = 0; i < pointCount; ++i) {
if (i < pointHorizontal) {
if (i % 2) {
vertices.append(Vector({1, currentIntHor, 0, 1}));//performed second
currentIntHor -= intervalHorizontal;
} else {
vertices.append(Vector({-1, currentIntHor, 0, 1}));//runs first
}
} else {
if (i % 2) {
vertices.append(Vector({currentIntVer, -1, 0, 1}));//performed second
currentIntVer += intervalVertical;
} else {
vertices.append(Vector({currentIntVer, 1, 0, 1})); //runs first
}
}
}
//Create pairs of vertex indices for lines
const int vertical = countHorizontal + 1;
const int horizontal = countVertiacal + 1;
for (int i = 0; i < vertical; ++i) {
edges.append({i*2, i*2 + 1});
}
const int lastHorIndex = edges.size() - 1;
std::array<int, 2> lastHorVal = edges[lastHorIndex];
for (int i = 0; i < horizontal; ++i){
if (i == 0) {//first line
edges.append({0, lastHorVal[0]});
} else if (i == horizontal - 1) {//last line
edges.append({1, lastHorVal[1]});
} else {
const int magic = 2 * i;
edges.append({lastHorVal[1] + magic - 1, lastHorVal[1] + magic});
}
}
}
In the figure it looks like this:
create grid
With a scale of 3 and a camera angle of 90 degrees in x, the grid looks like this:
norm grid
When you increase the camera rotation in x by 1 degree, the grid already breaks:
broken grid
And if you increase the scale of the grid, then the angle of rotation of the camera when drawing the grid becomes smaller. I assume that the problem is with the w factor, since it does not change for the better when the grid is scaled up. And I don't know how to change it so that the grid after scaling and perspective is drawn normally.
I posted the problem code on github:
grid project
P.S. I tried QMatrix4x4 but when passing the values ​​from the example, perspective didn't work. If someone solves my problem through QMatrix4x4 I will be glad.

Calculating a determinant in Lua

I'm trying to calculate determinants with any order using Lua. I can calculate determinants for order less than 4, but not for greater equals than 4 ones.
I have a 4x4 matrix and its determinant with the program is 0, but the real solution is 56.
I don't know if the problem is in getSubmatrix method or is in detMat method, because I don't have any error message from the console.
I've ported the methods from my own java code, where it works fine.
Here's all my code:
function numMat(n, A)
local S = {}
for i = 1, #A, 1 do
local T = {}
S[i] = T
for j =1, #A[1], 1 do
T[j] = n * A[i][j]
end
end
return S
end
function sumMat(A, B)
local C = {}
for i = 1, #A do
local D = {}
C[i] = D
for j = 1, #A[1] do
D[j] = A[i][j] + B[i][j]
end
end
return C
end
function subMat(A, B)
return sumMat(A, numMat(-1, B))
end
function printMatrix(A)
for i, v in ipairs(A) do
for j, w in ipairs(v) do
print(w)
end
end
end
function escalarProduct(u, v)
local w = 0
for i = 1, #u do
w = w + u[i] * v[i]
end
return w
end
function prodMat(A, B)
local C = {}
for i = 1, #A do
C[i] = {}
for j = 1, #B[1] do
local num = A[i][1] * B[1][j]
for k = 2, #A[1] do
num = num + A[i][k] * B[k][j]
end
C[i][j] = num
end
end
return C
end
function powMat(A, power)
local B = {}
local C = {}
C = A
for i = 1, power - 1 do
B = prodMat(C, A)
C = B
end
return B
end
function trasposeMat(A)
local B = {}
for i = 1, #A do
local C = {}
B[i] = C
for j = 1, #A[1] do
C[j] = A[j][i]
end
end
return B
end
function productDiag(m)
local prod = 1
for i = 1, #m do
for j = 1, #m do
if i == j then prod = prod * m[i][i] end
end
end
return prod
end
function isDiagonal(A)
for i = 1, #A do
for j = 1, #A do
if i ~= j and A[i][j] ~= 0 then return false end
end
end
return true
end
function isTriangSup(m)
for i = 1, #m do
for j = 1, i do
if m[i][j] == 0 then return true end
end
end
return false
end
function isTriangInf(m)
return isTriangSup(trasposeMat(m))
end
function isTriang(m)
if(isTriangSup(m)) then return true
else
return false
end
end
function getSubmatrix(A, rows, cols, col)
local submatrix = {}
local k = 1
for j = 1, cols do
--local D = {}
--submatrix[j] = D
if j == col then
break
end
for i = 2, rows do
submatrix[i-1][k] = A[i][j]
--D[k] = A[i][j]
end
k = k + 1
end
return submatrix
end
function det2Mat(A)
assert(#A == 2 and #A == #A[1], 'Error: The matrix must be squared, order 2.')
return A[1][1] * A[2][2] - A[1][2] * A[2][1]
end
function det3Mat(A)
assert(#A == 3 and #A == #A[1], 'Error: The matrix must be squared, order 3.')
s1 = A[1][1] * A[2][2] * A[3][3] + A[2][1] * A[3][2] * A[1][3] + A[1][2] * A[2][3] * A[3][1]
s2 = A[1][3] * A[2][2] * A[3][1] + A[1][2] * A[2][1] * A[3][3] + A[2][3] * A[3][2] * A[1][1]
return s1 - s2
end
function detMat(A)
local submatrix = {}
local det
local sign = 1
local rows = #A
local cols = #A[1]
assert(rows == cols, 'Error: The matrix must be squared.')
if rows == 1 then
return A[1][1]
end
if rows == 2 then
return det2Mat(A)
end
if rows == 3 then
return det3Mat(A)
end
if isDiagonal(A) or isTriang(A) then return productDiag(A) end
if rows > 3 then
for column = 1, cols do
submatrix = getSubmatrix(A, rows, cols, column)
det = det + sign * A[1][column] * detMat(submatrix)
sign = -sign
end
end
return det
end
A = {{1, 3}, {5, 6}}
B = {{2, 4}, {3, 1}}
C = {{2, 3, 4}, {-5, 4, 7}, {7, 1, 0}}
D = {{2, 0, 0, 0}, {0, 4, 0, 0}, {0, 0, 7, 0}, {0, 0, 0, 6}}
E = {{2, 3, 4, -3}, {-5, 4, 7, -2}, {7, 1, 0, 5}, {3, 4, 5, 6}}
--printMatrix(numMat(-1, A))
--printMatrix(sumMat(A, B))
--printMatrix(subMat(A, B))
--print(escalarProduct({1, 3}, {5, 6}))
--printMatrix(prodMat(A, B))
--printMatrix(trasposeMat(A))
--printMatrix(powMat(A, 2))
--printMatrix(powMat(A, 3))
print(detMat(A))
print(detMat(B))
print(detMat(C))
print(detMat(D))
print(detMat(E)) --The solution must be 56
And the console solution is:
-9
-10
1
336
0
The error is when I want to find out the determinant of the matrix E.

Shadow map matrix transformation

I can't seem to wrap my head around these shadow map matrices. It works great when light angles are about a 45 degree lookat position to 0,0,0. For example, if the sun angle is high(y) vs x,z. The shadows don't line up with the models. A light position of (-7,-10,7) or (-9,-10,0) works fine. (-1,-10,1) is skewed. Here is my code example. -x is left, -y is up and -z is far.
public Vector3f cameraPosition = new Vector3f(0f, -10f, 7f);
public float[] lightPosition = new float[]{-7f, -10.0f, 7f}
draw objects to shadow map texture
Matrix.setLookAtM(sunMatrix, 0, -lightPosition[0], lightPosition[1], lightPosition[2],
0, 0, 0,
0f, 1f, 0f);
//projection matrix plus sun
float width = (globals.glScreenSize/2);
float height = (globals.glScreenSize/2);
Matrix.orthoM(projectionMatrix, 0, -width, width,
-height, height,
-1f, 100f);
tempMatrix = new float[16];
Matrix.multiplyMM(tempMatrix, 0, projectionMatrix, 0, sunMatrix, 0);//add camera matrix to perspective
projectionMatrix = tempMatrix.clone();
//translate
Matrix.setIdentityM(modelMatrix, 0);//set to 0
//translate
Matrix.translateM(modelMatrix, 0, modelPos.location.x,
-(modelPos.location.y),
modelPos.location.z);//move
//rotate
Matrix.rotateM(modelMatrix, 0, modelPos.angles.x, 1f, 0f, 0f);
Matrix.rotateM(modelMatrix, 0, -modelPos.angles.y, 0f, 1f, 0f);
Matrix.rotateM(modelMatrix, 0, -modelPos.angles.z, 0f, 0f, 1f);
//scale
Matrix.scaleM(modelMatrix, 0, modelPos.scales.x,
modelPos.scales.y,
modelPos.scales.z);//scale
Matrix.multiplyMM(viewProjMatrix, 0, projectionMatrix, 0, modelMatrix, 0);
//Matrix.multiplyMM(projectionMatrix, 0, globals.viewProjMatrix, 0, modelMatrix, 0);//perspective/model/view projection matrix
finalMatrix = viewProjMatrix.clone();//final matrix created
rotate around y axis and draw shadow map to screen
Matrix.setLookAtM(modelMatrix, 0, 0f, 0f, 0f,
globals.lightPosition[0], 0f, -globals.lightPosition[2],
0f, 1f, 0f);
//scale
Matrix.scaleM(modelMatrix, 0, scale.x, scale.y, scale.y);//scale
Matrix.multiplyMM(projectionMatrix, 0, globals.viewProjMatrix, 0, modelMatrix, 0);//projection matrix
finalMatrix = projectionMatrix.clone();//final matrix created
enter image description here
Thanks for any help,
Norm
I changed,
float height = (globals.glScreenSize/2) * Math.abs(lightPos.y);
Shadows all line up with the models now. If you are looking for a simple shadow map and obj loader example, check out https://github.com/Normfly/myOpenglES20
Happy coding,
Norm

Two axis plot, one of the curves is incomplete

I'm using TwoAxisPlot to combine two plots for functions from an NDSolve, but the result has one of the curves truncated and is hence incomplete. I don't understand all the jargon when defining the TwoAxisPlot function so I don't know the origin of the problem. Code is as follows:
a = 0.99*10^-9;
b = 0.24*10^-3;
d = 1.21*10^-3;
T0 = 1*10^6;
n0 = 0.9*10^9;
ti = -20;
tf = 500;
kB = 1.38*10^-16;
Qb = 0.33*10^-3;
sig = 1;
var = sig^2;
Ag = 16.5;
Qg = Ag* Exp[-(t - 10)^2/(2*var)];
Qgt = Qg + Qb;
sss = NDSolve[{T'[t] == -(n[t]^-1) T[t]^(7/2) (a) -
n[t] T[t]^(-1/2) (b) + Qgt/(2*kB*n[t]),
n'[t] == T[t]^(5/2) (a) - (n[t]^2) (T[t]^(-3/2)) (d), T[ti] == T0,
n[ti] == n0}, {T, n}, {t, ti, tf}];
This gives me two interpolating functions which I can plot fully individually:
TP = Plot[T[t] /. sss, {t, ti, 300}, PlotRange -> All];
TPPa = Show[TP, Frame -> True,
FrameLabel -> {{"Temperature, K", ""}, {"Time, s", ""}}]
NP = Plot[n[t] /. sss, {t, ti, 300}, PlotRange -> All];
NPPa = Show[NP, Frame -> True,
FrameLabel -> {{"Density, \!\(\*SuperscriptBox[\(cm\), \(-3\)]\)",
""}, {"Time, s", ""}}]
I then define the TwoAxisPlot function, unchanged, copied from this website: Wolfram Documentation Center
TwoAxisPlot[{f_, g_}, {x_, x1_, x2_}] :=
Module[{fgraph, ggraph, frange, grange, fticks,
gticks}, {fgraph, ggraph} =
MapIndexed[
Plot[#, {x, x1, x2}, Axes -> True,
PlotStyle -> ColorData[1][#2[[1]]]] &, {f, g}]; {frange,
grange} = (PlotRange /. AbsoluteOptions[#, PlotRange])[[
2]] & /# {fgraph, ggraph}; fticks = N#FindDivisions[frange, 5];
gticks =
Quiet#Transpose#{fticks,
ToString[NumberForm[#, 2], StandardForm] & /#
Rescale[fticks, frange, grange]};
Show[fgraph,
ggraph /.
Graphics[graph_, s___] :>
Graphics[
GeometricTransformation[graph,
RescalingTransform[{{0, 1}, grange}, {{0, 1}, frange}]], s],
Axes -> False, Frame -> True,
FrameStyle -> {ColorData[1] /# {1, 2}, {Automatic, Automatic}},
FrameTicks -> {{fticks, gticks}, {Automatic, Automatic}}]]
and use it
TwoAxisPlot[{T[t] /. sss, n[t] /. sss}, {t, -20, 300}]
but the plot is now truncated and doesn't show the full curve. How can I fix this?
Add PlotRange -> Full as included below.
TwoAxisPlot[{f_, g_}, {x_, x1_, x2_}] := Module[
{fgraph, ggraph, frange, grange, fticks, gticks},
{fgraph, ggraph} = MapIndexed[Plot[#, {x, x1, x2}, Axes -> True,
PlotStyle -> ColorData[1][#2[[1]]], PlotRange -> Full] &, {f, g}];
{frange, grange} = (PlotRange /. AbsoluteOptions[#, PlotRange])[[2]] & /#
{fgraph, ggraph};
fticks = N#FindDivisions[frange, 5];
gticks = Quiet#Transpose#{fticks, ToString[NumberForm[#, 2],
StandardForm] & /# Rescale[fticks, frange, grange]};
Show[fgraph, ggraph /. Graphics[graph_, s___] :> Graphics[
GeometricTransformation[graph, RescalingTransform[{{0, 1}, grange},
{{0, 1}, frange}]], s], Axes -> False, Frame -> True,
FrameStyle -> {ColorData[1] /# {1, 2}, {Automatic, Automatic}},
FrameTicks -> {{fticks, gticks}, {Automatic, Automatic}}]]
Labeled[
TwoAxisPlot[{T[t] /. sss, n[t] /. sss}, {t, -20, 300}],
{Rotate["Temperature, K", Pi/2], "Time, s",
Rotate["Density, \!\(\*SuperscriptBox[\(cm\), \(-3\)]\)", Pi/2]},
{Left, Bottom, Right}]

Plot of ND solve differential equation with another parameter

I am trying to solve a differential equation numerically but I need to vary y0 for my plot and view result for constant x. I can solve my equation normally as I expected:but I can't get result when I try for my real purpose as you can see
`\[Sigma] = 1;
n = 23.04;
Rop = y[x];
R = 0.5;
sz = R/(Rop + R);
F = -n*\[Sigma]*y[x]*(1 - 2*sz);
s = NDSolve[{y'[x] == F, y[0] == 0.8}, y, {x, 0, 0.07}]
Plot[Evaluate[y[x] /. s], {x, 0, 0.07}, PlotRange -> All,]`
`[Sigma] = 1;
n = 23.04;
Rop = y[x];
R = 0.5;
sz = R/(Rop + R);
F = -n*\[Sigma]*y[x]*(1 - 2*sz);
y0 = 0.8;
\!\(\*
ButtonBox["Array",
BaseStyle->"Link",
ButtonData->"paclet:ref/Array"]\)[s, 140]
i = 1;
For[i < 140,
s = NDSolve[{y'[x] == F, y[0] == y0}, y, {x, 0, 0.07}]
Plot[Evaluate[y[] /. s], x = 0.07, {y0, 0.8, 2.2}] // print
y0 == y0 + i*0.01];`
A variety of typos or misunderstandings
\[Sigma] = 1;
n = 23.04;
Rop = y[x];
R = 0.5;
sz = R/(Rop + R);
F = -n*\[Sigma]*y[x]*(1 - 2*sz);
y0 = 0.8;
For[i = 1, i < 140, i++,
s = NDSolve[{y'[x] == F, y[0] == y0}, y, {x, 0, 0.07}];
Plot[Evaluate[y[x] /. s], {x, 0, 0.07}] // Print;
y0 = y0 + i*0.01
];
Go through that and compare it a character at a time against your original.
After you have figured out why each of the changes were made then you can try to decide whether to put your Button back in that or not.

Resources