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

  • Context: MATLAB 
  • Thread starter Thread starter motherh
  • Start date Start date
  • Tags Tags
    matlab
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 3K views
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.