Clear Filters
Clear Filters

Writing Coefficients of a Summation?

2 views (last 30 days)
amateurintraining
amateurintraining on 22 Sep 2017
Answered: Image Analyst on 22 Sep 2017
So, I have a quadratic function that is a summation. And the coefficients are the same, save for the first one but the powers are the powers from n_t to n_t-1.
To clarify: P*x^n_t - R*x^0 - R*x^1 ... - R*x^(n_t-1)
with coefficients: [P, -R, -R, ... , -R]
and powers: [n_t:n_t-1]
How do I write the coefficients in a way Matlab recognizes it?

Answers (3)

James Tursa
James Tursa on 22 Sep 2017
Edited: James Tursa on 22 Sep 2017
For use with MATLAB functions like polyval and friends, the highest power coefficient is the first element on down to the constant term which is the last element. So you should build your coefficient vector as
n_t = whatever;
coef = [P,-R*ones(1,n_t)];

Star Strider
Star Strider on 22 Sep 2017
See if this does what you want:
n = 6; % Arbitrary Constant
P = 3; % Arbitrary Constant
R = 5; % Arbitrary Constant
coefv = [P -R*ones(1, n)]; % Coefficient Vector
xpntv = [n 0:n-1]; % Exponent Vector
x = 4.2; % Scalar Value For ‘x’
S = (x.^xpntv) .* coefv; % Series

Image Analyst
Image Analyst on 22 Sep 2017
Let's say, n_t is 5. Then (n_t - 1) is 4. Since you always go from n_t down to n_t-1, you always have only two terms, in this case an x^5 term and an x^4 term. But this does not make it a quadratic just because it has two terms. To be a quadratic, the highest term should be 2. So you can just make your coefficient array like
coefficient = [P, R];
And your output, for my example would be
y = P * x^5 + R * x^4;
I don't see any real need to make an array for the coefficients when you have only two of them.

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!