0
$\begingroup$
 N0 = 1000; N1 = 0.1 N0; s = 0.1; T1 = N0/1000; NtStep[t_, T_] := Piecewise[{{N0, t < T1}, {N1, T1 <= t <= (T1 + T)}, {N0, t > T}}] Tvalues = Range[0, N0/5, N0/1000]; Pfix[t0_, T_] := 1. - Exp[-4/ NIntegrate[ E^(-s (t - t0)) (2 NtStep[t0, T])/NtStep[t, T], {t, t0, N0}]] pfmine = Table[1/(N0 - Log[N0 s 0.5]/(0.5 s)) NIntegrate[ Pfix[t0, T], {t0, 0, N0 (*- (Log[N0 s 0.5]/(0.5 s))*)}], {T, 0, N0/5, N0/1000}] Pfixotto[t0_, T_] := 2/( NtStep[t0, T] NIntegrate[ E^(- s (t - t0)) 1/NtStep[t, T], {t, t0, N0}]) pfotto = Table[1/(N0 - Log[N0 s 0.5]/(0.5 s)) NIntegrate[ Pfixotto[t0, T], {t0, 0, N0 (*- (Log[N0 s 0.5]/(0.5 s))*)}], {T, 0, N0/5, N0/1000}] customTicksX = {{1/N0 2 \[Pi], Row[{"\!\(\*FractionBox[\(2 \[Pi]\), SubscriptBox[\(N\), \(0\)]]\ \) "}]}, {1/N0 100 \[Pi], Row[{"\!\(\*FractionBox[\(100 \[Pi]\), SubscriptBox[\(N\), \ \(0\)]]\)"}]}, {1/N0 25 \[Pi], Row[{"\!\(\*FractionBox[\(25 \[Pi]\), SubscriptBox[\(N\), \ \(0\)]]\)"}]}, {1/N0 400 \[Pi], Row[{"\!\(\*FractionBox[\(400\\\ \[Pi]\), SubscriptBox[\(N\), \(0\ \)]]\)"}]}}; a = ListPlot[Transpose@{Tvalues, pfmine}, PlotStyle -> Red, PlotRange -> All , FrameLabel -> {"growth rate", "Pfix"}, Frame -> True, LabelStyle -> Directive[Black, Bold, Medium], Frame -> Thickness[0.003]]; b = ListPlot[Transpose@{Tvalues, pfotto}, PlotStyle -> Blue, PlotRange -> All, FrameLabel -> {"growth rate", "Pfix"}, Frame -> True, LabelStyle -> Directive[Black, Bold, Medium], Frame -> Thickness[0.003]]; Show[a, b] 

I am not able to run the above code and get error as enter image description here

enter image description here

$\endgroup$
7
  • $\begingroup$ Please explain what your code is doing and where exactly you encounter an issue. $\endgroup$ Commented Feb 1, 2024 at 17:15
  • $\begingroup$ I have edited the code and pasted the error which I get $\endgroup$ Commented Feb 1, 2024 at 17:50
  • $\begingroup$ Executing pfmine = Table[1/(N0 - Log[N0 s 0.5]/(0.5 s)) NIntegrate[ Pfix[t0, T], {t0, 0, N0 (*- (Log[N0 s 0.5]/(0.5 s))*)}], {T, 0, N0/5, N0/1000}], I obtain an error "NIntegrate::nlim: t = t0 is not a valid limit of integration.". $\endgroup$ Commented Feb 1, 2024 at 18:24
  • $\begingroup$ @user64494 yes, I think you may ignore this error because t0 is a variable whose value is assigned later $\endgroup$ Commented Feb 1, 2024 at 19:26
  • $\begingroup$ There are other errors there, for example, "NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in t0 near {t0} = {4.84544}. NIntegrate obtained 186.19850829351896` and 0.04665384952817386` for the integral and error estimates.". $\endgroup$ Commented Feb 1, 2024 at 19:36

1 Answer 1

2
$\begingroup$

Your main problem consists in the behavior if NIntegrate. Consider:

Clear[f]; f[x_] := NIntegrate[t, {t, x, 10}] NIntegrate[f[z], {z, 0, 1 }] 

This gives error messages:

NIntegrate::nlim: t = z is not a valid limit of integration.

NIntgrate tries to simplify its argument f[z], that is symbolic, and obviously fails. To prevent this you need to ensure that f[z] is only evaluated if z is numeric. You can due this e.g. by:

Clear[f]; f[x_?NumericQ] := (NIntegrate[t, {t, 1, 10}]) NIntegrate[f[z], {z, 0, 1 }] 

Now there are no more error messages.

Applied to your code,you have this problem with: Pfix[t0_, T_]. Therefore define:

Pfix[t0_?NumericQ, T_] := 1. - Exp[-4/ NIntegrate[ E^(-s (t - t0)) (2 NtStep[t0, T])/NtStep[t, T], {t, t0, N0}]] 

Further, you have convergence problems in the integral in "pfmine" that may or may not give an inaccurate result. But I will not investigate this now.

$\endgroup$
1
  • $\begingroup$ perfect! thank you $\endgroup$ Commented Feb 1, 2024 at 20:29

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.