An empty sum result when using function solve

조회 수: 2 (최근 30일)
ANDREW XU
ANDREW XU 2015년 12월 10일
댓글: ANDREW XU 2015년 12월 12일
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?

채택된 답변

Walter Roberson
Walter Roberson 2015년 12월 10일
[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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MuPAD에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by