Solve for specific variable - like Excel's solver

조회 수: 5 (최근 30일)
Aaron Ashley
Aaron Ashley 2021년 2월 9일
댓글: Star Strider 2021년 2월 10일
I would like to determine the value of a variable within a complex equation. For example, let's say my equation is y = mx + b. This is simplified but still useful. I know what y is, but I don't know what x is. I want to determine which value of x gives the known value of y. As another example, I am trying to tell MATLAB how to act like the Excel Solver add-in.
I have tried to follow various guides online and used simple equations as outlined below. I encounter the same error and I'm not sure what else I might try. How might I go about this process?
My example code and the corresponding error follows:
>> syms x;
t = solve('2*x+6==0', 'x');
Error using solve>getEqns (line 418)
List of equations must not be empty.
Error in solve (line 226)
[eqns,vars,options] = getEqns(varargin{:});

채택된 답변

Star Strider
Star Strider 2021년 2월 9일
The problem is with the single (or any other) quotes.
Remove them, and then:
syms x
t = solve(2*x+6==0, x)
produces:
t =
-3
.
  댓글 수: 2
Aaron Ashley
Aaron Ashley 2021년 2월 10일
Thanks! That resolved the issue.
Star Strider
Star Strider 2021년 2월 10일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numeric Solvers에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by