Why mathematica is returning error when computing correlation under Compile?

Can someone tell me what am I doing wrong here ..

corr = Compile[{{array1, _Real, 1}, {array2, _Real, 1}},    Block[{corr}, corr = Correlation[array1, array2]; corr],CompilationTarget :> "C"] lm = Compile[{{array1, _Real, 1}, {array2, _Real, 1}},    Block[{mdlfit, x},  mdlfit = LinearModelFit[Join[Transpose[{array1}], Transpose[{array2}], 2], x, x];  {mdlfit, Sqrt[mdlfit["RSquared"]]}],CompilationTarget :> "C"] array1 = N[{2, 4, 5, 6, 3, 7, 5, 8, 9, 6, 4, 7, 6, 5}]; array2 = N[{5, 7, 8, 6, 3, 1, 2, 4, 5, 8, 7, 2, 3, 4}]; corr[array1, array2] // AbsoluteTiming lm[array1, array2] // AbsoluteTiming  

Output

CompiledFunction::cfte: Compiled expression -0.218004439363 should be a rank 1 tensor of machine-size real numbers. >>  CompiledFunction::cfexe: Could not complete external evaluation; proceeding with uncompiled evaluation. >>  {0.049968, -0.218004439363}  {0.001135, {FittedModel[6.09022556391 -0.263157894737 x], 0.218004439363}}  

why computation of Correlation is giving error while LinearModelFit is working? If I get rid of ‘CompilationTarget’ from LinearModelFit then it’s also giving error

