Evaluate a vectorial symbolic matlab function through Matrices and vectors directly
1 view (last 30 days)
Show older comments
Hello everyone,
I'm actually working with the symbolic toolbox, and I want to evaluate a matlab symbolic function that depends on a matrix and a vector which the dimension changes in the general application.
However, when I want to evaluate the final result, the error message tells me that I have to pass on the members of the matrix and the vector, and it is exactly the thing that I want to avoid.
clear;close;clc;
Msym = sym('M', [8, 2], 'real');
vsym = sym('v', [2, 1], 'real');
q0sym = sym('q0', [8, 1], 'real');
qsym = Msym * vsym + q0sym;
q0 = [0; 0; 0; 1; 0; 0; 0; 1];
M = [0, 0; 0.0164, 0.0109; 0, 0; -0.0005, -0.0005; 0, 0; 0, 0.0553; 0, 0; 0, -0.0011];
v = [0; 0];
q = matlabFunction(qsym)
q_eval = double(q(q0, M, v))
Can anyone help me please to solve this probem ?
P.S: I have already succeeded to solve this problem using "subs", but it is taking long time when the size of Msym and vsym are great.
Thanks in advance.
0 Comments
Accepted Answer
Ameer Hamza
on 4 Dec 2020
The function handle is not being created in the way you want. Change the matlabFunction line to
q = matlabFunction(qsym, 'Vars', {q0sym, Msym, vsym})
1 Comment
More Answers (0)
See Also
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!