simple integration question
simple integration question
(OP)
Im new to matlab so you'll have to excuse the very basic question (and Im not sure if this is in the correct forum).
1) In the function polyint, there is 1 line of code to perform integration, and I can't see how it works. The line is-
r = [ p./(n:-1:1), 0 ];
where r is the integral being calculated, p is a row vector representing a polynomial (in the form of [1 0 0]) and n is the number of elements in p.
If someone could explain briefly what is happening it would be a big help. Thanks.
1) In the function polyint, there is 1 line of code to perform integration, and I can't see how it works. The line is-
r = [ p./(n:-1:1), 0 ];
where r is the integral being calculated, p is a row vector representing a polynomial (in the form of [1 0 0]) and n is the number of elements in p.
If someone could explain briefly what is happening it would be a big help. Thanks.





RE: simple integration question
Say p = [A B C D]
in a matlab polynomial this represents the polynomial
Ax^3 + Bx^2 + Cx + D.
Now the expression (n:-1:1) translates in matlab as "a vector whous elements count from n to 1 in steps of -1". ie, for n = 4 the vector
(n:-1:1) = [4 3 2 1]
so now
r = [p./(n:-1:1) ,0]
becomes
r = [ [A B C D]./[4 3 2 1] , 0]
the "X./Y" operator means "divide the element of X by the corresponding element of Y"
so now
r = [ [A/4 B/3 C/2 D/1], 0 ]
the ",0" bit means "append a 0 onto the end of the vector"
so r = [A/4 B/3 C/2 D/1 0]
which represents the matlab polynomial
(A/4)*x^4 + (B/3)*x^3 + (C/2)*x^2 + (D/1)*x + 0
and is the indefinite integral of p with the constant of integration set to zero.
M
--
Dr Michael F Platten
RE: simple integration question