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
Click For Summary
SUMMARY

To ensure that MATLAB outputs all coefficients, including zero coefficients, when using the coeffs function, the polynomial must be explicitly defined with all terms included. For example, defining the polynomial as f = 2*x^2 + 0*x + 1 will result in the output [2, 0, 1]. Alternatively, starting with the coefficient array f = [2, 0, 1] is a straightforward method to achieve the desired output.

PREREQUISITES
  • Understanding of MATLAB syntax and functions
  • Familiarity with polynomial representation in MATLAB
  • Basic knowledge of symbolic mathematics in MATLAB
  • Experience with array manipulation in MATLAB
NEXT STEPS
  • Learn how to define polynomials in MATLAB using symbolic variables
  • Explore the poly2sym function for converting coefficient arrays to symbolic expressions
  • Research MATLAB's symbolic toolbox for advanced polynomial manipulations
  • Investigate array initialization techniques in MATLAB for efficient coding
USEFUL FOR

Mathematics students, MATLAB users, and engineers looking to manipulate polynomial coefficients effectively in their computations.

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 ·
Replies
5
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K