user899714
user899714

Reputation: 465

How to take a polynomial as input in matlab?

I want to take a polynomial p as input from user in matlab for a given degree (specified by the user each time) such that the polynomial is input one element at a time into a matrix at each index from 1 to n. where n is the polynomial degree. was tryin to do something like this but m stuck

     for M = 1:n
        p[n] = input('polynomial')
        p
     end

How should I input a polynomial coefficient at each index of matrix i.e. how to reach each index position?

Upvotes: 1

Views: 2569

Answers (1)

sgarizvi
sgarizvi

Reputation: 16796

Instead of using a loop, you can take a polynomial as input using the following method:

p = input('Enter a polynomial in [] brackets');

Now the user should enter the polynomial like this:

[2, 4, 3, 8];

Then you can calculate its degree using the length command:

n = length(p);

Upvotes: 1

Related Questions