MATLAB: Isolate a variable functionsymbolicsyms I can isolate one variable as an expression? example: 'x^2+2+x' em 'x = x^2 +2' remembering that they are symbolic objects. Thanks in advance. Best Answer If your input is x^2 + 2 + x then you cannot isolate x to one side of an equation, as your input is not an equation.If your input is implicitly x^2 + 2 + x = 0 then your example output of x = x^2 + 2 is incorrect: instead x = -x^2 - 2You cannot always isolate one variable -- not unless you are willing to make some restrictions on the form of the equation.If you have a polynomial as input, thenS = x^2+2+x;c = sym2poly(S);isolated_x = x * c(end-1) - S; Related SolutionsMATLAB: Solve a system of equations having variables as a arrays You need to define ‘x’ as a vector uisng the sym function. Then it works: syms x x = sym('x',[1 2]); % <— ADD THIS ASSIGNMENTeq1= x(1) + 3*x(2) == 7;eq2= x(1) + x(2) == 2;eq=[eq1,eq2];v=[x(1),x(2)];vs = solve(eq,v);X = [vs.x1, vs.x2]producing: X =[ -1/2, 5/2]No other changes in your code are necessary. MATLAB: How can you make an input to a symbolic variable equation = {'x^2 + x'};diff(str2sym(equation))ans = 2 x+1equation = {'x^2 + y'};eq = str2sym(equation);syms(symvar(eq))diff(str2sym(equation), x)ans = 2 x Related QuestionSimplifying symbolic expression in terms of other variablesHow to find the Elements of a Coefficient MatrixHow to isolate a letter in some equationHow to expose a symbol from an equation? I have Symbolic Math Toolbox, if it is necessary
Best Answer