During my while loop my h value decreases like it is suppose to but the value is not being plugged back into my equation so I am not getting the values I should have. Plus I need this values put into a table. What can I do to my current code to have the new h value put back into my equation and the error calculated again? I also need to have all previous values plotted into a table. Also I need the original h plotted as well.
Here is my code:
%x-value%
x=0.5;
%define function%
f=inline('-0.1.*x.^4-0.15.*x.^3-0.5.*x.^2-.25.*x+1.2','x');
%calculated true value%
truevalue=-.9125;
h=1;
Central_Finite_Difference_Approximation=(f(x+h)-f(x-h))/2*h;
Relative_Error=abs((truevalue-Central_Finite_Difference_Approximation)/truevalue);
while 3.64*10^-10 < Relative_Error
h=h/10; x=0.5; Step_Size=h; t=table(Step_Size,Central_Finite_Difference_Approximation,Relative_Error);
disp(t)
end
This is my result:
Step_Size Central_Finite_Difference_Approximation Relative_Error _________ _______________________________________ ______________ 0.1 -1.2625 0.38356 Step_Size Central_Finite_Difference_Approximation Relative_Error _________ _______________________________________ ______________ 0.01 -1.2625 0.38356 Step_Size Central_Finite_Difference_Approximation Relative_Error _________ _______________________________________ ______________ 0.001 -1.2625 0.38356 Step_Size Central_Finite_Difference_Approximation Relative_Error _________ _______________________________________ ______________ 0.0001 -1.2625 0.38356 Step_Size Central_Finite_Difference_Approximation Relative_Error _________ _______________________________________ ______________ 1e-05 -1.2625 0.38356
Best Answer