# Using variable coefficients & getting approximate functions for NDsolve?

**URL:** <https://community.wolfram.com/t/using-variable-coefficients-getting-approximate-functions-for-ndsolve/19257>\
**Category:** Questions\
**Tags:** calculus, equation-solving, graphics-and-visualization, numerical-computation\
**Created:** [December 16, 2021, 4:57pm UTC](https://community.wolfram.com/t/using-variable-coefficients-getting-approximate-functions-for-ndsolve/19257 "2021-12-16T16:57:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![morhayimeli](https://avatars.discourse-cdn.com/v4/letter/m/c37758/32.png) [@morhayimeli](https://community.wolfram.com/u/morhayimeli)\
**Post date:** [December 16, 2021, 4:57pm UTC](https://community.wolfram.com/t/using-variable-coefficients-getting-approximate-functions-for-ndsolve/19257/1 "2021-12-16T16:57:32Z")

</div>

Hello, I have a slightly complicated coupled differential equation here. I was wondering if I could actually get an approximate function to these graphs that NDSolve is producing. Moreover, can I use variable coefficients instead of the constants m and k I have on top? I’m trying to get a function where I can also vary the m and k coefficients.

[Open in Wolfram Cloud ↗](https://www.wolframcloud.com/obj/def6448e-1b75-4c5e-835b-aabbcfc32634)

---

<div class="post-metadata">

**Author:** ![hdolhaine](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/hdolhaine/32/35924_2.png) [@hdolhaine](https://community.wolfram.com/u/hdolhaine)\
**Post date:** [December 17, 2021, 12:18am UTC](https://community.wolfram.com/t/using-variable-coefficients-getting-approximate-functions-for-ndsolve/19257/2 "2021-12-17T00:18:16Z")

</div>

Something like this perhaps?

```
g = 9.81; l0 = 0.2;
Manipulate[
 sol = NDSolve[{x''[t] == (l0 + x[t])*(theta'[t])^2 - (k*x[t])/(m) + 
      g*Cos[theta[t]], 
    theta''[t] == (-2*theta'[t]*x'[t])/(l0 + x[t]) - (g*
         Sin[theta[t]])/(l0 + x[t]), x[0] == 0.05, x'[0] == 0, 
    theta[0] == 0.35, theta'[0] == 0}, {x, theta}, {t, 0, 100}];
 fx = x /. sol[[1, 1]];
 ft = theta /. sol[[1, 2]];
 
 pl1 = ParametricPlot[{t, fx[t]} /. sol, {t, 0, 40}, 
   PlotRange -> {{0, 6}, {-1, 3}}];
 pl2 = ParametricPlot[{t, ft[t]} /. sol, {t, 0, 40}];
 Show[pl1, pl2],
 {{m, .9}, 0, 2}, {{k, 10}, 0, 20}]

```

What do you mean by “approximate function to these graphs”?

---

<div class="post-metadata">

**Author:** ![morhayimeli](https://avatars.discourse-cdn.com/v4/letter/m/c37758/32.png) [@morhayimeli](https://community.wolfram.com/u/morhayimeli)\
**Post date:** [December 20, 2021, 7:17am UTC](https://community.wolfram.com/t/using-variable-coefficients-getting-approximate-functions-for-ndsolve/19257/3 "2021-12-20T07:17:29Z")

</div>

Hello, NDSolve allows me to plot the graphs of these differential equations but can it also give me an algebraic equation where I can insert an x value and output a y value. furthermore, can I make it so that this equation has the variable coefficients I have mentioned above in it. Or is this just not possible.

---

<div class="post-metadata">

**Author:** ![hdolhaine](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/hdolhaine/32/35924_2.png) [@hdolhaine](https://community.wolfram.com/u/hdolhaine)\
**Post date:** [December 20, 2021, 6:03pm UTC](https://community.wolfram.com/t/using-variable-coefficients-getting-approximate-functions-for-ndsolve/19257/4 "2021-12-20T18:03:38Z")

</div>

NDSolve gives back InterpolationFunction - objects. In my code above I called them fx and ft.

Try ft[3.57]. This should give a number, the value of theta at t = 3.57. So you insert a value and get back another one.

Concerning variable coefficients you should check the documentation of ParametricNDSolveValue. My old version of Mma doesn’t have/know this functionality.

What do you mean by algebraic equation? Why do you need this? You have already fx[t] and ft[t].
