Group Abstract Group Abstract

Message Boards Message Boards

Integrate doesn't seems to work

Posted 4 years ago

Please, I have two different functions "pwtemp1" and "pwPAMV[t]" (see notebook below). Anyone knows why when I Integrate each one, that have different values (see plot), the integrations returns the same value? Seems that the integration for "pwtemp'" is OK, but for "pwPAMV[t]" its NOT OK. "pwPAMV[t]" shall be the multiplication of functions "pwtemp1" and "pwtemp2[t]". PS: I divided the Integration result by m=10 in order to get a Average value along the axis x. Please help me find what I am missing.

15 Replies
POSTED BY: Gianluca Gorni
POSTED BY: Gianluca Gorni

Thank you. But could you see any solution to get the Integral of what was wrongly plotted? How I get the correct function that represents what is plotted?

POSTED BY: Gianluca Gorni

This seems to work:

FC1alternative[t_] = 
 Integrate[Sum[DiracDelta[t - k], {k, vti}], {t, t - Vscc, t}, 
    Assumptions -> Element[t, Reals]] /. HeavisideTheta -> UnitStep //
   PiecewiseExpand
Plot[FC1[t], {t, -1, 12}, PlotRange -> {-.1, 3.1}]
Plot[FC1alternative[t], {t, -1, 12}, PlotRange -> {-.1, 3.1}, 
 Exclusions -> None]
POSTED BY: Gianluca Gorni

Success... Thank you so much Gianluca Gorni! With your DiracDelta solution I was able to calculate the Integral that I needed! Case closed!

You forgot to divide by m. Anyway, your "functions" are awfully convoluted in their definition and Plot gets them in the wrong evaluation order. Insert Evaluate and see what happens:

Plot[pwPAMV[tt], {tt, 0, m}, PlotRange -> Full, Filling -> Axis]
Plot[Evaluate[pwPAMV[tt]], {tt, 0, m}, PlotRange -> Full, 
 Filling -> Axis]

Try this simpler example, where it is easier to understand what happens:

f := Sin[x] /. x -> Pi/2 - x;
Plot[f, {x, 0, 2 Pi}]
Plot[Evaluate[f], {x, 0, 2 Pi}]
POSTED BY: Gianluca Gorni

Thank you Gianluca, I understood your Sin example for Plot. However, I still do not understand how can I get the Integral of this graph below (that represents the function that I want in the end), divided by m=10, that should be some value near 0.0004:

enter image description here

Here I get different integrals

Vscc = 1.5; f = 0.6;
\[Tau]1 = Vscc; \[Tau]2 = f Vscc; \[Tau]3m = f Vscc; m = 10;
PAI = 0.04819277; \[Lambda] = 0.03150354; PSA = 0.025; ni = 
 IntegerPart[(m - \[Tau]1 - \[Tau]2)/\[Tau]3m] + 2;
vti = Flatten[
   Append[Append[{0, \[Tau]1, \[Tau]1 + \[Tau]2}, 
     Table[\[Tau]1 + \[Tau]2 + (i - 2) \[Tau]3m, {i, 3, ni}]], m]];
F[t_] = 1 - Exp[-\[Lambda] t];
vf = {F[t] + PAI};
Do[vf = Append[vf, 
    F[t - vti[[i]]] + PSA (vf[[i - 1]] /. t -> vti[[i]])], {i, 2, 
   ni + 1}];
pwPA = Piecewise[
   Partition[
    Riffle[vf, 
     Table[vti[[i]] \[LessSlantEqual] t < vti[[i + 1]], {i, 1, 
       ni + 1}]], 2]];

pwtemp1 = 
  Piecewise[{{pwPA /. t -> (t - Vscc), 
     Vscc \[LessSlantEqual] t < 2 Vscc}, {pwPA /. t -> (t - f Vscc), 
     2 Vscc \[LessSlantEqual] t < m}}];

FC1[t_] := Count[vti, x_ /; (t - Vscc) \[LessSlantEqual] x < t];
FC2[t_] := Count[vti, x_ /; (t - f Vscc) \[LessSlantEqual] x < t];
pwtemp2[t_] := 
  Piecewise[{{PSA^FC1[t], 
     Vscc \[LessSlantEqual] t < 2 Vscc}, {PSA^FC2[t], 
     2 Vscc \[LessSlantEqual] t < m}}];

pwPAMV[ut_] := (pwtemp1 /. t -> ut) pwtemp2[ut];

    pl1 = Plot[(pwtemp1 /. t -> tt), {tt, 0, m}, PlotRange -> Full, Filling -> Axis]
    NIntegrate[pwtemp1, {t, 0, m}]
    pl2 = Plot[pwPAMV[tt], {tt, 0, m}, PlotRange -> Full, Filling -> Axis]
    NIntegrate[pwPAMV[tt], {tt, 0, m}]/m
POSTED BY: Hans Dolhaine
Posted 4 years ago

Thank you Mr. Hans Dolhaine, but we can see by the Plot pl2, that the result of the Nintegrate, divided by m=10, should be something near 0.0004 (the average value of pl2 between 0 and 10), and your solution resulted in the value 0.0210715, that is out of what we would expect for the average.

POSTED BY: Updating Name

Hello Andre Luiz,

in my opinion the main problem is the absolute complex structure of your code.

Did you consider to use something like this?

Plot[
 {
  Piecewise[
   {
    {0, x < 3},
    {1 + 1.5 x, 3 <= x < 4},
    {SawtoothWave[{0, 1.3}, .9 x], 4 <= x < 9},
    {0, x < 9}
    }
   ]
  },
 {x, 0, 10},
 PlotStyle -> Red,
 PlotRange -> {0, 8},
 Filling -> Axis
 ]
POSTED BY: Hans Dolhaine
Posted 4 years ago

Similar crossposted here.

POSTED BY: Rohit Namjoshi

Your integrands seem to be equal

pwPAMV[t] - pwtemp1 // Simplify
POSTED BY: Hans Dolhaine
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard