Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple integration question

Status
Not open for further replies.

jacobs2011

Computer
Nov 8, 2004
2
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.
 
Replies continue below

Recommended for you

It is simply integrating the polynomial as you would do yourself by hand. ie. int(A*x^n) = A/(n+1)*x^(n+1) + constant

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
 
Thanks for the very prompt and helpful response! Even more simple than I thought now that I know what's going on..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor