Message Boards Message Boards

0
|
9265 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

Using an InterpolatingFunction in another function?

Posted 9 years ago

I used NDsolve for a first order ODE which results in an Interpolating Function for y[x]. My question is how do I use the values of this function y[x] in some other function f(y[x])? I do not really care what the values are for f(y[x]), but rather just need to plot this function.
Solution found. Use First[Evaluate [interpolating function] when including it in another function.

ifun = NDSolve[ODE, y[0] == 0.1}, y, {x, 0, 5}, Method -> "ExplicitRungeKutta"]

Plot[Evaluate[y[x] /. ifun], {x, 0, 5}, AxesLabel -> {"X", "Y[X]"}]

Other Function with ifun = (200x)/y[x]

Plot[Other Function with ifun, {x, 0, 5}]

POSTED BY: Nick Perry
Posted 9 years ago

Hi Nick,

The solution is quite obvious:

ifun = NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1}, y, {x, 0, 30}];

Plot[Evaluate[(200 x)/y[x] /. ifun], {x, 0, 5}, AxesLabel -> {"X", "\!\(\*FractionBox[\(200\\\ X\), \(Y[X]\)]\)"}]

plot

POSTED BY: Alexey Popkov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract