force matlab to display its symbolic calculations using indexed varaiables
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
hosein Javan
le 11 Jan 2017
Commenté : Walter Roberson
le 12 Jan 2017
hello. I'm looking for a way to make matlab display the result of its output by showing the variables with their index, while doing symbolic calculations. for example in this code I want it to display x(1) instead of x1.
x=sym('x',[1 2])
y=x(1)*x(2)
e=diff(y,x(2))
now here's matlab results:
ans=
x1
what matlab did here, was to show what's contained in x(1) which is x1. the reason why I'm trying to do this, is that I need these results to create a function whose input is an indexed variable to use with fsolve because this function requires x(1), x(2) and not x1, x2. I know it is possible using strings and eval function but I need a better way.
0 commentaires
Réponse acceptée
Walter Roberson
le 12 Jan 2017
x = sym('x',[1 2])
y = x(2)^2 + sin(x(1)*x(2));
e = diff(y, x(2))
f = matlabFunction(y, 'vars', {x});
fsolve(f, rand(1,2))
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical 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!