Unable to find explicit solution on vector equation with solve

Hello !
I'm trying to solve static mechanics equations, hence implying vectors.
I tried with a simple case but Matlab is unable to find an explicit solution, though it should be solvable. It seems to me as if there is an error in the code preventing Matlab to properly spot the unknowns (which are vector components).
Here's a minimal code example, with a couple of tries with solve :
syms g mS fS real positive
syms vR_S_1 vR_S_2 vR_S_3 real
vP_S = [0; 0; -mS * g];
vR_S = [vR_S_1; vR_S_2; vR_S_3];
S1 = solve([vP_S + vR_S == zeros(3, 1); vR_S(2)^2 == vR_S(3)^2 * fS^2 - vR_S(1)^2]', [vR_S(3), vR_S(1)])
S2 = solve([vP_S + vR_S == zeros(3, 1); vR_S_2^2 == vR_S_3^2 * fS^2 - vR_S_1^2]', [vR_S_3, vR_S_1])
S3 = solve(subs([vP_S + vR_S == zeros(3, 1); vR_S_2^2 == vR_S_3^2 * fS^2 - vR_S_1^2])', [vR_S_3, vR_S_1])
Any clue about what's going on ?
Many thanks in advance !

Respuestas (3)

Walter Roberson
Walter Roberson hace alrededor de 13 horas
Editada: Walter Roberson hace alrededor de 13 horas
S1 = solve([vP_S + vR_S == zeros(3, 1); vR_S(2)^2 == vR_S(3)^2 * fS^2 - vR_S(1)^2]', [vR_S(3), vR_S(1)])
You are trying to solve 4 equations for two variables. Most of the time that is going to fail.

1 comentario

By the way, the ' operator is the complex conjugate operator, not simply the transpose operator which is .' . When you use it the way you are using it, you introduce extraneous solutions.
If you solve vP_S + vR_S == zeros(3, 1) for vR_S then several components come out as zero

Iniciar sesión para comentar.

Umar
Umar hace alrededor de 8 horas
Editada: Walter Roberson hace alrededor de 5 horas
Hi @Yanncha,
I took a close look at your code and identified everything that's going wrong — there are actually a few layered issues, some are MATLAB-specific quirks and one may be a deeper conceptual problem with the constraint equation itself.
Issue 1 Passing indexed vector elements as unknowns to solve() (S1)
In your first attempt, you pass vR_S(3) and vR_S(1) as the unknowns argument to solve(). Even though these resolve to the correct symbolic variables, MATLAB's solve() prefers to receive named scalar syms directly — the kind you declared with syms. Passing indexed vector elements can confuse the solver's internal variable detection. Your S2 attempt correctly switches to the named scalars vR_S_3 and vR_S_1, which is the right approach.
Issue 2 The conjugate transpose operator (') on an equation array
All three of your attempts apply the ' operator to the equation array. In MATLAB, ' is the Hermitian (conjugate) transpose, not the plain transpose. For symbolic equations it usually doesn't cause a visible error, but it is bad practice and can behave unexpectedly depending on MATLAB version. If you need to reshape the array, use .' (plain transpose) instead, or better yet just remove the transpose entirely — solve() handles both row and column vectors of equations without issue.
Issue 3 Leaving vR_S_2 undeclared as either an unknown or a known value (most likely cause of failure)
This is the main reason MATLAB is silently failing. You have 4 equations and ask solve() to find only 2 unknowns (vR_S_1 and vR_S_3). But vR_S_2 appears in the equations and is not declared as a known parameter — it is still a free symbolic variable. MATLAB's solver sees 3 free unknowns but is only told to solve for 2, and rather than internally eliminating vR_S_2, it tends to give up and return an empty result. The fix is to either solve for all three vR_S components at once, or manually substitute the value of vR_S_2 first before calling solve() on the remaining equation.
Issue 4 S3's bare subs() call does nothing
In your third attempt, you write subs([...equations...]). Calling subs() with only one argument and no substitution pairs is a no-op — it returns the input unchanged. So S3 is identical in behavior to S2 and is not actually testing anything different. This is worth knowing so you don't spend time treating S3 as a separate diagnostic.
Issue 5 Possible physical inconsistency in the constraint (important)
After fixing all the MATLAB issues, if you substitute the force balance solution
(vR_S_1 = 0, vR_S_2 = 0, vR_S_3 = mS*g) into the constraint equation, it
reduces to:
0 = (mS * g)^2 * fS^2
Since mS, g, and fS are all declared as real positive, this expression can never equal zero. That means the constraint as written is physically inconsistent with the force balance — they cannot be simultaneously satisfied for any nonzero mass or friction coefficient. MATLAB is not wrong to return no solution; there may genuinely be no solution. I'd recommend double-checking whether the constraint equation correctly models your physical scenario (for example, whether it should be an inequality instead of an equality, or whether the signs are correct).
Recommended approach
Rather than fighting solve() with all four equations at once, break it into steps:
Step 1 — The force balance gives you explicit values directly:
vR_S_1 = 0, vR_S_2 = 0, vR_S_3 = mS * g
Step 2 — Substitute these into the constraint separately and check whether the constraint is satisfied, or what condition on your parameters it implies.
This avoids all the solver ambiguity and also makes the physics much clearer at each step.
Hope this helps get you unstuck.

2 comentarios

They did
syms vR_S_1 vR_S_2 vR_S_3 real
vR_S = [vR_S_1; vR_S_2; vR_S_3];
This results in vR_S(1) being vR_S_1 and vR_S(2) being vR_S_2 and vR_S(3) being vR_S_3 .
If you compare
solve(EQNS, [vR_S(3), vR_S(1)])
to
solve(EQNS, [vR_S_3, vR_S_1])
you will find that they go through the same symbol resolution and what will get passed in each case is (for example) [#object('sym', '__ans_4321'), #object('sym', '__ans_176')]
There is absolutely no difference (other than minor efficiency) between passing in [vR_S(3), vR_S(1)] and passing in [vR_S_3, vR_S_1] .
There would be a difference if the call had instead been
solve(EQNS, 'vR_S_3', 'vR_S_1')
but that difference would not be important.
Umar
Umar hace alrededor de 4 horas
Movida: Walter Roberson hace alrededor de 3 horas
You're absolutely right Walter, thank you for the correction. I was wrong on Issue 1 — since vR_S is constructed directly from named syms, vR_S(1) simply retrieves the same underlying symbolic object as vR_S_1, so there is no difference between the two forms when passed to solve(). The MathWorks documentation confirms solve() accepts any symbolic vector or list of variables without distinction. I should not have listed that as a contributing factor — the real issues remain the over-constrained system, the free vR_S_2 variable, and the potential physical inconsistency in the constraint.

Iniciar sesión para comentar.

Umar
Umar hace alrededor de 4 horas
You're absolutely right Walter, thank you for the correction. I was wrong on Issue 1 — since vR_S is constructed directly from named syms, vR_S(1) simply retrieves the same underlying symbolic object as vR_S_1, so there is no difference between the two forms when passed to solve(). The MathWorks documentation confirms solve() accepts any symbolic vector or list of variables without distinction. I should not have listed that as a contributing factor — the real issues remain the over-constrained system, the free vR_S_2 variable, and the potential physical inconsistency in the constraint.

Categorías

Más información sobre Symbolic Math Toolbox en Centro de ayuda y File Exchange.

Productos

Versión

R2025b

Preguntada:

hace alrededor de 14 horas

Movida:

hace alrededor de 3 horas

Community Treasure Hunt

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

Start Hunting!

Translated by