Unable to convert expression into double array.
194 views (last 30 days)
Show older comments
I have a 20 equations to solve i have already the symbolic funtioncs of M , E ,Izz and when i try to solve it appears in the command window( Unable to convert expression into double array.) This is the code
syms c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 M1(x) M2(x) M3(x) M4(x) M5(x) M6(x) M7(x) M8(x) M9(x) M10(x) T(x) E2(x) E3(x) E4(x) Izz3(x) Izz2(x) Izz4(x)
delta1 = int(int(M1/(E1*Izz1),x),x) + c1*x + c2;
delta2 = int(int(M2/(E2*Izz2),x),x) + c3*x + c4;
delta3 = int(int(M3/(E3*Izz3),x),x) + c5*x + c6;
delta4 = int(int(M4/(E4*Izz4),x),x) + c7*x + c8;
delta5 = int(int(M5/(E5*Izz5),x),x) + c9*x + c10;
delta6 = int(int(M6/(E6*Izz6),x),x) + c11*x + c12;
delta7 = int(int(M7/(E7*Izz7),x),x) + c13*x + c14;
delta8 = int(int(M8/(E8*Izz8),x),x) + c15*x + c16;
delta9 = int(int(M9/(E9*Izz9),x),x) + c17*x + c18;
delta10 = int(int(M10/(E10*Izz10),x),x) + c19*x + c20;
s1 = int(M1/(E1*Izz1),x) + c1;
s2 = int(M2/(E2*Izz2),x) + c3;
s3 = int(M3/(E3*Izz3),x) + c5;
s4 = int(M4/(E4*Izz4),x) + c7;
s5 = int(M5/(E5*Izz5),x) + c9;
s6 = int(M6/(E6*Izz6),x) + c11;
s7 = int(M7/(E7*Izz7),x) + c13;
s8 = int(M8/(E8*Izz8),x) + c15;
s9 = int(M9/(E9*Izz9),x) + c17;
s10 = int(M10/(E10*Izz10),x) + c19;
%For Turbine
eq1 = subs(delta1,x,K1) == subs(delta2,x,K1); eq2 = subs(s1,x,K1) == subs(s2,x,K1);
eq3 = subs(delta2,x,K2) == subs(delta3,x,K2); eq4 = subs(s2,x,K2) == subs(s3,x,K2);
eq5 = subs(delta3,x,K3) == subs(delta4,x,K3); eq6 = subs(s3,x,K3) == subs(s4,x,K3);
eq7 = subs(delta4,x,K4) == subs(delta5,x,K4); eq8 = subs(s4,x,K4) == subs(s5,x,K4);
eq9 = subs(delta5,x,K5) == subs(delta6,x,K5); eq10 = subs(s5,x,K5) == subs(s6,x,K5);
eq11 = subs(delta6,x,K6) == 0; eq12 = subs(s6,x,K6) == 0;
%For Generator
eq13 = subs(delta7,x,K7) == subs(delta8,x,K7); eq14 = subs(s7,x,K7) == subs(s8,x,K7);
eq15 = subs(delta8,x,K8) == subs(delta9,x,K8); eq16 = subs(s8,x,K8) == subs(s9,x,K8);
eq17 = subs(delta9,x,K9) == subs(delta10,x,K9); eq18 = subs(s9,x,K9) == subs(s10,x,K9);
eq19 = subs(delta7,x,K6) == 0; eq20 = subs(s7,x,K6) == 0;
sol1 = solve(eq1,eq2,eq3,eq4,eq5,eq6,eq7,eq8,eq9,eq10,eq11,eq12,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12);
sol2 = solve(eq13,eq14,eq15,eq16,eq17,eq18,eq19,eq20,c13,c14,c15,c16,c17,c18,c19,c20);
c1 = double(c1); c2 = double(sol1.c2); c3 = double(sol1.c3); c4 = double(sol1.c4); c5 = double(sol1.c5);
c6 = double(sol1.c6); c7 = double(sol1.c7); c8 = double(sol1.c8); c9 = double(sol1.c9); c10 = double(sol1.c10);
c11 = double(sol1.c11); c12 = double(sol1.c12); c13 = double(sol2.c13); c14 = double(sol2.c14); c15 = double(sol2.c15);
c16 = double(sol2.c16); c17 = double(sol2.c17); c18 = double(sol2.c18); c19 = double(sol2.c19); c20 = double(sol2.c20);
delta1 = int(int(M1/(E1*Izz1),x),x) + c1*x + c2
delta2 = int(int(M2/(E2*Izz2),x),x) + c3*x + c4;
delta3 = int(int(M3/(E3*Izz3),x),x) + c5*x + c6;
delta4 = int(int(M4/(E4*Izz4),x),x) + c7*x + c8;
delta5 = int(int(M5/(E5*Izz5),x),x) + c9*x + c10;
delta6 = int(int(M6/(E6*Izz6),x),x) + c11*x + c12;
delta7 = int(int(M7/(E7*Izz7),x),x) + c13*x + c14;
delta8 = int(int(M8/(E8*Izz8),x),x) + c15*x + c16;
delta9 = int(int(M9/(E9*Izz9),x),x) + c17*x + c18;
delta10 = int(int(M10/(E10*Izz10),x),x) + c19*x + c20;
what am i doing wrong?
2 Comments
Jesus Sanchez
on 8 Dec 2019
Did you check if the variables that you are trying to convert to double have a numerical value? Double does not work for letters, as far as I know, only with numbers. Here is the reference page, you can check the examples there: double.
I am specifically speaking about these lines:
c1 = double(c1); c2 = double(sol1.c2); c3 = double(sol1.c3); c4 = double(sol1.c4); c5 = double(sol1.c5);
c6 = double(sol1.c6); c7 = double(sol1.c7); c8 = double(sol1.c8); c9 = double(sol1.c9); c10 = double(sol1.c10);
c11 = double(sol1.c11); c12 = double(sol1.c12); c13 = double(sol2.c13); c14 = double(sol2.c14); c15 = double(sol2.c15);
c16 = double(sol2.c16); c17 = double(sol2.c17); c18 = double(sol2.c18); c19 = double(sol2.c19); c20 = double(sol2.c20);
Answers (1)
Jesus Sanchez
on 8 Dec 2019
Your problem is that you did not assign numerical values to your sym variables. Therefore, when you do double(sym_variable), matlab does not find anything that it can convert and throws an error.
To check this, execute this code section by section. Its the same as your code. You should see that when executing double(c1) for example, there is an error:
Error using symengine
Unable to convert expression into double array.
Error in sym/double (line 661)
Xstr = mupadmex('symobj::double', S.s, 0);
I could not execute the code, as M1 and E1 are not provided. Maybe the error jumps before the lines that I marked. If so, do the same comprobation, check if the symbolical variable has numerical value.
syms c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 M1(x) M2(x) M3(x) M4(x) M5(x) M6(x) M7(x) M8(x) M9(x) M10(x) T(x) E2(x) E3(x) E4(x) Izz3(x) Izz2(x) Izz4(x)
delta1 = int(int(M1/(E1*Izz1),x),x) + c1*x + c2;
delta2 = int(int(M2/(E2*Izz2),x),x) + c3*x + c4;
delta3 = int(int(M3/(E3*Izz3),x),x) + c5*x + c6;
delta4 = int(int(M4/(E4*Izz4),x),x) + c7*x + c8;
delta5 = int(int(M5/(E5*Izz5),x),x) + c9*x + c10;
delta6 = int(int(M6/(E6*Izz6),x),x) + c11*x + c12;
delta7 = int(int(M7/(E7*Izz7),x),x) + c13*x + c14;
delta8 = int(int(M8/(E8*Izz8),x),x) + c15*x + c16;
delta9 = int(int(M9/(E9*Izz9),x),x) + c17*x + c18;
delta10 = int(int(M10/(E10*Izz10),x),x) + c19*x + c20;
s1 = int(M1/(E1*Izz1),x) + c1;
s2 = int(M2/(E2*Izz2),x) + c3;
s3 = int(M3/(E3*Izz3),x) + c5;
s4 = int(M4/(E4*Izz4),x) + c7;
s5 = int(M5/(E5*Izz5),x) + c9;
s6 = int(M6/(E6*Izz6),x) + c11;
s7 = int(M7/(E7*Izz7),x) + c13;
s8 = int(M8/(E8*Izz8),x) + c15;
s9 = int(M9/(E9*Izz9),x) + c17;
s10 = int(M10/(E10*Izz10),x) + c19;
%% For Turbine
eq1 = subs(delta1,x,K1) == subs(delta2,x,K1); eq2 = subs(s1,x,K1) == subs(s2,x,K1);
eq3 = subs(delta2,x,K2) == subs(delta3,x,K2); eq4 = subs(s2,x,K2) == subs(s3,x,K2);
eq5 = subs(delta3,x,K3) == subs(delta4,x,K3); eq6 = subs(s3,x,K3) == subs(s4,x,K3);
eq7 = subs(delta4,x,K4) == subs(delta5,x,K4); eq8 = subs(s4,x,K4) == subs(s5,x,K4);
eq9 = subs(delta5,x,K5) == subs(delta6,x,K5); eq10 = subs(s5,x,K5) == subs(s6,x,K5);
eq11 = subs(delta6,x,K6) == 0; eq12 = subs(s6,x,K6) == 0;
%% For Generator
eq13 = subs(delta7,x,K7) == subs(delta8,x,K7); eq14 = subs(s7,x,K7) == subs(s8,x,K7);
eq15 = subs(delta8,x,K8) == subs(delta9,x,K8); eq16 = subs(s8,x,K8) == subs(s9,x,K8);
eq17 = subs(delta9,x,K9) == subs(delta10,x,K9); eq18 = subs(s9,x,K9) == subs(s10,x,K9);
eq19 = subs(delta7,x,K6) == 0; eq20 = subs(s7,x,K6) == 0;
sol1 = solve(eq1,eq2,eq3,eq4,eq5,eq6,eq7,eq8,eq9,eq10,eq11,eq12,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12);
sol2 = solve(eq13,eq14,eq15,eq16,eq17,eq18,eq19,eq20,c13,c14,c15,c16,c17,c18,c19,c20);
%% PROBLEMATIC section
% Check if double(sym_variable) of all the variables here present gives this error. There should be one without numerical value
c1 = double(c1); c2 = double(sol1.c2); c3 = double(sol1.c3); c4 = double(sol1.c4); c5 = double(sol1.c5);
c6 = double(sol1.c6); c7 = double(sol1.c7); c8 = double(sol1.c8); c9 = double(sol1.c9); c10 = double(sol1.c10);
c11 = double(sol1.c11); c12 = double(sol1.c12); c13 = double(sol2.c13); c14 = double(sol2.c14); c15 = double(sol2.c15);
c16 = double(sol2.c16); c17 = double(sol2.c17); c18 = double(sol2.c18); c19 = double(sol2.c19); c20 = double(sol2.c20);
%% Continues
delta1 = int(int(M1/(E1*Izz1),x),x) + c1*x + c2
delta2 = int(int(M2/(E2*Izz2),x),x) + c3*x + c4;
delta3 = int(int(M3/(E3*Izz3),x),x) + c5*x + c6;
delta4 = int(int(M4/(E4*Izz4),x),x) + c7*x + c8;
delta5 = int(int(M5/(E5*Izz5),x),x) + c9*x + c10;
delta6 = int(int(M6/(E6*Izz6),x),x) + c11*x + c12;
delta7 = int(int(M7/(E7*Izz7),x),x) + c13*x + c14;
delta8 = int(int(M8/(E8*Izz8),x),x) + c15*x + c16;
delta9 = int(int(M9/(E9*Izz9),x),x) + c17*x + c18;
delta10 = int(int(M10/(E10*Izz10),x),x) + c19*x + c20;
2 Comments
Jesus Sanchez
on 8 Dec 2019
As a way to solve this... If you are not interested in the numerical value, why do you use int() and double() along the whole code? You should think about what you want exactly from your equations. I would not use int() and double() until I have the final results, as symbolic operations are more precise.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!