1
$\begingroup$

I want to write a function that takes the derivative of f wrt y1 and then find the root of this derivative when y1 equals y2. The function f contains several integrals, y1, y2 and x also appear as limits of the integrals. Eventually I would like to be able to vary x and see how the root changes.

Below is the closest I've gotten, but doesn't work.

fd[x_?NumericQ, y1_?NumericQ, y2_?NumericQ] := D[f[x, y1, y2], y1]
fr[x_?NumericQ, y10_?NumericQ] := 
 y1 /. FindRoot[fd[x, y1, y1]==0, {y1, y10}]

Am I missing a HoldAll condition for y2 in fd?

$\endgroup$
4
  • $\begingroup$ I think you are missing two things. 1. That FindRoot works with equations. So, you have to add Equal to your code. 2. That FindRoot is a completely numerical procedure. Therefore, all your parameters must be assigned to some number. Are you going to assign x to something? $\endgroup$ Commented Mar 3, 2020 at 14:16
  • $\begingroup$ Thanks, I added that fd should be equal to 0. And yes, x will be assigned a number to evaluate fr. $\endgroup$ Commented Mar 3, 2020 at 14:26
  • $\begingroup$ D[f[x, y1, y2], y1] won't work if y1 is a number. Search the site; there are many solutions presented. Depending on f, fd[x_?NumericQ, y1_?NumericQ, y2_?NumericQ] = D[f[x, y1, y2], y1] might work. So might fd[x_?NumericQ, y1_?NumericQ, y2_?NumericQ] := Derivative[0,1,0][f][x, y1, y2], but it's probably better to compute the derivative once and use the result (again, depends on f). $\endgroup$
    – Michael E2
    Commented Mar 3, 2020 at 14:41
  • $\begingroup$ @AlexeiBoulbitch Note that FindRoot[x^2 - 2, {x, 1}] works without an explicit Equal. (See the first paradigm in the docs for FindRoot.) $\endgroup$
    – Michael E2
    Commented Mar 3, 2020 at 14:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.