An empty sum result when using function solve

6 views (last 30 days)
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?

Accepted Answer

Walter Roberson
Walter Roberson on 10 Dec 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.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!