- #1
Kanashii
- 9
- 0
Thread moved from the technical forums, so no Homework Help Template is shown.
Homework Statement
Develop aprogram that will determine the second derivative of pi(16 x^2 - y^4) at y=2 with step sizes of 0.1, 0.01, 0.001…. until the absolute error (numerical-analytical) converges to 0.00001. Use the 2nd order Central Difference Formula.
User Input: y, tolerance
Output: h, second derivative, error
Homework Equations
[f(x+h) - 2f(x) + f(x-h)]/h^2
The Attempt at a Solution
Code:
do
{
n[0]= h;
n[i+1]=n/10;
f= function (y,n);
error[0]= error_function(true_value,f);
error[i+1]= error_function(f,f[i-1]);
printf("%lf %lf %lf\n",n,f,error);
i++;
}
while (error > tolerance || error != tolerance);
When I input 0.00001 (tolerance) and 2 (y) into the program I created, the program crashes but it got the values of h, f`` right and also some values for the error. I do know what to change.
Thank you.
Output:
h ----------------------------f``----------------------------error
0.100000--------------- -50.328314 --------------- 0.062832
0.010000-------------- -50.266111 --------------- 50.328314
0.001000--------------- -50.265489 --------------- 0.062204
0.000100--------------- -50.265481--------------- 0.000622
0.000010--------------- -50.265498--------------- 0.000007
0.000001--------------- -50.249582--------------- 0.000017
0.000000--------------- -54.001248--------------- 0.015916
0.000000--------------- -284.217094--------------- 3.751666
0.000000--------------- 0.000000--------------- 230.215846
This table would also go on and the values do not make any sense.
Last edited: