MATLAB: The following error occurred converting from sym to double: DOUBLE cannot convert the input expression into a double array. Error in bending (line 12) B(i,1)=a;

differentiationdoublesymbolic

l=5; B=zeros(1,4); syms x; N1=1-(3*(x^2)/l^2)+(2*(x^3)/l^3); N2=x-(2*(x^2)/l)+((x^3)/l^2); N3=(3*(x^2)/l^2)-(2*(x^3)/l^3); N4=-((x^2)/l)+((x^3)/l^2); N=[N1 N2 N3 N4]; for i=1:4; a=diff(N(i,1),x); B(i,1)=a; end

Best Answer

Define B to be an array of sym objects before your for loop.
B = sym(zeros(4, 1));
You'll also need to change the reference to N(i, 1) inside the loop. As written N is 1-by-4 so you need N(1, i).
Related Question