MATLAB How to Make Matlab Output Zero Coefficients in f=2x^2+1?

  • Thread starter Thread starter motherh
  • Start date Start date
  • Tags Tags
    matlab
AI Thread Summary
In MATLAB, when using the coeffs function on a polynomial like f = 2x^2 + 1, it only returns the non-zero coefficients, resulting in [2, 1]. To include zero coefficients in the output, the polynomial must be explicitly defined with all terms, such as f = 2x^2 + 0x + 1. This ensures that MATLAB recognizes the zero coefficient for the x term. Alternatively, starting with a coefficient array like f = [2, 0, 1] can also achieve the desired output. The discussion highlights the importance of explicitly stating all coefficients in polynomial expressions to ensure accurate representation in MATLAB.
motherh
Messages
27
Reaction score
0
Take f = 2x^2 + 1. When I run coeffs(f) in Matlab it outputs [2,1]. However I want it to output all the zero coefficients as well, for example [2 0 1] here. How do I do that?
 
Last edited:
Physics news on Phys.org
motherh said:
Take f = 2x^2 + 1. When I run coeffs(f) in Matlab it outputs [2,1]. However I want it to output all the zero coefficients as well, for example [2 0 1] here. How do I do that?


My first thought would be that you'd need to have f = 2x^2 + 0x + 1 because with what you have f as right now, MATLAB doesn't know that the x coefficient is 0 if it's not explicitly typed.

Then again I'm no expert so there's a good chance I'm wrong, just a thought.
 
Does this have to be done symbolically?

If not you should probably just *start* with f = [2 0 1] and work from there.
 

Similar threads

Replies
5
Views
2K
Replies
8
Views
2K
Replies
4
Views
1K
Replies
2
Views
2K
Replies
1
Views
4K
Replies
5
Views
2K
Back
Top