I declare the variables using sym or syms then i have an equation a+2*b=1; I want MATLAB to give me a=1-2*b; or alternatively b=(1-a)/2;
is there a way to do this?
Also, There maybe more than 2 variables Equation maybe linear or non-linear Equation can change at each iteration. Thanks
No products are associated with this question.
This is one way:
syms a b eqn = (a + 2*b == 1) v_a = solve(eqn, a) v_b = solve(eqn, b)
producing this output:
1 - 2*b
1/2 - a/2
I suggest you avoid expressions such as:
[a b] = solve(eqn, a, b)
even though it is valid syntax, because instead of solving the equation for ‘a’ and then solving it independently for ‘b’, it solves it for ‘a’ first and then solves the resulting equation for ‘b’ in terms of an introduced variable ‘z’. That produces a multi-line warning in red (that I will not reproduce here), and the results:
1 - 2*z
that does not make sense to me. I consider this to be a bug, and I would prefer it to be an option rather than the default, but that is not my decision.