large symbolic matrix substitution

3 次查看(过去 30 天)
Hi,
I am trying to find a way to efficiently substitute a large symbolic Jacobian matrix with the corresponding numerical values, but all at once. As long as "subs" command becomes extremely slow and the PC becomes idle with no output, I am urgently looking for alternative faster ways. The problem with "matlabFunction" is that it accepts the elements of the "guess matrix" one by one and I don't know how to pass the numerical matrix values all at once to it.
As an example , if
R=sym('R',[1000 1])
RV=matlabFunction (R)
T=ones(1000,1)
then, how to pass "T" into "RV", as a whole?
Any other effective solutions are appreciated, as well. (MATLAB R2012b)
Thanks.

回答(1 个)

Star Strider
Star Strider 2014-10-5
I am not certain what you are actually doing, but this works for this example:
syms x y z
f(x,y,z) = 3*x*y + 5*x*z + 7*y*z + 13*x*z;
JF = jacobian(f, [x y z]);
MJF = matlabFunction(JF);
[VX,VY,VZ] = deal(ones(5,1));
JN = MJF(VX, VY, VZ);
The deal function simply takes the single (5x1) column vector created by the ones function and distributes it to [VX,VY,VZ] that are then arguments to the Jacobian anonymous function ‘MJF’.
One item of possible relevance is that ‘R’ should probably be a row vector rather than a column vector.
  2 个评论
Parmida Boroumand
Parmida Boroumand 2014-10-6
Thanks for your answer. It was good to learn about the "deal" function. However, it is not solving my problem :(
In the real program, I am currently trying to do the following,
Jac_Subs=subs(Jac,Def_Mat,Def_Mat0);
Eq_Subs=-subs(Equ,Def_Mat,Def_Mat0);
where "Jac" is the square Jacobian matrix, a function of the sybmolic elements of "Def_Mat" to be substituted by "Def_Mat0" and "Equ" is the symbolic vector of equations to be solved.
Since the program becomes idle at this point, I just put it in a loop as below which works for less numbers of the unknowns, but again freezes for the actual size.
Jac_Subs(i,j)=subs(Jac(i,j),Def_Mat,Def_Mat0);
Eq_Subs(i,1)=-subs(Equ(i,1),Def_Mat,Def_Mat0);
And application of the "fsolve" command to just grab the set of equations does not do a great job in this case, either! (Too slow)
Anything alternatives for "subs" to accept "Def_Mat" and "Def_Mat0", in this format and not element wise? Or any hints on the limitations associated with "subs"?
tnx.
Star Strider
Star Strider 2014-10-6
My pleasure!
It seems that your system is freezing because of the size of the matrices involved. I don’t understand what ‘Def_Mat’, ‘Def_Mat0’, and ‘Equ’ are. It might be best at this point to use matlabFunction to convert everything to numeric and go from there.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by