How do i transfer big symbolic equations into Simulink

Hello everyone,
I am trying to solve the dynamics of a serial manipulator with 6DOF, and I want to transfer the result of an m file (vector of symbolic Torques) into a Simulink block and replace the symbolic variables with a vector of input to have the final numeric result as an output of the block.
I tried a Matlab function block but it does not support symbolic variables.
I tried to call the function as an extrinsic function but Simulink crashes every time I run it.
"from workspace" and "from m file" blocks are not what I need since I have an input to the block.
Any suggestions?
Thanks in advance.

댓글 수: 3

Hello,
I did the following: I created a sym variable
s = sym(3)
and tried to assign its value to a constant block in Simulink: If the constant value is simply chosen to be "s", the following error occurs:
"Invalid setting in 'untitled/Constant' for parameter 'Value'",
but when I tried "double(s)" as constant value, it worked fine and a Display block connected to the Constant block showed the correct value of 3 in the simulation.
I hope this might help you. If not, could you please describe your problem more detailed?
Kind regards, Stefan
hello Stefan,
I cannot use a constant block because it only has an output, no input.
I have this huge symbolic vector, I want to put it in a simulink block with an input and output, so that the input replaces all the symbols in the vector and displays a numeric one in the output.
let's say I have the following:
syms q1
syms q2
syms dq1
syms dq2
T=[cos(q1)+sin(q2)*dq1 ; son(q2)*dq2]
I want symbolic T to be in a block and the vector [q1;q2;dq1;dq2] to be an input to this block. matlab function would do it but it doesn't support symbols.
I also can't not use symbols because I have some derivations in the code.
I tried to copy the massive symbolic T vector in a matlab function but it's so big that simulink crashes every time I run it.
Hello sed, I have same problem,can you explain how you fixed it?

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

 채택된 답변

Ced
Ced 2016년 4월 19일
What do you mean by "matlab function does not support symbols"? Maybe I misunderstood your problem, but there is a function called matlabFunction, and it is specifically made to take symbolic expressions and turn them into "numerical functions".
Here is a small example for a 3DOF robot arm:
% Given: symbolic EoM dx = f(....)
syms q1 q2 q3 dq1 dq2 dq3 T1 T2 T3 real
q = [q1 q2 q3]'; % generalized coordinates
dq = [dq1 dq2 dq3]'; % derivative of generalized coordinates
T = [T1 T2 T3]'; % torque vector
% ... HERE: computation of EoM, returning symbolic dx = f(q,dq,T)
% now generate function
matlabFunction(dx,'file','f_dyn','vars',{[q;dq],T});
This will generate a file f_dyn.m with function
function dx = f_dyn(in1,in2)
where in1 = [ q ; dq ] and in2 = T

댓글 수: 9

hello, thank you for your answer. it works for most of the equations, but mine results in a massive vector, so when I tried to generate the matlabFunction it took such a long time (more than an hour) that I had to stop it.
any alternatives?
hello again,
I am still struggling to make it work but I got the idea (it took a long time to generate the function but it worked), I just was not very familiar with the use of a matlabfunction.
thank you for your help.
Great, thanks for the update.
Hello I faced same problem I have 5*5 matrices and I should take partial derivative of this matrices, and take the derivative of matrices in m file, now I dont know how should send the data (5*5 symbolic matrix) from m file to simulink.. can any one help me!
matlabFunction() and be sure to use 'file' and 'optimize', false
Hello roberson, Many thanks, i have a question,I try to converts the symbolic function in mfile with matlabFunction. Now how i can use this function in simulink? ( this function is one input of simulink model)
Use a MATLAB Function Block and call the function from that.
As usual it is best to pre-allocate the space for the outputs before calling the file.
Hello Every one.. I do this method and use matlab function block to call matlabFunction and run simulink but one error shows “ output argument ‘matrix name’ is not assigned on some execution paths. What should I do and write in this block to fixed this error?
Please show the code for the function that reports that erroy

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Simulink Coder에 대해 자세히 알아보기

질문:

Sed
2016년 4월 18일

댓글:

2022년 6월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by