|
Science Forum Index » Math - Numerical Analysis Forum » ODE to difference equation and solution
Page 1 of 1
|
| Author |
Message |
| Calvin Guan |
Posted: Thu Jan 18, 2007 7:05 pm |
|
|
|
Guest
|
Hello,
I'm trying to convert an 2nd order ODE to difference equation and solve it
numerically. Here is an example.
y''=sin(x), given the IC y(0)=0 and BC y(3.14)=0. This can be solved
analytically if y'(0) is known.
I convert the ODE to DE like:
y(n+1)-2y(n)+y(n-1)=h*h*sin(n*h)
given initial value y(0)=0
and final y(m+1)=0 where h=3.14/(m+1)
This can be solved by constructing a m*m matrix. but it became very resource
demanding if m is big. I try to solve it by z-transform but I don't have the
value for y(1).
How this can be solved efficiently?
Thanks,
Calvin |
|
|
| Back to top |
|
| Carl Barron |
Posted: Thu Jan 18, 2007 10:51 pm |
|
|
|
Guest
|
In article <c3Trh.24536$sR.21775@newssvr29.news.prodigy.net>, Calvin
Guan <hguan@nospam.broadcom.com> wrote:
Quote: Hello,
I'm trying to convert an 2nd order ODE to difference equation and solve it
numerically. Here is an example.
y''=sin(x), given the IC y(0)=0 and BC y(3.14)=0. This can be solved
analytically if y'(0) is known.
I convert the ODE to DE like:
y(n+1)-2y(n)+y(n-1)=h*h*sin(n*h)
given initial value y(0)=0
and final y(m+1)=0 where h=3.14/(m+1)
This can be solved by constructing a m*m matrix. but it became very resource
demanding if m is big. I try to solve it by z-transform but I don't have the
value for y(1).
How this can be solved efficiently?
Thanks,
Calvin
The matrix is almost tridiagonal. A fixed # of gauss eliminations
reduces this to a tridiagonal system. This takes about 3*m data
locations and O(m) flops, using a special lu decomposition or guass
elimination using the fact the matrix is tri diagonal. |
|
|
| Back to top |
|
| Roy Stogner |
Posted: Thu Jan 18, 2007 11:43 pm |
|
|
|
Guest
|
On Thu, 18 Jan 2007 23:05:44 +0000, Calvin Guan wrote:
Quote: I'm trying to convert an 2nd order ODE to difference equation and solve
it numerically. Here is an example.
y''=sin(x), given the IC y(0)=0 and BC y(3.14)=0. This can be solved
analytically if y'(0) is known.
It can be solved analytically given just y(0) and y(3.14) - although the
analytic solution looks nicer if you're given y(0) and y(pi) instead.
Yeah, I know, for engineering uses "pi = 3.14" is often close enough, but
I've had to help one student who defined "double pi = 3.14;" in his code
and then couldn't figure out why his solution never converged to better
than three significant figures of accuracy...
Quote: y(n+1)-2y(n)+y(n-1)=h*h*sin(n*h)
given initial value y(0)=0
and final y(m+1)=0 where h=3.14/(m+1)
This can be solved by constructing a m*m matrix. but it became very
resource demanding if m is big.
Yes; you would want to store the matrix in some sparse format and use a
solver aware of that; by creating a matrix with m*m entries you end up
storing and calculating with a whole lot of unnecessary zeros.
Do a Google search for "tridiagonal solver" or "Thomas algorithm". When
you move on to PDEs you'll have to worry about sparsity patterns and look
at iterative solvers, but for ODEs you can simply store diagonal vectors
and use a bandwidth-aware version of Gaussian elimination, and you'll get
O(n) instead of O(n^3) expense.
---
Roy Stogner |
|
|
| Back to top |
|
| Robert Israel |
Posted: Fri Jan 19, 2007 12:23 am |
|
|
|
Guest
|
In article <c3Trh.24536$sR.21775@newssvr29.news.prodigy.net>,
Calvin Guan <hguan@nospam.broadcom.com> wrote:
Quote: Hello,
I'm trying to convert an 2nd order ODE to difference equation
and solve it
numerically. Here is an example.
y''=sin(x), given the IC y(0)=0 and BC y(3.14)=0. This can be solved
analytically if y'(0) is known.
I convert the ODE to DE like:
y(n+1)-2y(n)+y(n-1)=h*h*sin(n*h)
given initial value y(0)=0
and final y(m+1)=0 where h=3.14/(m+1)
This can be solved by constructing a m*m matrix. but it became
very resource
demanding if m is big. I try to solve it by z-transform but I
don't have the
value for y(1).
How this can be solved efficiently?
This is a linear equation.
The general solution is of the form
y(n) = a + b n + y_p(n)
where y_p is one particular solution (obtained numerically
or symbolically) and a + b n is the general solution of the
homogeneous equation y(n+1) - 2 y(n) + y(n-1) = 0.
To obtain the values of the constants a and b, just solve
the boundary conditions
a + y_p(0) = 0
a + b (m+1) + y_p(m+1) = 0
Robert Israel israel@math.ubc.ca
Department of Mathematics http://www.math.ubc.ca/~israel
University of British Columbia Vancouver, BC, Canada |
|
|
| Back to top |
|
| A.L. |
Posted: Fri Jan 19, 2007 9:58 am |
|
|
|
Guest
|
On Thu, 18 Jan 2007 23:05:44 GMT, "Calvin Guan"
<hguan@nospam.broadcom.com> wrote:
Quote: Hello,
I'm trying to convert an 2nd order ODE to difference equation and solve it
numerically. Here is an example.
y''=sin(x), given the IC y(0)=0 and BC y(3.14)=0. This can be solved
analytically if y'(0) is known.
I convert the ODE to DE like:
y(n+1)-2y(n)+y(n-1)=h*h*sin(n*h)
given initial value y(0)=0
and final y(m+1)=0 where h=3.14/(m+1)
This can be solved by constructing a m*m matrix. but it became very resource
demanding if m is big. I try to solve it by z-transform but I don't have the
value for y(1).
How this can be solved efficiently?
By solving numerically equation for y'(0).
See the book: "Quasilinearization and nonlinear boundary-value
problems" (Modern analytic and computational methods in science and
mathematics) by Richard Ernest Bellman
A.L. |
|
|
| Back to top |
|
| Calvin Guan |
Posted: Fri Jan 19, 2007 8:56 pm |
|
|
|
Guest
|
Thanks to everyone who had help me to understand the problem from different
angles.
Now a -sin(x) trace has been beautifully drawn on my screen.
Calvin
Quote: Hello,
I'm trying to convert an 2nd order ODE to difference equation and solve it
numerically. Here is an example.
y''=sin(x), given the IC y(0)=0 and BC y(3.14)=0. This can be solved
analytically if y'(0) is known.
I convert the ODE to DE like:
y(n+1)-2y(n)+y(n-1)=h*h*sin(n*h)
given initial value y(0)=0
and final y(m+1)=0 where h=3.14/(m+1)
This can be solved by constructing a m*m matrix. but it became very
resource demanding if m is big. I try to solve it by z-transform but I
don't have the value for y(1).
How this can be solved efficiently?
Thanks,
Calvin
|
|
|
| Back to top |
|
| |