0
$\begingroup$

I am looking to plot the function f[x, y]

  f[x_?NumericQ, y_?NumericQ] := Cos[x + y]/Sqrt[1 - y^2]

where y[x]<1 is the solution of the equation

y[x_] := y /. FindRoot[1 + int[x, y] + D[int[x, y], y] == 0, {y, 0.8}]

and where int is the numerical integral

int[x_?NumericQ, y_?NumericQ] := NIntegrate[Exp[-x/Sqrt[1 - t^2]]/(t^2 - y^2), {t, 0, y, 1}, Method -> "PrincipalValue"]
  • First, if I try to calculate the derivative D[int[x, y], y]] at x = 50 and y = 0.8

    Block[{x = 50, y = 0.8}, D[int[x, y], y]]
    

I get the error

(*\[PartialD](-5.391169080810072`*^-23)/\[PartialD]0.8`*)

General::ivar: 0.8` is not a valid variable.

  • Second (my real problem), when I plot this function for 0<x<10 by replace all command

    Plot[f[x, y]/.y -> y[x], {x, 0, 10}, Frame -> True, PlotRange ->{-3, 3}]]
    

it takes a huge time.

Thanks in advance for the answers and suggestions.

$\endgroup$
  • 1
    $\begingroup$ You're reusing the symbol y in a lot of different ways in these 4 lines. There's a reason it's known as good practice to use unique & descriptive function/variable names. I think doing so in this scenario might help. $\endgroup$ – user6014 Sep 30 '18 at 14:28
2
$\begingroup$

You need to limit the scope of y in y[x_] := y /. FindRoot[1 + int[x, y] + D[int[x, y], y] == 0, {y, 0.8}].

I will adapt this answer to your problem.

f[x_?NumericQ, y_?NumericQ] := Cos[x + y]/Sqrt[1 - y^2]
ClearAll[y]
y[x_] := Module[{y}, 
   y /. FindRoot[
     1 + int[x, y] + Evaluate[D[int[x, y], y]] == 0, {y, 0.8}]];
int[x_?NumericQ, y_?NumericQ] := 
 NIntegrate[Exp[-x/Sqrt[1 - t^2]]/(t^2 - y^2), {t, 0, y, 1}, 
  Method -> "PrincipalValue"]
Block[{x = 50, y = 0.8}, Evaluate[D[int[x, y], y]]]

1.39305*10^-22

Your real problem seems to be, that the integral does not converge. I cannot even evaluate int[10, 0.8], as I get warning messages:

`NIntegrate::zeroregion: Integration region {{0.8,0.800000000000000044408920985011711129445345555642315378316693834590}} cannot be further subdivided at the specified working precision. NIntegrate assumes zero integral there and on any further indivisible regions.

I do not think these messages should be ignored and there is a reasonable precision limit one should use. Before increasing precision, I would rethink possibility of analytical simplification.

$\endgroup$
  • $\begingroup$ Thank you @Johu, it's a nice analysis. For me the integral converge: int[10, 0.8]=-0.000029950778. What's the problem for you? $\endgroup$ – Gallagher Sep 30 '18 at 14:56
  • $\begingroup$ What's about the huge time in plotting this function? $\endgroup$ – Gallagher Oct 2 '18 at 7:48
  • $\begingroup$ One cannot plot it if it cannot be evaluated. $\endgroup$ – Johu Oct 2 '18 at 8:15
  • $\begingroup$ Do you have any suggestions about this huge time? $\endgroup$ – Gallagher Oct 2 '18 at 10:41

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.