Writing Coefficients of a Summation?

4 visualizzazioni (ultimi 30 giorni)
amateurintraining
amateurintraining il 22 Set 2017
Risposto: Image Analyst il 22 Set 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?

Risposte (3)

James Tursa
James Tursa il 22 Set 2017
Modificato: James Tursa il 22 Set 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 il 22 Set 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 il 22 Set 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.

Categorie

Scopri di più su Quadratic Programming and Cone Programming in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by