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?
Blockdoesn't support the syntaxBlock[{{t1,t2}=…}, please check the document carefully. Simplest fix is probablyBlock[{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 aBlockthat supports this syntax, check this post: https://mathematica.stackexchange.com/q/28610/1871 – xzczd Dec 12 '20 at 12:51