MATLAB: I am trying to solve a system of nine equations and nine variables using the symbolic toolkit, and am getting an error message when trying to convert the solutions to a double array.

homeworkSymbolic Math Toolbox

This is the code I have written:
if true
% code


end
one=sym('cosd(45.4)*G1+G2=0');
two=sym('-G9-cosd(46.5)*G8=0');
three=sym('1107.14+sind(46.5)*G8=0');
four=sym('4000=G7+sind(46.5)*G5');
five=sym('G9=cosd(46.5)*G5+G6');
six=sym('cosd(46.5)*G8=G4');
seven=sym('-sind(46.5)*G8-G7=500');
eight=sym('G4+cosd(46.5)*G5-cosd(45.4)*G1=0');
nine=sym('-G3-sind(46.5)*G5-sind(45.4)*G1=1000');
[G1,G2,G3,G4,G5,G6,G7,G8,G9]=solve(one,two,three,four,five,six,seven,eight,nine)
fprintf(['G1=%.3f;\nG2=%.3f;\nG3=%.3f;\nG4=%.3f;\nG5=%.3f;\nG6=%.3f;'...
'\nG7=%.3f;\nG8=%.3f;\nG9=%.3f\n'],double(G1),double(G2),double(G3)...
,double(G4),double(G5),double(G6),double(G7),double(G8),double(G9))
And this is the error I recieve:
if true
% code
end
Error using symengine
DOUBLE cannot convert the input expression into a double array.
if true
% code
end
Error in sym/double (line 613)
Xstr = mupadmex('symobj::double', S.s, 0);

Best Answer

The symbolic toolbox does not define cosd() or sind()
syms G1 G2 G3 G4 G5 G6 G7 G8 G9
one = cosd(45.4)*G1+G2 == 0;
two = -G9-cosd(46.5)*G8 == 0;
three = 1107.14+sind(46.5)*G8 == 0;
four = 4000 == G7+sind(46.5)*G5;
five = G9 == cosd(46.5)*G5+G6;
six = cosd(46.5)*G8 == G4;
seven = -sind(46.5)*G8-G7 == 500;
eight = G4+cosd(46.5)*G5-cosd(45.4)*G1 == 0;
nine = -G3-sind(46.5)*G5-sind(45.4)*G1 == 1000;
[g1, g2, g3, g4, g5, g6, g7, g8, g9] = solve(one, two, three, four, five, six, seven, eight, nine);
fprintf(['G1=%.3f;\nG2=%.3f;\nG3=%.3f;\nG4=%.3f;\nG5=%.3f;\nG6=%.3f;'...
'\nG7=%.3f;\nG8=%.3f;\nG9=%.3f\n'], double(g1), double(g2), double(g3), ...
double(g4), double(g5), double(g6), double(g7), double(g8), double(g9))
Related Question