Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Mathematics
General TopicsResearchOperations ResearchStatisticsMathematical LogicNumerical AnalysisUndergraduate MathAlgebra HelpRecreational Math
Math Software
MapleMathematicaMATLABScilabSASSPSS

Math Forum / Math Software / Mathematica / July 2009



Tip: Looking for answers? Try searching our database.

NDSolve to solve a set of "loop" equations

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Haibo Min - 02 Jul 2009 12:14 GMT
Hi, there.

I am new to mathematica and recently I am intrigued by the convenience of
NDSolve function, since there is no need to write the Runge-kutta like
functions myself to solve ODEs. However, if what I want to solve is a list
of equations expressed in a loop way, I have no idea how to express it.

For example, a set of simple equations are:
Subscript[y, i]'[x]  = Subscript[y, i][x] Cos[x + Subscript[y, i][x]] + i,
where i=1,2,...,N;

if N is small, of course I can write the equations separately, i.e.
Subscript[y,1]'[x]  = Subscript[y,1][x] Cos[x + Subscript[y,1][x]] + 1
Subscript[y,2]'[x]  = Subscript[y,2][x] Cos[x + Subscript[y,2][x]] + 2
...
Subscript[y,N]'[x]  = Subscript[y,N][x] Cos[x + Subscript[y,N][x]] + N
But if N is large, this method seems clumsy, so I would like to express this
kind of "loop" equations in a neat way.

I have tried to nest "do" or "for" to control this loop, but the problem is
that they can not be incorporated into the NDSolve function. Does anyone
have a better solution?

Best regards and thanks in advance.

Haibo
Pillsy - 03 Jul 2009 10:35 GMT
> Hi, there.

> I am new to mathematica and recently I am intrigued by the convenience of
> NDSolve function, since there is no need to write the Runge-kutta like
> functions myself to solve ODEs. However, if what I want to solve is a lis=
t
> of equations expressed in a loop way, I have no idea how to express it.

> For example, a set of simple equations are:
> Subscript[y, i]'[x]  = Subscript[y, i][x] Cos[x + Subscript[y, i][x]]=
+ i,
> where i=1,2,...,N;

This is almost certainly not what you want, because, like in a few
other languages, "=" is an assignment operatore, whereas "==" is the
test for equality. So instead you'd want

Subscript[y, i]'[x] == Subscript[y, i][x] Cos[x + Subscript[y, i][x]]
+ i

In order to create a list of these, for i rangeing from 1...n, you
want to use Mathematica's Table construct. This function will generate
a list of n equations, for a positive integer n:

eqns[n_Integer] /; Positive[n] :=
 Table[Subscript[y, i]'[x] == Subscript[y, i][x] Cos[x + Subscript[y,
i][x]] + i, {i, n}];

HTH,
Pillsy
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.