For example, Here is a NDSolve function with a parameter of w
s[w_] := NDSolve[{x''[t] == -T1 x'[t] + C1*Ex[x[t], y[t], t, w],
y''[t] == -T1 y'[t] + C1*Ey[x[t], y[t], t, w] - g, x[0] == 0,
y[0] == 0, x'[0] == 0, y'[0] == 0}, {x, y}, {t, 0,
timelimit}];
MMy[t_] = y[t] /. s[7];
ymax = Max[Table[MMy[i], {i, timelimit - 2, timelimit, .00001}]];
In this way, I can know the max value when w=7.
Now, how can I set a functin of ymax related to w.
Like ymax[w_] :=
I mean if I want to get the max value of y[t], I only need to change the w in the yman[] function rather than the value in this place MMy[t_] = y[t] /. s[w]
If I can set a function ymax[w], I can easily get a series of ymax with different value of w.
I have tried this:
MMy[w_, t_] = y[t] /. s[w];
ymax[w_] = Max[Table[MMy[w, i], {i, timelimit - 2, timelimit, .00001}]];
It seems not work.
Max[y@“ValuesOnGrid” /. s[7]]? – Michael E2 Oct 14 '21 at 17:29Max[y@"ValuesOnGrid" /. s[7]]– Yue Yu Oct 14 '21 at 17:36s[w_] := NDSolve[..., {t, timelimit - 2, timelimit}]and then theMax[..]code would do what you want. Otherwise something likeMax@Select[Transpose[{y@"Grid", y@"ValuesOnGrid"} /. s[7]}], #[[1, 1]] > timelimit - 2 &]-- I don't have a computer at hand, so the code might need tweaking. – Michael E2 Oct 14 '21 at 17:51s[w_]withClearAll[s]; s[w_?NumericQ] :=...andMMywith:=instead of=. – Michael E2 Oct 14 '21 at 17:53:=too, which is very slow and I don't know if I can get the same results. I think the use of=stores the value of y[t] and will make the calculation of max[Table] very fast. – Yue Yu Oct 14 '21 at 18:28NDSolveands[w_], you should uses = ParametricNDSolveValue[...]withwas a parameter. It saves (recent)NDSolveresults for you internally, so that multiple calls tos[7]reuse theNDSolveresult – Michael E2 Oct 14 '21 at 18:38ParametricNDSolveValueI find examples in the help ofParametricNDSolveValueonly have single variable. – Yue Yu Oct 14 '21 at 19:00