1
$\begingroup$

I ran this code earlier, and even saved a pdf of the plot. After closing the file and reopening it later in the day, I came to find that it will not run anymore (I truly think that I saved it before closing, but oh well). Here is the code

rCMid[x_, y_, z_,ϕ1_, z1_] := {x - R*Cos[ϕ1], 
  y - R*Sin[ϕ1], z - z1}
rCNormMid[x_, y_, z_,ϕ1_, z1_] := 
 Sqrt[x^2 + y^2 + z^2 + z1^2 + R^2 - 2*z*z1 - 
   2*R*(x*Cos[ϕ1] + y*Sin[ϕ1])]

rCTop[x_, y_, z_, 
  r1_, ϕ1_] := {x - r1*Cos[ϕ1], y - 
    r1*Sin[ϕ1], z - L/2}
rCNormTop[x_, y_, z_, r1_, ϕ1_] := 
 Sqrt[x^2 + y^2 + z^2 + (L/2)^2 + r1^2 - z*L - 
   2*r1*(x*Cos[ϕ1] + y*Sin[ϕ1])]

rCBottom[x_, y_, z_, 
  r1_,ϕ1_] := {x - r1*Cos[ϕ1], y - 
    r1*Sin[ϕ1], z + L/2}
rCNormBottom[x_, y_, z_, r1_,ϕ1_] := 
 Sqrt[x^2 + y^2 + z^2 + (L/2)^2 + r1^2 + z*L - 
   2*r1*(x*Cos[ϕ1] + y*Sin[ϕ1])]

eleCyl[x_?NumericQ, y_?NumericQ, z_?NumericQ, L_?NumericQ, 
  R_?NumericQ] := 
 NIntegrate[(rCMid[x, y, z,ϕ1, z1]/
      rCNormMid[x, y, z,ϕ1, z1]^3)*R, {ϕ1, 0, 
    2*\[Pi]}, {z1, -L/2, L/2}, AccuracyGoal -> 8] + 
  NIntegrate[(rCTop[x, y, z, r1,ϕ1]/
      rCNormTop[x, y, z, r1,ϕ1]^3)*r1, {ϕ1, 0, 
    2*\[Pi]}, {r1, 0, R}, AccuracyGoal -> 8] + 
  NIntegrate[(rCBottom[x, y, z, r1,ϕ1]/
      rCNormBottom[x, y, z, r1,ϕ1]^3)*r1, {ϕ1, 0, 
    2*\[Pi]}, {r1, 0, R}, AccuracyGoal -> 8]

vecPlotCyl = 
  With[{R = 0.5, L = 3}, 
   VectorPlot3D[
    eleCyl[x, y, z, L, R], {x, -3, 3}, {y, -3, 3}, {z, -4, 4}, 
    VectorStyle -> {"Arrow3D", Medium}, 
    VectorColorFunction -> "DarkRainbow", VectorPoints -> 8]];

Here is the error it gives me when i try to run the Vector3DPlot:

NIntegrate::inumr: The integrand (0.5 (-3.99886-z1))/(33.9806 +<<5>>)^(3/2) has evaluated to non-numerical values for all sampling points in the region with boundaries {{0,6.28319},{-(3/2),3/2}}.

Which leads me to believe it is an issue with my function rCMid, but I just can not figure it out. Any help would be much appreciated

$\endgroup$
3
$\begingroup$

NIntegrate does not recognize R and L in the integrand. Define it explicitly in your functions:

rCMid[x_, y_, z_, \[Phi]1_, z1_, R_] = {x - R*Cos[\[Phi]1], 
y - R*Sin[\[Phi]1], z - z1}
rCNormMid[x_, y_, z_, \[Phi]1_, z1_, R_] = 
Sqrt[x^2 + y^2 + z^2 + z1^2 + R^2 - 2*z*z1 - 
2*R*(x*Cos[\[Phi]1] + y*Sin[\[Phi]1])]

rCTop[x_, y_, z_, r1_, \[Phi]1_, L_] = {x - r1*Cos[\[Phi]1], 
y - r1*Sin[\[Phi]1], z - L/2}
rCNormTop[x_, y_, z_, r1_, \[Phi]1_, L_] = 
Sqrt[x^2 + y^2 + z^2 + (L/2)^2 + r1^2 - z*L - 
2*r1*(x*Cos[\[Phi]1] + y*Sin[\[Phi]1])]

rCBottom[x_, y_, z_, r1_, \[Phi]1_, L_] = {x - r1*Cos[\[Phi]1], 
y - r1*Sin[\[Phi]1], z + L/2}
rCNormBottom[x_, y_, z_, r1_, \[Phi]1_, L_] = 
Sqrt[x^2 + y^2 + z^2 + (L/2)^2 + r1^2 + z*L - 
2*r1*(x*Cos[\[Phi]1] + y*Sin[\[Phi]1])]

eleCyl[x_?NumericQ, y_?NumericQ, z_?NumericQ, L_?NumericQ, 
R_?NumericQ] := 
NIntegrate[(rCMid[x, y, z, \[Phi]1, z1, R]/
  rCNormMid[x, y, z, \[Phi]1, z1, R]^3)*R, {\[Phi]1, 0, 
2*\[Pi]}, {z1, -L/2, L/2}, AccuracyGoal -> 8] +
NIntegrate[(rCTop[x, y, z, r1, \[Phi]1, L]/
  rCNormTop[x, y, z, r1, \[Phi]1, L]^3)*r1, {\[Phi]1, 0, 
2*\[Pi]}, {r1, 0, R}, AccuracyGoal -> 8] +
NIntegrate[(rCBottom[x, y, z, r1, \[Phi]1, L]/
  rCNormBottom[x, y, z, r1, \[Phi]1, L]^3)*r1, {\[Phi]1, 0, 
2*\[Pi]}, {r1, 0, R}, AccuracyGoal -> 8]

vecPlotCyl = 
With[{R = 0.5, L = 3}, 
VectorPlot3D[
eleCyl[x, y, z, L, R], {x, -3, 3}, {y, -3, 3}, {z, -4, 4}, 
VectorStyle -> {"Arrow3D"}, VectorColorFunction -> "DarkRainbow", 
VectorPoints -> 8]]

enter image description here

$\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.