1
$\begingroup$

I have a system of differential equation for which I want analytical solution. Let say my equations are -

x'[t] - X[[i]]*y[t] == 0, y'[t] + X[[i]]*x[t] == 0 

where X = [0.11, 0.21, 0.31, 0.41]

How can I write a for loop such that it takes X[[i]] from X and find the analytical solution and print/plot it?

I am trying following -

For[i = 1, i < 5, sols = DSolve[{x'[t] - X[[i]]*y[t] == 0, y'[t] + X[[i]]*x[t] == 0}, x[0] == 1, y[0] == 0, {x, y}, t] ]; 

Unfortunately, it isn't working.

$\endgroup$

3 Answers 3

2
$\begingroup$
c = Range[11, 41, 10]/100; sol = Table[ DSolveValue[{x'[t] - c[[i]]*y[t] == 0, y'[t] + c[[i]]*x[t] == 0, x[0] == 1, y[0] == 0}, {x[t], y[t]}, t], {i, Length@c}]; Plot[sol, {t, 0, 60}, PlotLegends -> "Expressions", ImageSize -> Large] 

enter image description here

$\endgroup$
3
  • $\begingroup$ Thanks @Okkes Dulgerci. Could you please tell how to export solutions x[t] and y[t] separately in different files. $\endgroup$ Commented Apr 5, 2018 at 13:57
  • $\begingroup$ x[t]=sol[[All,1]] and y[t]=sol[[All,2]] $\endgroup$ Commented Apr 5, 2018 at 14:05
  • $\begingroup$ Or {x[t],y[t]}=Transpose@sol $\endgroup$ Commented Apr 5, 2018 at 14:07
1
$\begingroup$
coefs = {0.11, 0.21, 0.31, 0.41} DSolve[{x'[t] - #*y[t] == 0, y'[t] + #*x[t] == 0, x[0] == 1, y[0] == 0}, {x, y}, t] & /@ coefs 
$\endgroup$
1
$\begingroup$
X = {0.11, 0.21, 0.31, 0.41} sols = {}; For[i = 1, i < 5, i++, AppendTo[sols,DSolve[{x'[t] - X[[i]]*y[t] == 0, y'[t] + X[[i]]*x[t] == 0, x[0] == 1, y[0] == 0}, {x[t], y[t]}, t]]]; 
$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.