eqn = 
Incorrect Coefficients from Symbolic Polynomial Equation Solving
Afficher commentaires plus anciens
I'm working with MATLAB's symbolic toolbox to solve a polynomial equation for specific coefficients a1, a2, a3, and a4. The objective is to express a polynomial in terms of these coefficients and then solve for them such that the polynomial equation holds true.
**Here is my function:**
function FindEquations()
syms a1 a2 a3 a4 x; % Define symbolic variables
% Define the equation with all terms on one side (zero on the other side)
eqn = a1 + a4*(x^3 + x^2 + x + 1) + a3*(x^2 + x + 1) + a2*(x + 1) - x^2 == 0;
% Expand the equation to simplify it and correctly distribute all terms
eqn = expand(eqn);
% Collect coefficients for the system of linear equations
[A, B] = equationsToMatrix(eqn, [a1, a2, a3, a4]);
% Solve the linear system
sol = linsolve(A, B);
% Display the solution
disp('The solutions for a1, a2, a3, a4 are:');
disp(sol);
end
```
**Expected Output:**
The coefficients should logically be [0, -1, 1, 0], corresponding to a1, a2, a3, a4, respectively.
**Actual Output:**
However, the actual output I get is [x^2, 0, 0, 0]. This suggests that a1 is being incorrectly set to x^2 instead of 0, and the others are zero, which does not match my expectations based on the equation setup.
Question:
1. Why might the `equationsToMatrix` function not be translating the symbolic equation into the correct system matrix A and vector B?
2. How can I adjust the equation or the process of deriving A and B to ensure that the coefficients are determined accurately?
Additional Context:
- I am using MATLAB R2021a.
- The symbolic toolbox is installed and has been working fine for other types of calculations.
Any insights or suggestions on how to correct this issue or alternative methods to achieve the desired results would be greatly appreciated!
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Linear Algebra dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!