# Error Solving numerical integral

Posted 2 months ago
862 Views
|
4 Replies
|
3 Total Likes
|
 Hello everybody,I'm trying to calculate an integral but it doesn't give a numerical result. Which mistake did I do? Any help would be appreciated! Thanks \[Mu]0 = 4*\[Pi]*10^-7; \[Rho]max = 0.22; q = {1}; i = 1; j = 1; n = {1}; aa = 0.130; m = 1; k = m; Sq[\[Rho]_, i_] := (Sin[(Indexed[q, i]*\[Pi]*\[Rho])/\[Rho]max]); dSq[\[Rho]_, i_] := (Indexed[q, i]*\[Pi]/\[Rho]max)*(Cos[(Indexed[q, i]*\[Pi]*\[Rho])/\[Rho]max]); \[Alpha][\[Rho]_] := ArcTan[\[Rho]/aa]; pn[\[Alpha]_, j_] := (N[LegendreP[Indexed[n, j], m, Cos[\[Alpha][\[Rho]]]], 20]); f[\[Rho]_] := (\[Rho]/ArcTan[\[Rho]/aa]); Cnm[j_, f_] := ((Indexed[n, j] - m)!/(Indexed[n, j] + m)!)*(1/(f[\[Rho]])^(Indexed[n, j] + 2)); pn1[\[Alpha]_, j_] := (N[LegendreP[Indexed[n, j] + 1, m, Cos[\[Alpha][\[Rho]]]], 20]); Cn\[Rho][pn_, \[Alpha]_] := (m*(pn[\[Alpha], j]/ Sin[\[Alpha][\[Rho]]])); Cnm\[Psi][j_, pn1_, pn_, \[Alpha]_] := ((1/ Sin[\[Alpha][\[Rho]]])*((Indexed[n, j] + 1)* pn[j, \[Alpha]] - (Indexed[n, j] - m + 1)* Cos[\[Alpha][\[Rho]]]*pn1[j, \[Alpha]])); DD1 = Integrate[(\[Rho]* Cnm[j, f] (Cn\[Rho][pn, \[Alpha]]*(k/\[Rho])*Sq[\[Rho], i] - Cnm\[Psi][j, pn1, pn, \[Alpha]]* D[Sq[\[Rho], i], \[Rho]])), {\[Rho], 0, 0.1}] 
4 Replies
Sort By:
Posted 2 months ago
 Sometimes you write pn, pn1 and some others Pn, Pn1: if they mean the same, use the same capitalization. Then you must give a value to k and \[Alpha].
Posted 2 months ago
 Hi Gianluca, thanks for the comment. There are two functions, pn and pn1. Alpha is a function of \rho. I've updated the script up there but still I cannot get the result.
 This version gives a number: \[Mu]0 = 4*\[Pi]*10^-7; \[Rho]max = 0.22; aa = 0.130; Sq[\[Rho]_, i_] := (Sin[(Indexed[q, i]*\[Pi]*\[Rho])/\[Rho]max]); dSq[\[Rho]_, i_] := (Indexed[q, i]*\[Pi]/\[Rho]max)*(Cos[(Indexed[q, i]*\[Pi]*\[Rho])/\[Rho]max]); \[Alpha][\[Rho]_] := ArcTan[\[Rho]/aa]; pn[j_] := (N[LegendreP[Indexed[n, j], m, Cos[\[Alpha][\[Rho]]]], 20]); f[\[Rho]_] := (\[Rho]/ArcTan[\[Rho]/aa]); Cnm[j_, f_] := ((Indexed[n, j] - m)!/(Indexed[n, j] + m)!)*(1/(f[\[Rho]])^(Indexed[n, j] + 2)); pn1[\[Alpha]_, j_] := (N[LegendreP[Indexed[n, j] + 1, m, Cos[\[Alpha][\[Rho]]]], 20]); Cn\[Rho][ pn_, \[Alpha]_] := (m*(pn[\[Alpha], j]/Sin[\[Alpha][\[Rho]]])); Cnm\[Psi][j_, pn1_, pn_, \[Alpha]_] := ((1/ Sin[\[Alpha][\[Rho]]])*((Indexed[n, j] + 1)* pn[\[Alpha], j] - (Indexed[n, j] - m + 1)* Cos[\[Alpha][\[Rho]]]*pn1[\[Alpha], j])); With[{q = {1}, i = 1, j = 1, n = {1}, m = 1, k = 1}, NIntegrate[(\[Rho]* Cnm[j, f] (Cn\[Rho][pn, \[Alpha]]*(k/\[Rho])*Sq[\[Rho], i] - Cnm\[Psi][j, pn1, pn, \[Alpha]]* D[Sq[\[Rho], i], \[Rho]])), {\[Rho], 0, 0.1}]] but it may not be what you are after. Your code is very difficult to read because you use the same symbols for both constants and variables, values and functions.
 Sorry, I made a mistake, here is the correct code: \[Mu]0 = 4*\[Pi]*10^-7; \[Rho]max = 0.22; aa = 0.130; Sq[\[Rho]_, i_] := (Sin[(Indexed[q, i]*\[Pi]*\[Rho])/\[Rho]max]); dSq[\[Rho]_, i_] := (Indexed[q, i]*\[Pi]/\[Rho]max)*(Cos[(Indexed[q, i]*\[Pi]*\[Rho])/\[Rho]max]); \[Alpha][\[Rho]_] := ArcTan[\[Rho]/aa]; pn[\[Alpha]_, j_] := (N[LegendreP[Indexed[n, j], m, Cos[\[Alpha][\[Rho]]]], 20]); f[\[Rho]_] := (\[Rho]/ArcTan[\[Rho]/aa]); Cnm[j_, f_] := ((Indexed[n, j] - m)!/(Indexed[n, j] + m)!)*(1/(f[\[Rho]])^(Indexed[n, j] + 2)); pn1[\[Alpha]_, j_] := (N[LegendreP[Indexed[n, j] + 1, m, Cos[\[Alpha][\[Rho]]]], 20]); Cn\[Rho][ pn_, \[Alpha]_] := (m*(pn[\[Alpha], j]/Sin[\[Alpha][\[Rho]]])); Cnm\[Psi][j_, pn1_, pn_, \[Alpha]_] := ((1/ Sin[\[Alpha][\[Rho]]])*((Indexed[n, j] + 1)* pn[\[Alpha], j] - (Indexed[n, j] - m + 1)* Cos[\[Alpha][\[Rho]]]*pn1[\[Alpha], j])); Block[{q = {1}, i = 1, j = 1, n = {1}, m = 1, k = 1}, NIntegrate[(\[Rho]* Cnm[j, f] (Cn\[Rho][pn, \[Alpha]]*(k/\[Rho])*Sq[\[Rho], i] - Cnm\[Psi][j, pn1, pn, \[Alpha]]* D[Sq[\[Rho], i], \[Rho]])), {\[Rho], 0, 0.1}]]