Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Why does the following Plot3D command never terminate?

vma[t_, v0_] := m Sin[w t] + v0;
vmb[t_, v0_] := m Sin[w t-2*Pi/3] + v0;
vmc[t_, v0_] := m Sin[w t+2*Pi/3] + v0;
ia[t_, theta_] := i Sin[w t + theta];
ib[t_, theta_] := i Sin[w t + theta-2*Pi/3];
ic[t_, theta_] := i Sin[w t + theta+2*Pi/3];
in[t_, theta_,v0_] := -(Sign[vma[t, v0]] vma[t, v0] ia[t, theta] + 
  Sign[vmb[t, v0]] vmb[t, v0] ib[t, theta] + 
  Sign[vmc[t, v0]] vmc[t, v0] ic[t, theta]);
vc1[theta_?NumericQ, v0_?NumericQ] := 280 + 1/(2*4700*^-6) * 
  NIntegrate[in[t, theta, v0], {t, 0, 0.3}];
Plot3D[vc1[theta,v0], {theta,-Pi, Pi}, {v0, -0.2, 0.2}]
share|improve this question

First, I don't know anything about this particular function and I've not examined the definitions closely at all. If you simply try to execute something like vc1[0.1,0.1], though, you'll find that it takes 3 or 4 seconds to evaluate. vc1[0,0] throws errors, so these things need to be more efficient. I simply changed your definition of vc1 to include some standard tricks to speed up the integration.

vc1[theta_?NumericQ, v0_?NumericQ] := 280 + 1/(2*4700*^-6) *
  NIntegrate[in[t, theta, v0], {t, 0, 0.3}, 
  PrecisionGoal -> 5, AccuracyGoal -> 3,
  Method->{"LocalAdaptive", "SymbolicProcessing"->0}];

Note that the decrease of PrecisionGoal and AccuracyGoal may be problematic for some applications, but this level of precision cannot be discerned in a plot anyway.

Now, we can also tone the expectations of Plot3D down a bit be decreasing PlotPoints and setting MaxRecursion to zero. The following now takes about 8 seconds on my machine.

Plot3D[vc1[theta, v0], {theta, -Pi, Pi}, {v0, -0.2, 0.2},
  MaxRecursion -> 0, PlotPoints -> 15]

enter image description here

share|improve this answer
Thanks,the result is consistent with MATLAB,but using mathematica is easier,I think. – user7028 Jun 28 '13 at 5:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.