Filter löschen
Filter löschen

An empty sum result when using function solve

1 Ansicht (letzte 30 Tage)
ANDREW XU
ANDREW XU am 10 Dez. 2015
Kommentiert: ANDREW XU am 12 Dez. 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?

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 10 Dez. 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.

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with MuPAD finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by