0
$\begingroup$

I want to generate a system of linear equations that is stable. For that I generated random coefficients and divided the 10 by 10 matrix by the largest eigenvalue and set the diagonal to -1:

  coeff={{-1., 0.150176, 0.0923103, 0.128731, 0.0603593, 0.181206, 0.154218, 
  0.181129, 0.183904, 0.0233792}, {0.150176, -1., 0.177743, 0.0363893,
   0.107509, 0.130683, 0.139527, 0.0864388, 0.142071, 
  0.0764704}, {0.0923103, 0.177743, -1., 0.0232546, 0.193606, 
  0.0888027, 0.0706979, 0.0414401, 0.189166, 0.108903}, {0.128731, 
  0.0363893, 0.0232546, -1., 0.0137908, 0.0513826, 0.164665, 0.192096,
   0.131068, 0.0269444}, {0.0603593, 0.107509, 0.193606, 
  0.0137908, -1., 0.0883905, 0.050653, 0.0422616, 0.130421, 
  0.0790802}, {0.181206, 0.130683, 0.0888027, 0.0513826, 
  0.0883905, -1., 0.109839, 0.0830945, 0.115235, 
  0.0673009}, {0.154218, 0.139527, 0.0706979, 0.164665, 0.050653, 
  0.109839, -1., 0.000702345, 0.203273, 0.187426}, {0.181129, 
  0.0864388, 0.0414401, 0.192096, 0.0422616, 0.0830945, 
  0.000702345, -1., 0.158302, 0.190119}, {0.183904, 0.142071, 
  0.189166, 0.131068, 0.130421, 0.115235, 0.203273, 0.158302, -1., 
  0.0200016}, {0.0233792, 0.0764704, 0.108903, 0.0269444, 0.0790802, 
  0.0673009, 0.187426, 0.190119, 0.0200016, -1.}}

The eigenvalues are:

{-1.42454, -1.24002, -1.21288, -1.18743, -1.12673, -1.03778, \
-1.00059, -0.94649, -0.823552, -3.43571*10^-17}

so the system is stable. Now I want to generate equations from that to simulate the system's reaction to some input. Specifically, the above values should be the coefficients of some variables y1[t] to y10[t] that will be the input to DSolve along with some initial conditions.e.g. y1[0]==1. That will be 10 equations with 10 variables each. I tried to build all the equations by using strings and turning them into expressions, but this somehow did not work very well since ToExpression messes up the order and values of the variables.

Does anybody have an idea how to do this and give me an example?

$\endgroup$
4
  • 4
    $\begingroup$ Use y[i,t] (or y[i][t]) instead of yi[t] so you don't have to mess with strings. Then you just need coeff.Table[y[i,t],{i,10}]==b to get your equations. $\endgroup$ – N.J.Evans Nov 15 '17 at 13:45
  • $\begingroup$ Thanks for the hint! I'm not sure I understand entirely. Somehow I have to add y'[i,t]== in front each equation in order to use DSolve. Also, I have to somehow append the initial conditions `y[i,0]==0' asf. Not sure how to do that with your approach. Can you maybe give a full working example? $\endgroup$ – holistic Nov 15 '17 at 14:46
  • $\begingroup$ y[t_]=Table[y[i,t],{i,10}]; DSolve[coeff.y[t]==y'[t],y[t],t] You might want to check out Scope->Systems of Differential Equations->Solve a system of ODE's in vector format in the docs for DSolve $\endgroup$ – N.J.Evans Nov 15 '17 at 15:11
  • $\begingroup$ That works very well, thank you! Quick final question though: How do I add a vector of initial conditions to this? E.g. y[0]==1 and all other variables are 0. $\endgroup$ – holistic Nov 15 '17 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.