I have a 3D curve

K2[s_] := 
c1[s] + 0.4*(j[s]*Sin[500*Pi*s/97.8] - v[s]*Cos [500*Pi*s/97.8])

where j and v are frame vectors.

I want to find the integral of the squared second derivative of the curve with respect to parameter s, from 0 to 5.

h[s_] := D[D[K2[s], s], s]

NIntegrate[(h[s])^2, {s, 0, 5}]

takes too long and gives;

The integrand (<<6>>+0.4` (<<1>>))^2 has evaluated to non-numerical \
values for all sampling points in the region with boundaries \
{{0,5`}}. >

Where do I do wrong? Should I use numerical derivatives?

Thank you.

  • $\begingroup$ Does K2[s] evaluate to a numerical value within the region {s,0,5}? $\endgroup$ – bobthechemist Apr 17 '15 at 17:26
  • $\begingroup$ I checked but no, however I can plot the function. $\endgroup$ – thedude Apr 17 '15 at 17:33

Let's try to simplify your question. I don't have the definitions for c1, j and v, so I'll just use:

K2[s_] := s^3


h[s_] := D[D[K2[s], s], s]

(you could also write D[k2[s], {s, 2}], to get the second derivative, but that's probably a matter of taste.)

Now if you evaluate:


you get the strange result:

D[D[8., 2.], 2.]

and the error message:

General::ivar: 2.` is not a valid variable. >>

To understand this, you have to understand how := (SetDelayed) works. In a nutshell: h[s_] := ... basically means "whenever you see the pattern h[something], take this expression, replace s with something and evaluate the whole thing. So h[2.] first evaluates to:

D[D[K2[2.], 2.], 2.]

And now the error message makes sense: You can't derive some expression by 2., because 2. is not a variable.

The easiest way around this is to use Set instead of SetDelayed, which evaluates the symbolic derivative on the right hand side, then assigns it to h[s]:

h[s_] = D[D[K2[s], s], s]

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.