I'm using Mathematica, and I want to integrate a function f[wr] in wr using some method that works with a Table/Do/For in the variable wr.
I tried to use something like the Riemann's sum, to evaluate the function in some point wr_0 times the spacing (in this case 0.01). The problem is that wr depends on "[Micro]" and for each value of Micro, the integral in wr would change its limits (from [Micro] - 50*kt to [Micro] + 50*kt).
kb = 8.61*10^-5;
Te = 300;
kt = kb*Te;
sum = 0;
sum1 = 0;
data = Table[
{
Table[
{
sum = sum + (f[wr]*0.01);
sum1 = sum1 + (f[wr]*(wr - \[Micro])*0.01);
}
, {wr, \[Micro] - 50*kt, \[Micro] + 50*kt, 0.01}];
\[Micro], sum1/(Te*sum)
}
, {\[Micro], -0.4, 0.4, 0.1}];
I think this code, is not doing what I want. That is, for each value of Micro, calculate the integral (sum1 and sum) for a range of wr's and store, then for other value of Micro, do it all again, at the end i want the output of the quotient of these integrals. How could I implement that?
To illustrate the idea. For each [Micro] I have one integral to evaluate. At the last [Micro] we need to sum all the other.
If you are interested in who is f[wr]: https://pastebin.com/7SwVvTen
\[Micro]
:data[\[Micro]_]:=Module[{sum=0,sum1=0},Do[sum = sum + (f[wr]*0.01); sum1 = sum1 + (f[wr]*(wr - \[Micro])*0.01);, {wr, \[Micro] - 50*kt, \[Micro] + 50*kt, 0.01}]; sum1/(Te*sum)]
. Then use it as a function itselfdata[0.4]
or make a tableTable[data[\[Micro]],{\[Micro],-0.4,0.4,0.1}]
. $\endgroup$ – Alx Aug 9 '19 at 3:43f
some function, e.g.Sin
and see this plot:ListLinePlot[Table[data[x] /. f -> Sin, {x, -0.4, 0.4, 0.1}],PlotRange -> All]
. It is far from a horizontal line. $\endgroup$ – Alx Aug 9 '19 at 4:03