Skip to content
Prev 43519 / 398513 Next

MATLAB to R

DivineSAAM at aol.com writes:
Are you sure this gives the same result?  If Y and T in Matlab are
vectors, I believe

for (J in 1:M)
{
  y[J+1] <- y[J] + h * f(tt[J], y[J])
  ...
}

is what you want.  (Don't use `t' as a variable; t() is the function
to transpose a matrix.)
I assume you mean k1(J) = ... and k2(J) = ...
## If f can take vector arguments:
k1 <- f(tt[-M],y)
k2 <- f(tt[-1], y+h*k1)
## Otherwise:
for (J in 1:M) {
  k1[J] <- f(tt[J], y[J])
  k2[J] <- f(tt[J+1], y[J] + h*k1[J])
}
Message-ID: <7o3c9tj298.fsf@foo.nemo-project.org>
In-Reply-To: <4368A860.211D5ACA.0B088159@aol.com> (DivineSAAM@aol.com's message of "Fri, 30 Jan 2004 16:04:52 -0500")