How to evaluate sym using certain known multiple values?

1 次查看(过去 30 天)
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.

采纳的回答

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

更多回答(1 个)

John D'Errico
John D'Errico 2023-12-31
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.

类别

Help CenterFile Exchange 中查找有关 Formula Manipulation and Simplification 的更多信息

标签

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by