CompiledFunction::cfex: Could not complete external evaluation at instruction 6; proceeding with uncompiled evaluation. >>  ``` 

When to trust the result of numerical integration in mathematica?

How does one know when to trust the result of numerical integration, using NIntegrate, for higher (5 or 6) dimensional integrals in mathematica? For example, I get the following result

`In[3]:= Integrate[ Exp[-a^2 – b^2 – c^2 – x^2 – y^2 – z^2], {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, {a, -2, 2}, {b, -2, 2}, {c, -2, 2}] // N

Out[3]= 30.1462`

whereas if I do the same integral numerically, I get

`In[2]:= NIntegrate[ Exp[-a^2 – b^2 – c^2 – x^2 – y^2 – z^2], {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, {a, -2, 2}, {b, -2, 2}, {c, -2, 2}] // N

During evaluation of In[2]:= NIntegrate::eincr: The global error of the strategy GlobalAdaptive has increased more than 2000 times. The global error is expected to decrease monotonically after a number of integrand evaluations. Suspect one of the following: the working precision is insufficient for the specified precision goal; the integrand is highly oscillatory or it is not a (piecewise) smooth function; or the true value of the integral is 0. Increasing the value of the GlobalAdaptive option MaxErrorIncreases might lead to a convergent numerical integration. NIntegrate obtained 30.14615590437465 and 0.0001823733624988688 for the integral and error estimates.

Out[2]= 30.1462′

This seems to indicate that one can trust the result of NIntegrate if the error estimate is a small percentage (~1%) of the estimated value of the integral. If that’s true then how would one understand the discrepancy in the values obtained in the following two cases when Mathematica does not report any errors.

`In[102]:= NIntegrate[ Exp[-a^2 – b^2 – c^2 – x^2 + y^2], {x, -2, 2}, {y, -2, 2}, {a, -2, 2}, {b, -2, 2}, {c, -2, 2}, Method -> "AdaptiveMonteCarlo"] // N

Out[102]= 298.918

In[104]:= NIntegrate[ Exp[-a^2 – b^2 – c^2 – x^2 + y^2], {x, -2, 2}, {y, -2, 2}, {a, -2, 2}, {b, -2, 2}, {c, -2, 2}, Method -> "MonteCarloRule"] // N

Out[104]= 313.592′

In the following example, I also get a result with an error bar that is a small (~2%) percentage of the value of the integral

` In[7]:= NIntegrate[ Exp[-a^2 – b^2 – c^2 – x^2 – y^2 – z^2], {x, -5, 5}, {y, -5, 5}, {z, -5, 5}, {a, -5, 5}, {b, -5, 5}, {c, -5, 5}, Method -> "AdaptiveQuasiMonteCarlo"] // N

During evaluation of In[7]:= NIntegrate::maxp: The integral failed to converge after 1000100 integrand evaluations. NIntegrate obtained 0.29686054547957375 and 0.005304460608762476 for the integral and error estimates.

Out[7]= 0.296861′

but comparing it with the following analytic evaluation of the integral

`In[8]:= Integrate[ Exp[-a^2 – b^2 – c^2 – x^2 – y^2 – z^2], {x, -5, 5}, {y, -5, 5}, {z, -5, 5}, {a, -5, 5}, {b, -5, 5}, {c, -5, 5}] // N

Out[8]= 31.0063 ‘

we see that the answer is way off. Any guidance in this regard will be greatly appreciated.

How to force mathematica to take derivatives in a specific way?

I am attempting to take some derivatives of some Lagrange planetary equations. In this I have two types of anomaly which have derivatives that are found geometrically. I’m trying to force mathematica to use the results of these derivatives. I realize that to do this I have defined the derivatives. To get Mathematica to be happy I unprotect D before doing so. Heres my code for that:

Unprotect[D];  D[f, e] := (a/r + (\[Mu]*a)/((\[Mu]*a)^(1/2)*(1 - e^2)^(1/2))^2)*Sin[f]  Unprotect[D];  D[f, M] := (1 + e*Cos[f])^2/(1 - e^2)^(3/2) 

Okay so this is all well. When I evaluate D[f,M] or D[f,e] it seems to work correctly; however when I take the derivatives of other functions derivatives don’t follow those rules I set above. For example, I made up a simple function to check this:

In[58]:= abc [a, e, i, f, c] := e*f*Sin[f]  In[59]:= D[abc[a, e, i, f, c], e]  Out[59]= f Sin[f] 

Uh oh. So my question is how do I get mathematica to match the derivatives I want?

Thanks for all your help

Resource Recommendations for Mathematica in Theoretical Physics

I know there are a lot of resources available out there for learning Wolfram Language. However, I would like to create a specific query here (which might lead to a useful thread in the future). I would be soon starting a PhD in Sting Theory and would like to learn Mathematica to make my life easy. Hence, I am looking for resources that I can use to learn Mathematica that I would be used in string theory research. As of what I know right now, there are three broad classifications of the tasks that a Theoretical physicist would be undertaking,

  1. Complicated algebraic tasks, which may involve vectors, tensors etc and their manipulations. This may also involve tasks like using differential operators, differntial forms and all sorts of algebras like lie algebra, super symmertic algebra etc.

  2. The numerical solution to eigenvalue problems, differential equations etc, which may involve use of several data structures like lists and tables.

  3. Simulation and/or data analysis and visulatization (plots etc).

I know no single book would teach all the three sorts. But can someone recommend books, resources, courses etc for each type or something? Please feel free to add to the list if I have missed a particular classification.

How is it possible that mathematica can’t calculate the eigenvectors and eigenvalues of this?

How is it possible that mathematica can’t calculate the eigenvectors and eigenvalues of this:

Code:

$  Assumptions = f \[Element] Reals ; \[CapitalNu] = (1/(4*Cosh[f]^3))*{{Exp[f]*(Cosh[f])^2, Exp[f],      Cosh[f], Cosh[f]}, {Exp[f], Exp[f]*(Cosh[f])^2, Cosh[f],      Cosh[f]}, {Cosh[f], Cosh[f], Exp[-f]*(Cosh[f])^2,      Exp[-f]}, {Cosh[f], Cosh[f], Exp[-f], Exp[-f]*(Cosh[f])^2}} Eigensystem[N]  

Image:

enter image description here

It is not very hard on paper(I ‘ve done it) but it has too many calculations. I ‘ve seen mathematica doing way harder things but it just failed on this one…

Where is my mistake?

Online Mathematica, pros and cons, linear algebra problem

I apologize in advance if this question is irrelevant to this website.

I would like to use Mathematica to solve a system of linear equations with lots of unknowns(729 unknowns), the unknowns are tensor components of curvature tensors arising from a differential geometry problem.

I would like to buy Mathematica for this purpose and I have to decide between buying it online or installing the desktop version on a PC. I m thinking of buying the online version. I have the following questions:

  1. What are the advantages and disadvantages of the desktop version over the online version ? For example, are there mathematical or programming functionalities which are available only on the desktop version and not in the online version ?

  2. I assume that if I buy the online version, then I will get a username and a password to access an online version of mathematica from any computer. (Just like how one can type latex on overleaf.com from an online account using any PC). Is my assumption correct ?

3)Does Mathematica provide a user friendly way for solving linear simultaneous equations with lots of unknowns ? Let me elaborate with an example: Say I want to solve the simultaneous equations $ x=2y+a, y-3x=7x+2$ for $ x,y$ . I would like a software where I can just type: $ x=2y+a, y-3x=7x+2$ and ask the software to solve for $ x,y$ and just give me the solution symbolically in terms of parameter $ a$ instead of me having to rearrange terms so that the equations become $ x-2y=a, y-10x=2$ and then write it in matrix form, then ask it to make a matrix inversion. The difference I am talking about might seem silly in this example but it will not be silly in my original problem where I have 700 unknowns. If this feature exists in Mathematica, it will save me a lot of time.

Thank you,