Message Boards Message Boards

0
|
2823 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How to integrate and plot equation below in short time?

Posted 9 years ago

Hey all,

In order to fit a lot of intensity measurement results over time t, I would like to use the following function:

function=Integrate[g[s+t] *Exp[-((s)/w)^2], {s,  - w, w}]

Here, g(s) is the theoretical given intensity profile, while the "convolution" with the exponential function is kind of smoothing it. Function g(s) is defined as following:

$Assumptions = 
  x \[Element] Reals && \[Phi]p \[Element] 
    Reals && \[Phi]r \[Element] Reals && de \[Element] Reals;
e1[x_, \[Phi]r_] := Exp[I (x + \[Phi]r)];
e2[x_, \[Phi]p_, \[CapitalDelta]e_] := (1 + \[CapitalDelta]e) Exp[
    I ( x + \[Phi]p)];
Int = (e1[x, \[Phi]r] + 
     e2[x, \[Phi]p, de]) Conjugate[(e1[x, \[Phi]r] + 
      e2[x, \[Phi]p, de])];
res1 = ExpToTrig[Simplify[Int]];
res2 = Simplify[res1 /. x -> 0];
TrigReduce[res2];
\[Phi][t_, \[Phi]0_, n_] = 
  If[Abs[t] < 1, \[Phi]0 Sqrt[1 - (Abs[t])^n], 0];
\[Phi][a (t + dt), \[Phi]0, n];
g[t_] = (res2 /. \[Phi]p -> \[Phi][a (t + dt), \[Phi]0, n]);

However, integration of function f(t) takes several minutes. This might be acceptable. But when I plot the function for distinct values of all the variables, the plot is even not finished after half an hour. As I would like to fit houndreds of data sets, this is inacceptable.

I have also tried to use a sum instead of an integral, in order to speed up:

function=sum[g[t + s] *Exp[-(s/w)^2], {s, -w, w, 0.01} ]

I have also tried to use the Convolve function of mathematica:

function=Convolve[g[s], Exp[-(s^2)], s, t]

Both with no improvement.

Do you have an idea how to computate the symbolic function in order to plot it in reasonable short time to perform fits to a lot of data sets?

I would be very pleased to hear your ideas. Thanks, Ka Me

POSTED BY: Ka Me
2 Replies
Posted 9 years ago

Hi Gianluca,

Thanks a lot for your reply. I have changed my script according to your suggestion and it is working much better now. The integral can be calculated and plotted in reasonable time, as you have written.

However, using the Manipulate function to adjust the fit is still not very comfortable, as Mathematica is running for a long time after moving one slider. I will see if I can directly use the NonlinearModelFit function.

Ka Me

POSTED BY: Ka Me

The function If is not well suited for symbolic computation. I would use something like Max instead. I doubt that those integrals can be computed symbolically. You can compute them numerically in a reasonable time:

e1[x_, \[Phi]r_] := Exp[I (x + \[Phi]r)];
e2[x_, \[Phi]p_, \[CapitalDelta]e_] := (1 + \[CapitalDelta]e) Exp[
    I (x + \[Phi]p)];
Int = (e1[x, \[Phi]r] + 
     e2[x, \[Phi]p, de]) Conjugate[(e1[x, \[Phi]r] + 
      e2[x, \[Phi]p, de])];
res1 = ExpToTrig[Simplify[Int]];
res2 = Simplify[res1 /. x -> 0];
\[Phi][t_, \[Phi]0_, n_] = Sqrt[Max[0, 1 - (Abs[t])^n]];
g[t_, de_, \[Phi]r_, a_, dt_, 
  n_] = (res2 /. \[Phi]p -> \[Phi][a (t + dt), \[Phi]0, n]); 
function[t_Real, w_, de_, \[Phi]r_, a_, dt_, n_] := 
 NIntegrate[
  g[s + t, de, \[Phi]r, a, dt, n]*Exp[-((s)/w)^2], {s, -w, w}];
Plot[function[t, 1, 0, 0, 1, 0, 2], {t, 0, 1}]
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract