Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have been trying to see why this integration is not converging but to no avail. The output gives only the y-values but fail to give any real value for x-values. Rather I always have something like this:

0.1, -1, Re[ NIntegrate[ Abs[x + y - 1]^k*Sign[x + y - 1]*f[x, y, θ, ρ], 
                         {x, 0, 1}, {y, 0, 1}, WorkingPrecision -> 100]],
2 - 2*Re[CDF[StudentTDistribution[1.1], ComplexInfinity]] 0.1, -0.7, 
Re[ NIntegrate[ Abs[x + y - 1]^k*Sign[x + y - 1]*f[x, y, θ, ρ], 
                {x, 0, 1}, {y, 0, 1}, WorkingPrecision -> 100]],
0.22388681701262803 0.1, -0.39999999999999997, 
Re[ NIntegrate[ Abs[x + y - 1]^k*Sign[x + y - 1]*f[x, y, θ, ρ], 
                {x, 0, 1}, {y, 0, 1}, WorkingPrecision -> 100]], 
0.33847856188105085 0.1, -0.09999999999999998, 
Re[ NIntegrate[ Abs[x + y - 1]^k*Sign[x + y - 1]*f[x, y, θ, ρ], 
                {x, 0, 1}, {y, 0, 1}, WorkingPrecision -> 100]], 
0.43918067389892146 
0.1, 0.2, Re[ NIntegrate[ Abs[x + y - 1]^k*Sign[x + y - 1]*f[x, y, θ, ρ],
                          {x, 0, 1}, {y, 0, 1}, WorkingPrecision -> 100]],
0.5383910479350043 "

The code is this:

ClearAll[A, f, θ, ρ, data, θmin, θmax, ρmin, ρmax, θinc, ρinc, c1, c2];
θmin = 0.1; θmax = 5; ρmin = -1; ρmax = 1; θinc = 0.01; ρinc = 0.3; k = 3;
data = {};
A[w_, θ_, ρ_] :=  w (CDF[StudentTDistribution[θ + 1], Sqrt[(1 + θ)/(1 -   ρ^2)] ( (w/(1 - w))^(1/θ) - ρ)]) + (1 - w) (CDF[ StudentTDistribution[θ + 1], Sqrt[(1 + θ)/(1 - ρ^2)] (((1 - w)/ w)^(1/θ) - ρ)]);
c1[x_, y_, θ_, ρ_] := Exp[Log[x y] A[Log[y]/Log[x y], θ, ρ]];
c2[x_, y_, θ_, ρ_] :=  x + y - 1 + c1[1 - x, 1 - y, θ, ρ];
f[x_, y_, θ_, ρ_] := D[c1[x, y, θ, ρ], x, y];
stream = OpenWrite["./data2011", BinaryFormat -> True];  
For[θ = θmin, θ <= θmax, θ += θinc, ρmin = -1; ρmax = 1;
 For[ρ = ρmin, ρ < ρmax, ρ += ρinc, 
  Print["θ=", θ, ", ρ=", ρ];
list = Re[{{θ, ρ, NIntegrate[ Abs[x + y - 1]^k Sign[x + y - 1] f[x, y, θ, ρ], {x, 0, 1}, {y, 0, 1}, WorkingPrecision -> 100], 2 - 2 A[1/2, θ, ρ]}}];
Export[stream, Table@list, "CSV"];

WriteString[stream, "\n"];]]
share|improve this question

closed as off-topic by Michael E2, Jens, Öskå, m_goldberg, Pickett Jul 19 at 2:09

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Michael E2, Jens, Öskå, m_goldberg, Pickett
If this question can be reworded to fit the rules in the help center, please edit the question.

    
Please format your code using the guidelines provided here. They are also available when you click the yellow question mark, top left of the edit box. –  Sjoerd C. de Vries Jul 17 at 10:44
    
What are the numbers in front of NIntegrate? It's not valid Mathematica syntax as is. They would seem to have nothing to do with the integration or your question -- is that right? Please clarify. Thanks. –  Michael E2 Jul 18 at 16:13
    
Note that A[Log[y]/Log[x y], θ, ρmin] is undefined; also for ρmax. Also, you might define f[x_, y_, θ_, ρ_] = D[c1[x, y, θ, ρ], x, y] with = (or use Evaluate) to take care of the problem with D mentioned below by Oliver Jennrich. Otherwise NIntegrate seems to work fine. For a question on this site, you ought to strip out the unnecessary code. You might also appreciate using Table instead of a using For loops. –  Michael E2 Jul 18 at 18:56

1 Answer 1

In any attempt to debug a code - make it as simple as possible. Neither the For-loops nor the Export make things easier.

Try to break things down - if I evaluate

f[0.1, 0.1, 0.1, -1]

I already get nonsense. One (!) of the problems is the definition of the function f, as you try to calculate the derivative for numerical parameters. Something along the line of

f[x_, y_, t_, r_] := D[c1[a, b, t, r], a, b]/. {a-> x, b-> y}; 

might be more useful.

share|improve this answer

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