A symbolic implementation issue
이전 댓글 표시
Hello,
I need to define a system of symbolic functions for a set of state variables. I explain by the following example:
syms x y
syms mu(x,y) [2 1]
syms sigma(x,y) [2 2]
par=sym('par', [1 6]);
mu(x,y)=[par(1)*x+par(2)*y;par(3)*x+par(4)*y];
sigma(x,y)=[par(5) 0;0 par(6)];
Here, it wotks well. However, as you see in above the function mu(x) is a vector which serves as a bi-variate function for me. A rather unprofessional way to define mu(x) would be as follows
syms mu1(x,y) mu2(x,y)
mu1(x,y)=par(1)*x+par(2)*y;mu2(x,y)=par(3)*x+par(4)*y
Likewise, for the function sigma(x) I could define 4 sub-functions (which is not so beautiful). What I wish to do is to repeat the same trick I used for symbolic functions mu(x,y) and sigma(x,y) for the symbolic variables x and y. I mean to say the following
syms x [2 1]
syms mu(x) [2 1]
syms sigma(x) [2 2]
par=sym('par', [1 6]);
mu(x)=[par(1)*x(1)+par(2)*x(2);par(3)*x(1)+par(4)*x(2)];
sigma(x)=[par(5) 0;0 par(6)];
Unfortunately, MATLAB does not accept this.
I am wondering if thisa is possible?
Thanks,
Babak
채택된 답변
추가 답변 (1개)
I'm not fully sure I understand what your are looking for. However, if the goal is to create arrays which hold symbolic equations you can try the method below. μand σ are intialized as just symbolic expressions witouth dimmensions etc. Afterwards we can fill them in. Does this work for you?
syms x [2 1]
syms par [1 6]
syms mu sigma
% create mu
mu(x) = [par(1)*x(1)+par(2)*x(2); par(3)*x(1)+par(4)*x(2)]
% create sigma
sigma(x) = [par(5) 0; 0 par(6)]
댓글 수: 4
Just want to point out that mu and sigma don't need to be declared as sym objects, as they are immediately redefined as symfun objects
syms x [2 1]
syms par [1 6]
%syms mu sigma
% create mu
mu(x) = [par(1)*x(1)+par(2)*x(2); par(3)*x(1)+par(4)*x(2)]
% create sigma
sigma(x) = [par(5) 0; 0 par(6)]
whos mu sigma
Mohammad Shojaei Arani
2022년 12월 26일
Walter Roberson
2022년 12월 26일
gradient is not defined for a vector-valued function.
If you have a vector valued symbolic function then you first need to invoke the symbolic function on specific values (which might be symbolic variables.) This will return a symbolic array. You can then arrayfun gradient over the members of the array, with UniformOutput false. Then splice together the results along whatever dimension seems appropriate.
Insofar as mu(x) is a vector valued function, perhaps you mean to compute the jacobian?
syms x [2 1]
syms par [1 6]
mu(x) = [par(1)*x(1)+par(2)*x(2); par(3)*x(1)+par(4)*x(2)];
jacobian(mu,x)
카테고리
도움말 센터 및 File Exchange에서 Symbolic Variables, Expressions, Functions, and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
