Hello, i try to write a code about central difference. But something is wrong. My code is below. What is wrong?
function derivativecentral(numericalvalue, step, n) centraltable=[0 -1 0 1 0;0 1 -2 1 0;-1 2 0 -2 1;1 -4 6 -4 1]; x=numericalvalue-2*step: step:numericalvalue+2*step; m=2; if (n/2)==floor(n/2); m=1; coeff = centraltable(n,:); der=sum(coeff.*fonk(x)) / (m*step^n); display(der); endendfunction [f] = fonk(x) f=x*exp(x); end
At the end of code, i am writing derivativecentral(0,0.1,1)
But there is nothing.
Best Answer