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})
  1 件のコメント
Ameer Hamza
Ameer Hamza 2020 年 12 月 4 日
The variables are not attached. Can you attach them in a .mat file?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by