How to evaluate sym using certain known multiple values?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Rounak Saha Niloy
le 31 Déc 2023
Réponse apportée : John D'Errico
le 31 Déc 2023
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.
0 commentaires
Réponse acceptée
Plus de réponses (1)
John D'Errico
le 31 Déc 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))
That stuffs the elements of X into x1,x2,x3 respectively. Then the call to double turns the result into numbers.
0 commentaires
Voir également
Catégories
En savoir plus sur Formula Manipulation and Simplification dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!