1D linear convection with C++
View Single Post
Mar21-11, 07:19 PM
I like Serena
Change the line that I marked in red.
The line that I marked in red should be changed to this:
/(nx-1); // mesh size
What was happening was that dx was being initialized to 0.0, which is not what you wanted. As you had it before, the expression on the right was 2/9, which is 0, due to integer division. That value was being promoted to 0.0 and stored in your dx variable.
I think this is not a problem:
nx is a double, making (nx-1) a double, making 2/(nx-1) a double.
Another problem however, is that u[n+1][i] is indexing u out-of-range, which will give unpredictable results.