function [ J ] = J_springs( x )%Jacobian Matrix Jf
%df/dx(i) df/dx(i-1) df/dx(i+1)
%Initialization
x=1:20N=20K=zeros(N,1);b=zeros(N,1);J=zeros(N,1);for i = 1:N K(i) = (100+i-N/2); %N/cm
b(i) = (-10+0.1*(i-N/2)); %N/cm^3
endfor i = 2:N-2 J(i,i) = -(K(i,i)+K(i+1,i))+3*b(i,i)*(x(i,i)-x(i-1,i))^2+3*b(i+1,i)*(x(i+1,i)-x(i,i))^2; end%
for i = 2:N-1 J(i,i-1) = K(i,i-1)-3*b(i,i-1)*(x(i,i-1)-x(i-1,i-1))^2;end%for i = 1:N-2 J(i,i+1) = K(i+1,i+1)-3*b(i+1,i+1)*(x(i+1,i+1)-x(i,i+1))^2; end%
end
MATLAB: Hi, I’m new to Matlab. I keep getting Index exceeds matrix dimensions error. Maybe someone can help me with this.
jacobianmatrices
Best Answer