0
$\begingroup$

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.

  • 0
    What kind of solution are you looking for, numerical, symbolic, ...? What did you try already, WolframAlpha, python.sympy, Maple ...?2017-02-04
  • 0
    ive tried the wolfram alpha but there seems to be no simultaneous differential solver. I'm looking for general solution for x(t) and y(t). I've tried rearranging the equation so that there would only be y(t) in the equation but then it would be a second order differential equation and the wolfram alpha cannot process this amount of data2017-02-04
  • 0
    Among the non-linear ODE (systems) there are infinitely more that do not have a symbolic general solution than those that have. What gives you the optimism that your ODE system falls inside this rare category?2017-02-04
  • 0
    I'm not quite sure what other ODE should I use and I don't have acess to Matlab. Could you give me advice on what other ODE i should try?2017-02-04
  • 0
    You could try Octave. The ODE solver (`lsode`) has a different interface from MATLAB's, but not too much.2017-02-04
  • 0
    I just got octave 2 seconds ago, but I got no idea how to put the equation in can you give me some tips2017-02-04
  • 0
    I know nothing about octave's programming language2017-02-04
  • 0
    Octave's language is very similar to MATLAB's. Are you familiar with that? Also, what are your initial conditions and desired interval of integration?2017-02-04
  • 0
    when t=0, x=0 and y=02017-02-04

2 Answers 2

0

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.

  • 0
    OMG thanks so much. By the way, which line in the code is the actual equation used?. I'm very new to matlab2017-02-04
  • 0
    temp = -(c*y(1).^2 + k(1)*y(2))/m; dydt = [ temp; (c*y(2).^2 + k(1) - temp - k(2))/m]; is this the part where you pasted the equation ; m2k21y′′−2c2my′y2+2cmk2y′−2k1mcyy′+cm2y′2+c3y4−2c2k2y2+k31y+k22c=0 ?2017-02-04
  • 0
    I started from the formulation at the top of your post. Since $dx/dt$ is used in the computation of $dy/dt$, I computed it first, and then used it twice. In solving ODEs numerically, you reduce them to first order, not the other way around.2017-02-04
  • 0
    Another question; If I were to reproduce the code is it possible if I copy and paste it into octave and run it straight away as I dont have matlab and if the solution works I want to try varying the conditions myself2017-02-04
  • 0
    Only in part. As I pointed out in my comment to your post, `lsode` and `ode45` have different interfaces. The rest will work more or less unchanged.2017-02-04
  • 0
    Oh I see, but unfortunately I edited the forum again because I realized that i made a mistake. At first I wrote k1 + dx/dt. but I changed it to k1x. I'm very sorry that was a major mistake. Anyway ^ the post is edited and the formula is now correct. Is it possible if you do the coding once more.2017-02-04
  • 0
    OK. I've updated the MATLAB solution and added the Octave equivalent.2017-02-04
  • 0
    is it possible if I collect data points from octave or find the equation that the octave program drew2017-02-05
  • 0
    It's worth a try; $y_2$ looks like a decaying exponential, and $y_1$ is some kind of sigmoid.2017-02-05
  • 0
    is there a function in octave that allows you to collect the data points obtained/ graph equation?2017-02-05
  • 0
    They are already collected in `ys` in the code above.2017-02-05
  • 0
    What is a ys? and is dydt = [ -(c*y(1).^2 + k(1)*y(2)); c*y(2).^2 + k(1)*y(1) - k(2) ] / m; when u make dy/dt and dx/dt the subject(separated by a semi colon? If so keeping the m outside of the [] means ur dividing both equations by 'm' right?2017-02-05
  • 0
    `ys` is the matrix of solutions returned by `lsode`. `dydt` is a column vector with one component for each state variable. The rows are separated by the semicolon. Finally, yes, dividing a vector by a scalar (`m`) divides all rows.2017-02-05
  • 0
    Oh where can you find this solution returned by isode? I'm very new to this program and is it possible if the program tell me the general solution?2017-02-05
  • 0
    No, `lsode` does numerical integration. It only returns a matrix of *numbers*. It doesn't compute any formula.2017-02-05
  • 0
    right now when i runit on octave i can only see a graph but not the console with data points on the graph2017-02-05
  • 0
    I'll update the Octave function so that it returns the solution. Then you call it from the command line like this: `[times, values] = odeoctave;`2017-02-05
  • 0
    When i used the command it says; error: 'odeoctave' undefined near line 1 column 172017-02-05
  • 0
    Does the `odeoctave.m` file show in the browser subwindow of the Octave GUI? Alternatively, if you are running the non-GUI version, are you running it from the directory/folder where `odeoctave.m` is stored?2017-02-05
  • 0
    I keep them all in the same folder called octave. in the folder there is "diff.m", Octave-4.2.0(GUI), Octave-4.2.0(CLI). I've tried both the non GUI version but it gives me the same error message. "error: 'odeoctave' undefined near line 1 column 17". Also do you mean the files under the name in octave.GUI. Under the name there is diff.m, octave.vbs2017-02-05
  • 0
    This was the code i pasted 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 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; end2017-02-05
  • 0
    Then I pasted "[times, values] = odeoctave;" this exact code in the command window in the same octave(GUI)2017-02-05
  • 0
    The key point is that the file that contains the code must have the same name as the function (`odeoctave`) and the `.m` extension. This is true of both Octave and MATLAB.2017-02-05
  • 0
    oh i renamed it and now theres no more error message. but when i press the code there is ; Values and times under name, double under class, dimensions (2x5000) and (1x5000) and value [0,3.4... and [0,0.0... is that where the data is suppose to show up? if not then where should i look for the data2017-02-05
  • 0
    oh i see theres a copy value when you right click it. I got itt thanksss !! a lot2017-02-05
1

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)$

  • 0
    Oh thanks this is useful as there are data points tooo. Before I download this program Im wondering do u just press run and u'll get both the graphs and data points? or must you do something extra too. Also, (nevermind if not possible) can mathematica give you the general solution for y(t) and x(t)?2017-02-05
  • 0
    In Mathematica, you use shift-enter to enter a command. You can do one at a time or both of them in this case. I will see if it can find a closed form solution.2017-02-05
  • 0
    @MewLeenutaphong: You should also upvote and/or accept the nice answer by Fabio - he was very helpful, IMO.2017-02-05
  • 0
    do i tick or something? how do i upvote?2017-02-05
  • 0
    when i upvote and press tick on one post its gone in another post?2017-02-05
  • 0
    can you only upvote 1 person in a post?2017-02-05