MHB Finite difference method-convergence

Click For Summary
The discussion centers around implementing the finite difference method for a fourth-order differential equation in C, specifically the equation y''' - q(x)y''(x) = f(x). The user seeks to understand the convergence rate and how to calculate J1 and J2 for error analysis, with a specific interest in how error changes with step size. The conversation reveals issues with the implementation, particularly regarding the accuracy of approximations Wj and Yj, and the need to verify the correctness of the function f. Ultimately, the user is troubleshooting numerical stability and accuracy in their program, aiming to ensure that the finite difference method yields reliable results.
  • #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:
Mathematics 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
3K
Replies
9
Views
2K
Replies
5
Views
3K
  • · Replies 30 ·
2
Replies
30
Views
6K
Replies
0
Views
820
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 1 ·
Replies
1
Views
507
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 0 ·
Replies
0
Views
1K