Solving an Equation with given variables

2 ビュー (過去 30 日間)
Paul Marco
Paul Marco 2017 年 6 月 9 日
回答済み: Walter Roberson 2017 年 6 月 10 日
I'm learning matlab and trying to set up an code to solve an equation with given inputs, where those inputs might not be for the same variable every time. e.g. f = x + y sometimes you have x and y, other times you have f and x, etc.
Right now I'm just trying to get the solve function to work, I can worry about input prompts later.
clc
syms f x y
f = 5;
x=2;
f == x + y;
S = solve(f,y)
I'm getting a return of an empty matrix.
S =
Empty sym: 0-by-1
The tutorial tells me it's because the solution doesn't exist. Obviously the solution is y=3.
Thank you for your assistance!

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 6 月 10 日
f == x + y;
is not an assignment statement.
eqn = f == x + y;
S = solve(eqn, y)

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by