An empty sum result when using function solve

5 vues (au cours des 30 derniers jours)
ANDREW XU
ANDREW XU le 10 Déc 2015
Commenté : ANDREW XU le 12 Déc 2015
clear;
syms x y
a=[x y];
b=[1 1];
c=[1 -1];
dot(a,b)-1
dot(a,c)-2
[x1,y1]=solve('dot(a,b)-1','dot(a,c)-2')
[x2,y2]=solve('x+y-1','x-y-2')
why can't I get the results of x and y from the first line of writing the solve function, while there are results from the second line?

Réponse acceptée

Walter Roberson
Walter Roberson le 10 Déc 2015
[x1,y1] = solve(dot(a,b)-1,dot(a,c)-2)
When you pass a string into solve(), the string is interpreted strictly in terms of MuPAD calls. MuPAD does not have a function named dot(). In MuPAD, the dot product routine is named linalg::scalarProduct()
Also keep in mind that when you pass a string to solve() and the string refers to a variable that has been defined at the MATLAB level, then unless you somehow transfer the variable to MuPAD then MuPAD is not going to know about the value of the variable.
Basically the only time you should pass strings to solve() is as variable names or when you know you are writing a MuPAD expression that the interface to the Symbolic Toolbox does not provide an easy way to write. For example in MATLAB up to about R2011b, MATLAB did not recognize the "==" operator on symbolic expressions in any useful way, so it was necessary to pass in strings to solve() that used the MuPAD equivalent, the "=" operator
solve('x^2+y^2=9', 'x=2*y+5') %notice MuPAD syntax has been used!
solve('zeta(cos(x), 5) = besselJ(3,sin(x))') %uses MuPAD functions!
but otherwise do not pass in strings.
  1 commentaire
ANDREW XU
ANDREW XU le 12 Déc 2015
Thanks a lot, it finally works!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MuPAD dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by