How to evaluate sym using certain known multiple values?

1 visualización (últimos 30 días)
I have a 2*3 sym (named "A") as follows:
[ 1, 0, 0]
[-1/(2*(x1/(x2^2 - 10*cos(4*x3*pi) - 10*cos(4*x2*pi) + x3^2 + 21))^(1/2)), (x1*(2*x2 + 40*pi*sin(4*pi*x2)))/(2*(x1/(x2^2 - 10*cos(4*x3*pi) - 10*cos(4*x2*pi) + x3^2 + 21))^(1/2)*(x2^2 - 10*cos(4*pi*x3) - 10*cos(4*pi*x2) + x3^2 + 21)) - (2*x2 + 40*pi*sin(4*pi*x2))*((x1/(x2^2 - 10*cos(4*pi*x3) - 10*cos(4*pi*x2) + x3^2 + 21))^(1/2) - 1), (x1*(2*x3 + 40*pi*sin(4*pi*x3)))/(2*(x1/(x2^2 - 10*cos(4*x3*pi) - 10*cos(4*x2*pi) + x3^2 + 21))^(1/2)*(x2^2 - 10*cos(4*pi*x3) - 10*cos(4*pi*x2) + x3^2 + 21)) - (2*x3 + 40*pi*sin(4*pi*x3))*((x1/(x2^2 - 10*cos(4*pi*x3) - 10*cos(4*pi*x2) + x3^2 + 21))^(1/2) - 1)]
I want to evaluate this 2*3 sym at -
X=[0.394876, 0.963263, 0.173956]
where
x1=X(1);
x2=X(2);
x3=X(3);
How can I do this?
Note, I tried matlabFunction command. This causes certain problems in some certain scenarios. I do not want to use matlabFunction command.

Respuesta aceptada

Rounak Saha Niloy
Rounak Saha Niloy el 31 de Dic. de 2023
double(subs(A, [x1, x2, x3], X));
Could sort it out. The above code evaluates the sym at X.

Más respuestas (1)

John D'Errico
John D'Errico el 31 de Dic. de 2023
Easy peasy, though using matlabFunction here is not my recommendation.
syms('x',[1,3])
So x is a vector, with elements [x1,x2,x3].
A = [[ 1, 0, 0]
[-1/(2*(x1/(x2^2 - 10*cos(4*x3*pi) - 10*cos(4*x2*pi) + x3^2 + 21))^(1/2)), (x1*(2*x2 + 40*pi*sin(4*pi*x2)))/(2*(x1/(x2^2 - 10*cos(4*x3*pi) - 10*cos(4*x2*pi) + x3^2 + 21))^(1/2)*(x2^2 - 10*cos(4*pi*x3) - 10*cos(4*pi*x2) + x3^2 + 21)) - (2*x2 + 40*pi*sin(4*pi*x2))*((x1/(x2^2 - 10*cos(4*pi*x3) - 10*cos(4*pi*x2) + x3^2 + 21))^(1/2) - 1), (x1*(2*x3 + 40*pi*sin(4*pi*x3)))/(2*(x1/(x2^2 - 10*cos(4*x3*pi) - 10*cos(4*x2*pi) + x3^2 + 21))^(1/2)*(x2^2 - 10*cos(4*pi*x3) - 10*cos(4*pi*x2) + x3^2 + 21)) - (2*x3 + 40*pi*sin(4*pi*x3))*((x1/(x2^2 - 10*cos(4*pi*x3) - 10*cos(4*pi*x2) + x3^2 + 21))^(1/2) - 1)]];
Now you have X, with the values of x1,x2,x3.
X=[0.394876, 0.963263, 0.173956];
You can simply do this:
double(subs(A,x,X))
ans = 2×3
1.0000 0 0 -3.4478 -50.1285 95.5057
That stuffs the elements of X into x1,x2,x3 respectively. Then the call to double turns the result into numbers.

Categorías

Más información sobre Formula Manipulation and Simplification en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by