solve non-linear simultaneous differential equation

827 Views Asked by At

I am struggling to solve the following non-linear simultaneous differential equation. $$ m\frac{dx}{dt} + cx^2 +k_1 y=0\\ m\frac{dy}{dt}-cy^2-k_1x+k_2=0 $$ where m, c, $k_1$ and $k_2$ are positive constants.

I have continued further to find y(t);

After much simplification I got;

$$ m^2k_1^2y'' -2c^2my'y^2 + 2cmk_2y'-2k_1mcyy'+cm^2y'^2+c^3y^4-2c^2k_2y^2+k_1^3y+k_2^2c=0 $$

However, I substituted all the constants in; \begin{align} m=0.66 \times 10^{-3}\\ k_1=4.6 \times 10^{-6}\\ k_2=6.5\times 10^{-3}\\ c=7.6\times 10^{-6} \end{align}

Initial condition \begin{align} t=0\\ x=0\\ y=0\\ \end{align}

and tried to run it on wolfram alpha, but it says "Standard computation time exceeded." What should I do? I do not have access to matlab.

To save your time: i pressed this into alpha wolfram - "(9.2x10^-18)y''-(7.6x10^-14)y'y^2+(6.5x10^-11)y'-(4.6x10^-14)yy'+(3.3x10^-12)(y')^2+(4.39x10^-16)y^4-(7.5x10^-13)y^2+(9.8x10^-17)y+(3.18x10^-10)=0"

So if anyone has matlab is it possible if you run this result for me.

2

There are 2 best solutions below

25
On BEST ANSWER

This MATLAB code:

function odemathse
  m = 0.66e-3;
  k = [4.6e-6, 6.5e-3];
  c = 7.6e-6;
  options = odeset('MaxStep', 1e-3, 'Stats', 'on');
  sol = ode45(@(~,y) f(y,c,m,k), [0 10], [0; 0], options);
  plot(sol.x, sol.y)
  title('Solution of ODEs')
  xlabel('t (s)')
  legend('y_1','y_2','location','southeast')
  grid on
end

function dydt = f(y,c,m,k)
  dydt = [
    -(c*y(1).^2 + k(1)*y(2));
    c*y(2).^2 + k(1)*y(1) - k(2)
  ] / m;
end

produces this answer:

enter image description here

Function f computes the derivatives in terms of current state y and parameters m, c, and k. Then @(~,y) f(y,c,m,k) fixes the values of the parameters to give an anonymous function of time and state, which is handed over to the ODE solver. The ODE solver (ode45 in this case) calls that function repeatedly to integrate. Since the system is time-invariant, the first parameter (time) to the function passed to the solver is ignored. (That's what the tilde is for.)

For Octave, the call to the ODE solver must be changed:

function [times, values] = odeoctave(tfinal)
  if nargin < 1
    tfinal = 50;
  end
  m = 0.66e-3;
  k = [4.6e-6, 6.5e-3];
  c = 7.6e-6;
  t = linspace(0,tfinal,100*tfinal);
  lsode_options('maximum step size', 1e-3);
  ys = lsode(@(y,~) f(y,c,m,k), [0; 0], t);
  plot(t, ys)
  title('Solution of ODEs')
  xlabel('t (s)')
  legend('y_1','y_2','location','east')
  grid on
  if nargout > 1
    times = t;
    values = ys.';
  end
end

The function f doesn't need any changes.

6
On

As an alternative, here is the same problem in Mathematica.

  s = With[{m = 0.66 10^(-3), k1 = 4.6 10^(-6), k2 = 6.5 10^(-3), 
  c = 7.6 10^(-6)}, NDSolve[{m x'[t] + c x[t]^2 + k1 y[t] == 0, 
  m y'[t] - c y[t]^2 - k1 x[t] + k2 == 0, x[0] == 0, y[0] == 0}, {x,
  y}, {t, 25}]]

  Plot[Evaluate[{x[t], y[t]} /. s], {t, 0, 25}]

Here is the plot of $x(t)$ and $y(t)$

enter image description here

Here is the data for $(t, x(t), y(t))$ in steps of $0.5$ for $t = 0 \ldots 25$.

$\left( \begin{array}{c} \{0.,0.,0.\} \\ \{0.5,0.00853979,-4.87822\} \\ \{1.,0.033688,-9.49226\} \\ \{1.5,0.0741245,-13.6322\} \\ \{2.,0.127927,-17.1747\} \\ \{2.5,0.192882,-20.0848\} \\ \{3.,0.266762,-22.3965\} \\ \{3.5,0.34752,-24.1843\} \\ \{4.,0.433391,-25.5384\} \\ \{4.5,0.522917,-26.5478\} \\ \{5.,0.614928,-27.2915\} \\ \{5.5,0.708507,-27.8346\} \\ \{6.,0.802938,-28.2286\} \\ \{6.5,0.897666,-28.513\} \\ \{7.,0.992259,-28.7176\} \\ \{7.5,1.08638,-28.8643\} \\ \{8.,1.17977,-28.9692\} \\ \{8.5,1.2722,-29.0441\} \\ \{9.,1.3635,-29.0975\} \\ \{9.5,1.45355,-29.1354\} \\ \{10.,1.5422,-29.1622\} \\ \{10.5,1.62938,-29.1811\} \\ \{11.,1.71499,-29.1944\} \\ \{11.5,1.79897,-29.2036\} \\ \{12.,1.88125,-29.2099\} \\ \{12.5,1.96178,-29.2142\} \\ \{13.,2.04053,-29.2171\} \\ \{13.5,2.11746,-29.2189\} \\ \{14.,2.19254,-29.2199\} \\ \{14.5,2.26575,-29.2204\} \\ \{15.,2.33708,-29.2206\} \\ \{15.5,2.40651,-29.2205\} \\ \{16.,2.47405,-29.2203\} \\ \{16.5,2.53969,-29.2199\} \\ \{17.,2.60343,-29.2194\} \\ \{17.5,2.66529,-29.2189\} \\ \{18.,2.72528,-29.2183\} \\ \{18.5,2.78342,-29.2178\} \\ \{19.,2.83972,-29.2172\} \\ \{19.5,2.8942,-29.2166\} \\ \{20.,2.9469,-29.2161\} \\ \{20.5,2.99784,-29.2155\} \\ \{21.,3.04705,-29.2149\} \\ \{21.5,3.09456,-29.2144\} \\ \{22.,3.1404,-29.2139\} \\ \{22.5,3.18462,-29.2134\} \\ \{23.,3.22724,-29.2129\} \\ \{23.5,3.2683,-29.2124\} \\ \{24.,3.30785,-29.212\} \\ \{24.5,3.34592,-29.2115\} \\ \{25.,3.38254,-29.2111\} \\ \end{array} \right)$