MATLAB: Question about vpasolve to solve a nonlinear equation with mutliple variables

MATLABmultiple variablesnonlinear equationvpasolve

Hello everyone,
Recently I'm solving a nonlinear equation with mutliple variables. For example:
x=sym('a%d%d',[2,1]);
a=vpasolve(x.a11+tan(x.a12)==0,x,'random',true)
I know "vpasolve" can solve questions about multiple equations and variables. But I only have one equation, and the number of variables depends on the specific problem. So I want to find a more flexible codes. Brief, how can I solve a nonlinear equation with changeable number of variables?
Best,
Xiao

Best Answer

You have one equation, in more than one unknown. There is no solution for x. Or, said differently, there may generally be infinitely many solutions.
Had you asked to solve for one variable, as a function of the others, that you could do, well potentially so. It would depend on the actual equation. But VPASOLVE would not generally be the tool to solve the problem. VPASOLVE is a numerical tool, that works in high precision. You would just then use solve anyway.
For example:
syms x y
EQN = x+y == 0;
vpasolve(EQN,x)
ans =
-1.0*y
So for a trivial polynomial equation of low order, VPASOLVE did not have a hiccup. But, even for an almost as trivial one that is not trivially polynomial, we see:
EQN = sin(x+y) == 0;
vpasolve(EQN,x)
Error using mupadengine/feval (line 187)
Symbolic parameters not supported in nonpolynomial equations.
Error in sym/vpasolve (line 172)
sol = eng.feval('symobj::vpasolve',eqns,vars,X0);
solve(EQN,x)
ans =
-y
So you can use solve, at least in that case. Of course, not all problems have a solution. In your example I can do this:
a = solve(x(1)+tan(x(2))==0,x(1))
a =
-tan(a21)
Related Question