필터 지우기
필터 지우기

Solve Function - Having Difficulties

조회 수: 5 (최근 30일)
SJ Won
SJ Won 2019년 7월 4일
답변: Vaibhav Tomar 2019년 7월 4일
I'm having trouble using the solve function and I don't understand the problem. I looked at other posts + documentation but I still don't see it.
>> x = solve('x+4==2',x)
Error using solve>getEqns (line 418)
List of equations must not be empty.
Error in solve (line 226)
[eqns,vars,options] = getEqns(varargin{:});
This is the input I entered and the error I'm receiving.

채택된 답변

Stephan
Stephan 2019년 7월 4일
syms x
xsol = solve(str2sym('x+4==2'),x)
  댓글 수: 1
SJ Won
SJ Won 2019년 7월 4일
What's the reason people use quotes for the mathematical expression? Isn't it easier just using x+4==2 ?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Vaibhav Tomar
Vaibhav Tomar 2019년 7월 4일
Quotes are necessary as it's a string.
You need to use str2sym
str2sym(symstr) evaluates symstr where symstr is a string representing a symbolic expression. Enter symbolic expressions as strings only when reading expressions from text files or when specifying numbers exactly. Otherwise, do not use strings for symbolic input.
Use:
x=sym('x')
solx= solve(str2sym('x+4==2'),x)

카테고리

Help CenterFile Exchange에서 Food Sciences에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by