Forward, Reverse finite difference question
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
%forward
function df1_forward = forward_first(f,x,h)
df1_forward = (f(x(2:end))-f(x(1:end-1)))/h;
end
function df2_forward = forward_second(f,x,h)
df2_forward = (f(x(3:end))-2*f(x(2:end-1))+f(x(1:end-2)))/h^2;
end
function df3_forward = forward_third(f,x,h)
df3_forward = (f(x(4:end))-3*f(x(3:end-1))+3*f(x(2:end-2))-f(x(1:end-3)))/h^3;
end
function df4_forward = forward_fourth(f,x,h)
df4_forward = (f(x(5:end))-4*f(x(4:end-1))+6*f(x(3:end-2))-4*f(x(2:end-3))+f(x(1:end-4)))/h^4;
end
%reverse
function df1_reverse = reverse_first(f,x,h)
df1_reverse = (f(x(2:end))-f(x(1:end-1)))/h;
end
function df2_reverse = reverse_second(f,x,h)
df2_reverse = (f(x(3:end))-2*f(x(2:end-1))+f(x(1:end-2)))/h^2;
end
function df3_reverse = reverse_third(f,x,h)
df3_reverse = (f(x(4:end))-3*f(x(3:end-1))+3*f(x(2:end-2))-f(x(1:end-3)))/h^3;
end
function df4_reverse = reverse_fourth(f,x,h)
df4_reverse = (f(x(5:end))-4*f(x(4:end-1))+6*f(x(3:end-2))-4*f(x(2:end-3))+f(x(1:end-4)))/h^4;
end
I made a forward and backward finite difference code, and the forward and backward codes come out the same. Is this correct?


0 comentarios
Respuesta aceptada
Más respuestas (1)
KALYAN ACHARJYA
el 15 de Dic. de 2024
In your code, you have written both forward and reverse functions identically, please check it again and make the reverse code.
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
