How to simply rearrange a symbolic equation to get an expression for one variable in terms of others

71 ビュー (過去 30 日間)
I'm building differential equations symbolically and ran into an error when doing a simple re-arranging of an equation.
For example, I am able to rearrange an equation with a symbolic variable x:
syms x a
eqn1 = x == a + x/2;
% Re-arrange to get an expression for x
solve(eqn1, x)
ans =
2*a
But when x(t) is time-varying, solve does something else:
syms x(t) a
eqn1 = x(t) == a + x(t)/2;
% Re-arrange to get an expression for x(t)
solve(eqn1, x(t))
Warning: Unable to find explicit solution. For options, see help.
> In sym/solve (line 317)
ans =
struct with fields:
a: [0×1 sym]
t: [0×1 sym]
I'm not sure what it's trying to do. All I want is to re-arrange the expression!

採用された回答

Paul
Paul 2023 年 1 月 29 日
Not sure about solve, but isolate seems to work
syms x(t) a
eqn1 = x(t) == a + x(t)/2;
isolate(eqn1,x(t))
ans = 
  3 件のコメント
Bill Tubbs
Bill Tubbs 2023 年 1 月 29 日
That's exactly what I wanted. "isolate" is the right word!
Paul
Paul 2025 年 10 月 4 日 14:25
As of R2025A, solve can solve equations for symbolic functions and derivatives:
syms x(t) a
eqn1 = x(t) == a + x(t)/2;
solve(eqn1,x(t))
ans = 
eqn1 = x(t) == a + diff(x(t),t,2)/2;
solve(eqn1,diff(x(t),t,2))
ans = 

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by