Finite difference method-convergence

Click For Summary
SUMMARY

The forum discussion focuses on the implementation of the finite difference method (FDM) for solving a fourth-order differential equation in C. The participants discuss the convergence rate, specifically using the formula log(e1/e2)/log(J2/J1) to analyze error behavior as the step size decreases. They clarify the correct formulation of the differential equation and the associated functions, ultimately identifying that the error decreases as the step size is halved, leading to a division of the error by 4. The discussion also highlights the importance of verifying the accuracy of approximations through numerical methods like Gauss elimination for tridiagonal systems.

PREREQUISITES
  • Finite Difference Method (FDM) for numerical solutions
  • C programming for implementing numerical algorithms
  • Gauss elimination for solving tridiagonal systems
  • Understanding of convergence rates in numerical analysis
NEXT STEPS
  • Implement and analyze the finite difference method for second-order differential equations
  • Study the effects of varying step sizes on numerical stability and convergence
  • Explore advanced numerical methods such as the shooting method for boundary value problems
  • Learn about error analysis techniques in numerical computations
USEFUL FOR

Mathematicians, numerical analysts, software developers working on numerical simulations, and anyone interested in solving differential equations using computational methods.

  • #31
I like Serena said:
You have measurements at $x_0, x_1, ..., x_J$.
That are $(J+1)$ measurements.
However, you can leave out $x_0$ and $x_J$ since they are both given as boundary conditions: they are 0.
The leaves you with $(J-1)$ measurements.
So your matrix should be $(J-1) \times (J-1)$, your $b$ should have $(J-1)$ entries, and your resulting $w$ should have $(J-1)$ entries.

However, your "fix" gives you $J$ entries instead of $(J-1)$ entries.
That is $1$ off.
If it helps you to get the right answer, it means that later on you are also $1$ off.
So before you were probably calculating with an uninitialized variable.

Yes,you are right! :o

I looked again my code and realized that I didn't fix that $J$.
I have written the following in a function:
Code:
fun(b,J){
         for(j=0; j<J-1; j++)
		b[j]=f(X(j,J));	
         
 }

At the beginning I called the function fun(b,J-1) and that is wrong, since X is calculated in the function
Code:
X(j,J){
      x=(j+1)/J;
 }
Then I fixed it by calling the function by fun(b,J).
 
Last edited by a moderator:
Physics news on Phys.org
  • #32
mathmari said:
Yes,you are right! :o

I looked again my code and realized that I didn't fix that $J$.
I have written the following in a function, fun(b,J):
Code:
for(j=0; j<J-1; j++){
                x=(j+1)*h;
		b[j]=f(x);	
}

At the beginning I called the function fun(b,J-1) and in the function it was for(j=0; j<J; j++) and that is wrong.
Then I fixed it by calling the function by fun(b,J).

Aha!
 

Similar threads

  • · Replies 17 ·
Replies
17
Views
4K
Replies
9
Views
2K
Replies
5
Views
3K
  • · Replies 30 ·
2
Replies
30
Views
6K
Replies
0
Views
1K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 1 ·
Replies
1
Views
817
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 0 ·
Replies
0
Views
1K