Writing Coefficients of a Summation?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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?
0 comentarios
Respuestas (3)
James Tursa
el 22 de Sept. de 2017
Editada: James Tursa
el 22 de Sept. de 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)];
0 comentarios
Star Strider
el 22 de Sept. de 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
0 comentarios
Image Analyst
el 22 de Sept. de 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.
0 comentarios
Ver también
Categorías
Más información sobre Quadratic Programming and Cone Programming en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!