Is it possible to use 'solve' on a vector of functions?
Afficher commentaires plus anciens
Is it possible to use 'solve' function on a column/row vector of functions where each row/column is a function of just one variable?
syms t
funcVec = [3*t+2; 5t-3]
solve(funcVec)
For example, running the above lines of code should give me a vector
[-2/3; 3/5].
Réponses (1)
Walter Roberson
le 7 Nov 2012
No.
You can use
arrayfun(@solve, funcVec)
Or you can use the symbolic map() function. Note that map() is not exposed at the MATLAB level, so you would need evalin() or feval()
8 commentaires
Harshvardhan
le 7 Nov 2012
Modifié(e) : Harshvardhan
le 7 Nov 2012
Walter Roberson
le 7 Nov 2012
I do not have the symbolic toolbox to test with.
Try
arrayfun(@solve, funcVec, 'Uniform', 0)
and then cell2mat() the result.
Harshvardhan
le 7 Nov 2012
Modifié(e) : Harshvardhan
le 7 Nov 2012
Walter Roberson
le 7 Nov 2012
arrayfun( @(A, B, C) solve(subs(A, B, C)), 'Uniform', 0)
Harshvardhan
le 8 Nov 2012
Walter Roberson
le 8 Nov 2012
boxCOM = arrayfun( @(k) double(subs(line(k,:), t, solve(subs(planefunction2(k), P(k,:), line(k,:))))), 1:size(BOX,1), 'Uniform', 0);
boxCOM = cell2mat(boxCOM);
If it looks almost like your existing code, it should. arrayfun() has no magic to it: it just implements a "for loop" with a different syntax.
Harshvardhan
le 8 Nov 2012
Walter Roberson
le 8 Nov 2012
Yup. You would probably get better speed by evalin(symengine, ...) or feval(symengine, ...) some code that did the work for you all at the MuPAD level, such as by using MuPAD's map() . At the very least that would remove the overhead of talking to the symbolic engine for each operation.
Catégories
En savoir plus sur Utilities for the Solver dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!