Creating symbolic function with array for argument
Afficher commentaires plus anciens
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 commentaires
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
le 8 Mar 2024
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
le 8 Mar 2024
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Common Operations 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!
