1
$\begingroup$
a = 3; Tau = 100; T0 = 1/2; g0 = Tanh[2/T0];
z0 = (1 - g0) Tau;
s = NDSolve[{D[G[q, x], x] + (2 z0 (1 - x)^a + q^2) G[q, x] == 
Sqrt[2/Pi] q, G[0, x] == 0, G[10, x] == 0.0795932, G[q, 0] == 0.797885 q/(q^2 + 2 z0)}, G[q, x], {q, 0, 10}, {x, 0, 1}, AccuracyGoal -> 20]
 Plot[(G[q, x]) /. s /. q -> 0.5, {x, 0, 1}]
P[y_, x_] := Sqrt[2/Pi] NIntegrate[Sin[q y]*G[q, x], {q, 0, 10}, AccuracyGoal -> 20]

Here, I want to use the G[q,x] from the NDSolve, as solution in the NIntegrate code of P[y,x]. But I am not able to understand how to call it. This code is working till Plot of G[q,x]. But P[y,x] is giving a lot of errors.

$\endgroup$
2
  • $\begingroup$ For example, use G in NDSolve. a = 3; Tau = 100; T0 = 1/2; g0 = Tanh[2/T0]; z0 = (1 - g0) Tau; sol = NDSolve[{D[G[q, x], x] + (2 z0 (1 - x)^a + q^2) G[q, x] == Sqrt[2/Pi] q, G[0, x] == 0, G[10, x] == 0.0795932, G[q, 0] == 0.797885 q/(q^2 + 2 z0)}, G, {q, 0, 10}, {x, 0, 1}, AccuracyGoal -> 20]; P[y_, x_] := Sqrt[2/Pi] NIntegrate[Sin[q y]*G[q, x] /. sol[[1]], {q, 0, 10}, AccuracyGoal -> 20]; P[3, 2] $\endgroup$
    – cvgmt
    Commented Sep 2, 2023 at 11:18
  • $\begingroup$ It works, thank you so much $\endgroup$ Commented Sep 2, 2023 at 11:25

1 Answer 1

4
$\begingroup$

Try and see if this works for you.

Btw, you are also getting

 NDSolveValue::ibcinc: Warning: boundary and initial conditions are inconsistent.

which you might want to fix.

ClearAll["Global`*"]
a = 3; Tau = 100; T0 = 1/2; g0 = Tanh[2/T0];
z0 = (1 - g0) Tau;
solG = NDSolveValue[{D[G[q, x], x] + (2 z0 (1 - x)^a + q^2) G[q, x] == 
    Sqrt[2/Pi] q, G[0, x] == 0, G[10, x] == 0.0795932, 
   G[q, 0] == 0.797885 q/(q^2 + 2 z0)}, G, {q, 0, 10}, {x, 0, 1}, 
  AccuracyGoal -> 20]

Plot[solG[0.5, x], {x, 0, 1}]

Mathematica graphics

P[y_, x_] := Sqrt[2/Pi] NIntegrate[Sin[q y]*solG[q, x], {q, 0, 10},AccuracyGoal -> 20]

and now

 P[1, 2]

Mathematica graphics

Plot[P[2, x], {x, 0, 1}]

Mathematica graphics

I also think it will be better/safer to define your P as

P[y_?NumericQ, x_?NumericQ]

Since y,x could only be numerical for things to work, because you are using NIntegrate.

$\endgroup$

Your Answer

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

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