Search code examples
plotwolfram-mathematicadifferential-equations

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];`

Solution

  • 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.