MATLAB: Curvature of mode shape

curveture

Can you please help me how to write this code?
I have x=[…]
y=[….]
i=size(x)
and need to calculate r[…]=y(i+1)+y(i-1)-y(i)/h^2
h = x(i)-x(i-1)

Best Answer

Already you have written what you want and it should be bit placed properly. Let y be your array.
n = length(y) ;
r = zeros(n-2,1) ;
for i = 2:n-1
h = x(i)-x(i-1) ;
r(i) = (y(i+1)+y(i-1)-y(i))/h^2
end