Creating symbolic function with array for argument
古いコメントを表示
Hi,
I am trying to understand how to use mutli dimension array with symbolic function. I am not sure why I get an error for the symolic function when the input argument is two dimension.
x = sym ('x', [2 1]);
y = sym( 'y', [1 2]);
z = sym( 'z', [2 5]);
f(x,y,z)=(x(1,1)+y(1,1)+z(1,1));
if I change the variable to
x = sym ('x', [1 1]);
y = sym( 'y', [1 2]);
z = sym( 'z', [1 5]);
f(x,y,z)=(x(1,1)+y(1,1)+z(1,1));
it works fine, I am not sure I understand why
6 件のコメント
x = sym ('sh', [2 1]);
y = sym( 'ao', [1 2]);
z = sym( 'aa', [2 5]);
f=(x(1,1)+y(1,1)+z(1,1)) % The LHS of equation is creating problem since x, y, z are symbolic arrays !!
Benoit Cabot
2024 年 3 月 8 日
Do you mean something like this ?
x = sym ('sh');
y = sym( 'ao');
z = sym( 'aa');
f(x,y,z) = symfun(x + y + z,[x,y,z]) %
f(1,2,1)
The RHS of the below equation is already evaluated for specfic points in the symbolic arrays
f=(x(1,1)+y(1,1)+z(1,1));
symfun operates using scalars more efficiently. The function f has three independent variables, x y and z . So, the function needs inputs to three variables
x = sym ('x');
y = sym( 'y');
z = sym( 'z');
f(x,y,z)=symfun(x+y+z,[x,y,z])
X=[1 ; 1];
Y=[1 1];
Z=[1 2 3 4 5; 6 7 8 9 0];
f(X(1,1),Y(1,1),Z(1,1)) + f(X(2,1),Y(1,1),Z(1,1)) + f(X(1,1),Y(1,1),Z(1,1)) + f(X(1,1),Y(1,2),Z(1,1)) + ...
f(X(1,1),Y(1,1),Z(1,1)) + f(X(1,1),Y(1,1),Z(2,5))
Benoit Cabot
2024 年 3 月 8 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Common Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
