Message Boards Message Boards

Using variable coefficients & getting approximate functions for NDsolve?

Posted 2 years ago

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.

POSTED BY: Eli Morhayim
3 Replies

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].

POSTED BY: Hans Dolhaine

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"?

POSTED BY: Hans Dolhaine
Posted 2 years ago

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.

POSTED BY: Eli Morhayim
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