필터 지우기
필터 지우기

How to evaluate sym using certain known multiple values?

조회 수: 3 (최근 30일)
Rounak Saha Niloy
Rounak Saha Niloy 2023년 12월 31일
답변: John D'Errico 2023년 12월 31일
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