How to avoid syms in Simulink

2 次查看(过去 30 天)
Pu
Pu 2014-12-1
I need to solve the following 27 equations using fsolve in Simulink for each time step. So I cannot wait until it is exported to Matlab Workspace. But Matlab Function Blocks in Simulink cannot handle the syms. Is there any way to avoid it. Below is the function in my Matlab Function Block in Simulink. Thank you so much!
A = sym('A', [3 9]);
Coor=sym('B',[27,1]);
%Lower Octahedral
Coor(1)=transpose(A(:,4)-A(:,3))*(A(:,4)-A(:,3))-l^2;
Coor(2)=transpose(A(:,4)-A(:,1))*(A(:,4)-A(:,1))-l^2;
Coor(3)=transpose(A(:,4)-A(:,5))*(A(:,4)-A(:,5))-qt(1)^2;
Coor(4)=transpose(A(:,5)-A(:,1))*(A(:,5)-A(:,1))-l^2;
Coor(5)=transpose(A(:,5)-A(:,2))*(A(:,5)-A(:,2))-l^2;
Coor(6)=transpose(A(:,5)-A(:,6))*(A(:,5)-A(:,6))-qt(2)^2;
Coor(7)=transpose(A(:,6)-A(:,3))*(A(:,6)-A(:,3))-l^2;
Coor(8)=transpose(A(:,6)-A(:,2))*(A(:,6)-A(:,2))-l^2;
Coor(9)=transpose(A(:,6)-A(:,4))*(A(:,6)-A(:,4))-qt(3)^2;
%Upper Octahedral
Coor(10)=transpose(A(:,7)-A(:,4))*(A(:,7)-A(:,4))-l^2;
Coor(11)=transpose(A(:,7)-A(:,5))*(A(:,7)-A(:,5))-l^2;
Coor(12)=transpose(A(:,7)-A(:,8))*(A(:,7)-A(:,8))-qt(4)^2;
Coor(13)=transpose(A(:,8)-A(:,5))*(A(:,8)-A(:,5))-l^2;
Coor(14)=transpose(A(:,8)-A(:,6))*(A(:,8)-A(:,6))-l^2;
Coor(15)=transpose(A(:,8)-A(:,9))*(A(:,8)-A(:,9))-qt(5)^2;
Coor(16)=transpose(A(:,9)-A(:,6))*(A(:,9)-A(:,6))-l^2;
Coor(17)=transpose(A(:,9)-A(:,4))*(A(:,9)-A(:,4))-l^2;
Coor(18)=transpose(A(:,9)-A(:,7))*(A(:,9)-A(:,7))-qt(6)^2;
%r1 r2 & r3 are known
Coor(19)=A(1,1)-sqrt(3)*l/4;
Coor(20)=A(2,1);
Coor(21)=A(3,1);
Coor(22)=A(1,2)+A(1,1);
Coor(23)=A(2,2)-l/2;
Coor(24)=A(3,2);
Coor(25)=A(1,3)-A(1,2);
Coor(26)=A(2,3)+l/2;
Coor(27)=A(3,2);
%Use fsolve to solve the system based on current value of q
[result, fval, exit, output]=fsolve(Coor,guess);

回答(1 个)

Sean de Wolski
Sean de Wolski 2014-12-1
Since you're not generating code from it, you could use the "Interpretted MATLAB Function Block" which should allow for the use of syms.

Community Treasure Hunt

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

Start Hunting!

Translated by