# Evaluate the NDSolveValue at the condition point with replacement [closed]

I try to Evaluate something with replacement

Block[{{t1, t2} = NDSolveValue[{x''[t] + x[t] == 0., x[0.] == 1., x'[0.] == 0.,
WhenEvent[x'[t] > 0., {"StopIntegration"}]}, {Indexed[
x["Domain"], {1, -1}], x[Indexed[x["Domain"], {1, -1}]]}, {t,
0., 100.}, MaxStepSize -> 0.001]}, t1 + t2]


But it gets an Block::lvset error, but if I compute

{t1, t2} = NDSolveValue[{x''[t] + x[t] == 0., x[0.] == 1., x'[0.] == 0., WhenEvent[x'[t] > 0., {"StopIntegration"}]}, {Indexed[
x["Domain"], {1, -1}], x[Indexed[x["Domain"], {1, -1}]]}, {t, 0., 100.}, MaxStepSize -> 0.001]
t1 + t2


is ok. So how can I compute it in one expression?

• Block doesn't support the syntax Block[{{t1,t2}=…}, please check the document carefully. Simplest fix is probably Block[{t1, t2}, {t1, t2} = NDSolveValue[{x''[t] + x[t] == 0., x[0.] == 1., x'[0.] == 0., WhenEvent[x'[t] > 0., {"StopIntegration"}]}, {Indexed[ x["Domain"], {1, -1}], x[Indexed[x["Domain"], {1, -1}]]}, {t, 0., 100.}, MaxStepSize -> 0.001]; t1 + t2]. If you want to create a Block that supports this syntax, check this post: mathematica.stackexchange.com/q/28610/1871 Commented Dec 12, 2020 at 12:51
• @xzczd, thank you so much! Commented Dec 13, 2020 at 0:27