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

129 vues (au cours des 30 derniers jours)
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!

Réponse acceptée

Paul
Paul le 29 Jan 2023
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 = 
  2 commentaires
Walter Roberson
Walter Roberson le 29 Jan 2023
This is probably the easiest route.
solve() is not able to solve for anything other than variables, so the approach with solve() would have to be to subs() a variable for the function, solve for the variable, and then if needed subs() back.
Bill Tubbs
Bill Tubbs le 29 Jan 2023
That's exactly what I wanted. "isolate" is the right word!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Formula Manipulation and Simplification dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by