Solve for specific variable - like Excel's solver

5 Ansichten (letzte 30 Tage)
Aaron Ashley
Aaron Ashley am 9 Feb. 2021
Kommentiert: Star Strider am 10 Feb. 2021
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{:});

Akzeptierte Antwort

Star Strider
Star Strider am 9 Feb. 2021
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 Kommentare
Aaron Ashley
Aaron Ashley am 10 Feb. 2021
Thanks! That resolved the issue.
Star Strider
Star Strider am 10 Feb. 2021
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by