Evaluate a vectorial symbolic matlab function through Matrices and vectors directly

조회 수: 1 (최근 30일)
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.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 12월 4일
The function handle is not being created in the way you want. Change the matlabFunction line to
q = matlabFunction(qsym, 'Vars', {q0sym, Msym, vsym})

추가 답변 (0개)

카테고리

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