Message Boards Message Boards


How to remove curly brackets from NDSolve/Evaluate output

Posted 9 years ago
3 Replies
1 Total Likes
{{y-> InterpolatingFunction[{{0.,30.}},<>]}}
f[x_]:=Evaluate[y[x] /. s]
Dear All,

I am trying to get the output of a numerical solution to a differential euqation as shown in the example above. As usual I defined the function f using the Evaluate function to get the outpout from the resulting interpolating function. I notice that when substiuting a numerical value for the indepdenent variable, the output is surrounded by a curly bracket suggesting that the output is a list.
Although the presence of the curly brackets doesn't seem to affect functions like Plot[f, {x,0,30}], I notice that it is causing me some trouble when I try to use output of the function f in other computations like in parametric plot or in peicewise functions. Please advise how to remove the curly brackets from this output?

POSTED BY: Abdullah Alkudsi
3 Replies


f[x_]:=Evaluate[y[x] /. s[[1]]]


POSTED BY: Guilherme Correa
Dear Abdullah,

I am not sure whether this answers your question, because your input does not seem to be valid Mathematica input. I changed it a bit to make it work on my comptuer.
s = NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1},
  y[x], {x, 0, 30}]

If I do this and then useĀ 
f[x_] := Evaluate[y[x] /. s]
I get your output.

As you see this is a list of one element. If you only want that element you need to ask Mathematica for element one of that list.

This gives 0.991387 without the curly brackets.

POSTED BY: Marco Thiel
Thank you very much. That was helpful
POSTED BY: Abdullah Alkudsi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract