How to convert 1x1 sym into numeric value in the workspace?

조회 수: 31 (최근 30일)
Luigi Stragapede
Luigi Stragapede 2020년 5월 9일
댓글: Star Strider 2021년 7월 18일
I need to solve this system of equations and I need to obtain the numerical value of all coefficient also in the workspace.
In order to solve this system I used:
sol = solve([eqn1, eqn2, eqn3, eqn4, eqn5, eqn6, eqn7, eqn8, eqn9, eqn10], [A1 B1 A2 B2 A3 B3 A4 B4 A5 B5 A6 B6 A7 B7 A8 B8 A9 B9 A10 B10]);
The results in the workspace are:
How I can obtain numeric values of the coefficients? I need to put them also in the workspace.
Which is the meaning of 1x1 sym? what is the problem?
Here there is the same code if you need to try on yourself:
syms A1 B1 A2 B2 A3 B3 A4 B4 A5 B5 A6 B6 A7 B7 A8 B8 A9 B9 A10 B10;
eqn1 = A1-B1==0;
eqn2 = A1*exp(2*3)+B1*exp(-2*3)==A2*exp(2*3)+B2*exp(-2*3);
eqn3 = A1*exp(2*3)-B1*exp(-2*3)==(1/2)*(A2*exp(2*3)+B2*exp(-2*3))+(180/2);
eqn4 = A2*exp(2*2)+B2*exp(-2*2)==A3*exp(2*2)+B3*exp(-2*2);
eqn5 = A2*exp(2*2)-B2*exp(-2*2)==(A3*exp(2*2)-B3*exp(-2*2))+(180/2);
eqn6 = A3*exp(2*3)+B3*exp(-2*3)==(4/(3^2*4^2*12*4*4i*10))*(A4*exp(4*3)-B4*exp(-4*3));
eqn7 = A3*exp(2*3)-B3*exp(-2*3)==(2/(3^2*4^2*12*4*4i*10))*(A4*exp(4*3)+B4*exp(-4*3));
eqn8 = A4*exp(4*4)+B4*exp(-4*4)==(12/2)*(A5*exp(5*4)+B5*exp(-5*4));
eqn9 = A4*exp(4*4)-B4*exp(-4*4)==(12/(2*2))*(A5*exp(5*4)-B5*exp(-5*4));
eqn10 = A5*exp(5*5)+B5*exp(-5*5)==0;
sol = solve([eqn1, eqn2, eqn3, eqn4, eqn5, eqn6, eqn7, eqn8, eqn9, eqn10], [A1 B1 A2 B2 A3 B3 A4 B4 A5 B5 A6 B6 A7 B7 A8 B8 A9 B9 A10 B10]);

채택된 답변

Star Strider
Star Strider 2020년 5월 9일
A ‘1 x 1 sym’ is a single scalar symbolic expression, while:
Q = sym('Q', [2 3])
creates a ‘2 x 3’ symbolic expression.
If you want the numeric value of ‘A1’ (or any of the others that do not contain symbolic variables — I did not check all of them to be certain that they do not — refer to them with respect to the ‘sol’ structure:
A1d = double(sol.A1)
producing:
A1d =
0.446183616140603
.

추가 답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 5월 9일
편집: KALYAN ACHARJYA 2020년 5월 9일
  댓글 수: 1
Luigi Stragapede
Luigi Stragapede 2020년 5월 9일
I tried to used double but it doesn't work:
for example:
A1=double(A1); but nothing

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by