0

How can I solve this coupled differential equation?

ClearAll[x, y, g, w1, w2]
n = 1;b = 1;c = 1;
w1 = -(1/3) - 2 Sqrt[g[x]]/3;
w2 = -(b*b)*(1 + y[x])^n/(g[x])^(n - 1)*(1 - g[x] + y[x]);
g'[x] == -3*g[x]*(1 - g[x] + y[x])*(w1 - w2) + y[x]*g[x]*(1 + 3*w1);
y'[x] == -3*y[x]*(1 - g[x] + y[x])*(w1 - w2) + 
   y[x]*(1 + y[x])*(1 + 3*w1);
zhk
  • 11,939
  • 1
  • 22
  • 38
merve
  • 71
  • 6

1 Answers1

3

You can use NDSolve to solve your system of odes numerically,

n = 1; b = 1; c = 1;
w1 = -(1/3) - 2 Sqrt[g[x]]/3;
w2 = -(b*b)*(1 + y[x])^n/(g[x])^(n - 1)*(1 - g[x] + y[x]);
Eq1 = g'[x] == -3*g[x]*(1 - g[x] + y[x])*(w1 - w2) + 
       y[x]*g[x]*(1 + 3*w1)
Eq2 = y'[x] == -3*y[x]*(1 - g[x] + y[x])*(w1 - w2) + 
       y[x]*(1 + y[x])*(1 + 3*w1)
sol = NDSolve[{Eq1, Eq2, g[0] == 0.72, y[0] == 0.01}, {g, y}, {x, -3, 
   3}]
Plot[Evaluate[{g[x], y[x]} /. sol], {x, -3, 10}, PlotStyle -> Thick]

enter image description here

To plot g[x] vs y[x]

ParametricPlot[{g[x], y[x]} /. sol, {x, -3, 3}, PlotRange -> All, 
 MaxRecursion -> 8, AxesLabel -> {"g", "y"}]

enter image description here

zhk
  • 11,939
  • 1
  • 22
  • 38
  • thank you so much for your help – merve Jan 08 '17 at 09:50
  • can ı plot g(x) values versus y(x) values? – merve Jan 08 '17 at 15:43
  • 1
    @merve Sure. ParametricPlot[{g[x], y[x]} /. sol, {x, 0, 1}, PlotRange -> All, MaxRecursion -> 8, AxesLabel -> {"g", "y"}] – zhk Jan 08 '17 at 16:05
  • thank you, Plot[{g[x], y[x]} /. sol, {x, -10, 10}, PlotStyle -> Thick, PlotStyle -> {{Red}, {Green}}] ı am doing this but two of them again blue not red and green, where is the wrong? – merve Jan 08 '17 at 16:12
  • 1
    @merve Plot[Evaluate[{g[x], y[x]} /. sol], {x, -3, 10}, PlotStyle -> Thick] – zhk Jan 08 '17 at 16:45
  • thank you so much. Last question :(. how can ı put names above the lines, such as g(x), and y(x). – merve Jan 08 '17 at 17:00
  • 1
    @merve PlotLegends -> {"g", "y"}. – zhk Jan 08 '17 at 17:04
  • how can I get the datas to text or dat files? I want to plot the graphs in the another graphic programs by taking from the dates from mathematica. How can ı get? – merve Jan 28 '17 at 16:29
  • @merve http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – zhk Jan 28 '17 at 16:31
  • @merve http://mathematica.stackexchange.com/questions/19859/plot-extract-data-to-a-file – zhk Jan 28 '17 at 18:05
  • ok I have tried p = Evaluate[{g[x], y[x]} /. sol] Export["test.dat", p, "Table"] FilePrint["test.dat"] Import["test.txt", "Table"] but say interpolating function not gives the datas – merve Jan 28 '17 at 18:15
  • @merve http://mathematica.stackexchange.com/questions/134066/beautify-a-ndsolve-graph/134071#134071 – zhk Jan 28 '17 at 18:22
  • 1
    @merve data = Plot[Evaluate[{g[x], y[x]} /. sol], {x, -3, 10}, PlotStyle -> Thick]``points = Cases[Normal@data, Line[pts_, ___] :> Flatten[pts, Depth[pts] - 3], Infinity]; ifuncts = Interpolation[#, Method -> "Spline", InterpolationOrder -> 2][x] & /@ points; data = Table[Prepend[ifuncts, x], {x, -3, 10, .1}]; TableForm[data, TableHeadings -> {None, Prepend[Array["X", Length[points]], x]}]``Export["C:/tcdata/myfile.txt", data, "Table"] – zhk Jan 28 '17 at 18:27
  • when I want to plot w1 versus x and w2 versus x, on the positive side, y(x) is equal 0 and g(x) is equal 0,8 (example) why w2 goes to zero, is something wrong? When we put the values to w2 numerically, it does not go to zero it goes to negative values Plot[Evaluate[{w1, w2} /. sol], {x, -10, 10}, PlotStyle -> Thick] – merve Feb 13 '17 at 20:06
  • when I click at meta.stackexchange.com/questions/5234/ there is not any answer? – merve Feb 16 '17 at 17:47