Writing Coefficients of a Summation?

2 次查看(过去 30 天)
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?

回答(3 个)

James Tursa
James Tursa 2017-9-22
编辑:James Tursa 2017-9-22
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 2017-9-22
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 2017-9-22
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.

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by