Dear all,
I'm struggling calculating a numerical integral. Here you can find attached (and also written in the post) two notebooks: R1 (where I used Integrate) and R2 (where I used Nintegrate). I think that R1 does not end the notebook evaluation because the integral is probably not solvable analytically, while R2 gives me a warning about the convergence and a wrong final result.
What I'm after
- The result for the integrals (variable R) should be 0.5
- When an integral is not analytically solvable (and then I suppose that I have to use Nintegrate), is it still possible to make the integral symbol appear in the code editor? In such a way to have more readable equations (especially when they are really long).
I'm sorry for bothering you with this stupid beginner question, but I tried to read the documentation but I didn't manage to solve my issue.
Thanks a lot in advance for your help.
Here is R_1:
ClearAll["Global`*"];
n2 = 1;
n1 = 1.38;
Rs[\[Theta]_] = (
n1*Cos[\[Theta]] - n2*\[Sqrt](1 - (n1/n2*Sin[\[Theta]])^2))/(
n1*Cos[\[Theta]] + n2*\[Sqrt](1 - (n1/n2*Sin[\[Theta]])^2));
Rp[\[Theta]_] = (-n2*Cos[\[Theta]] +
n1*\[Sqrt](1 - (n1/n2*Sin[\[Theta]])^2))/(
n2*Cos[\[Theta]] + n1*\[Sqrt](1 - (n1/n2*Sin[\[Theta]])^2));
R[\[Theta]_] = (Rs[\[Theta]] + Rp[\[Theta]])/2;
c1 = \!\(
\*SubsuperscriptBox[\(\[Integral]\), \(0\), \(\[Pi]/
2\)]\(R[\[Theta]]*\ Sin[\[Theta]]*
Cos[\[Theta]] \[DifferentialD]\[Theta]\)\) ;
c2 = \!\(
\*SubsuperscriptBox[\(\[Integral]\), \(\(-\[Pi]\)/
2\), \(0\)]\(R[\[Theta]]*\ Sin[\[Theta]]*
\*SuperscriptBox[\((Cos[\[Theta]])\), \(2\)] \[DifferentialD]\[Theta]\
\)\) ;
R = (3 c2 + 2 c1)/(3 c2 - 2 c1 + 2)
Here is R_2:
enter code In[47]:= ClearAll["Global`*"];
n1 = 1.38;
n2 = 1;
Rs[\[Theta]_] =
Abs[((n1*Cos[\[Theta]] - n2*\[Sqrt](1 - (n1/n2*Sin[\[Theta]])^2))/(
n1*Cos[\[Theta]] + n2*\[Sqrt](1 - (n1/n2*Sin[\[Theta]])^2)))]^2;
In[51]:= Rp[\[Theta]_] =
Abs[((n1*\[Sqrt](1 - (n1/n2*Sin[\[Theta]])^2) - n2*Cos[\[Theta]])/(
n1*\[Sqrt](1 - (n1/n2*Sin[\[Theta]])^2) + n2*Cos[\[Theta]]))]^2;
In[52]:= R[\[Theta]_] = (Rs[\[Theta]] + Rp[\[Theta]])/2;
In[53]:= c1 =
NIntegrate[
R[\[Theta]]* Sin[\[Theta]]*Cos[\[Theta]], {\[Theta], 0, \[Pi]/2},
MaxRecursion -> 100]
During evaluation of In[53]:= NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small.
Out[53]= 0.256811
In[54]:= c2 =
NIntegrate[
R[\[Theta]]* Sin[\[Theta]]*(Cos[\[Theta]])^2, {\[Theta], -(\[Pi]/2),
0}, MaxRecursion -> 100]
During evaluation of In[54]:= NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small.
Out[54]= -0.12405
In[55]:= R = (3*c2 + 2*c1)/(3*c2 - 2*c1 + 2)
Out[55]= 0.12697
Attachments: