×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Calculation of area in plots

Calculation of area in plots

Calculation of area in plots

(OP)
Hi,
I'm using MATLAB 6.1 and want to calculate the area between the plot of a vector (with given values for the components) and the x-axis. I tried the quad command, but that's for functions only. Also the polyarea command doesn't seem to calculate the area correctly.
Can anyone tell me the, if there is a different command available?
Cheers,
Chris

RE: Calculation of area in plots

What's wrong with a straight numerical integration?

TTFN



RE: Calculation of area in plots

(OP)
Hi,
the numerical integration command (quad) needs a function or an string as input (but I only have the values of the vector (e.g. 5 60 45 3 8 etc.)). I programmed Simpsons rule:
%int=1/3*h*[fo+4*(f1+f3+...+f2n-1)+2*(f2+f4+...+f2n-2)+f2n]
and the results seem quite reasonable (about 5% error for several test functions).
I'm quite sure that there's also a MATLAB command for vectors (and not only for functions) available, I just don't know where to find it...
cheers,
Chris

RE: Calculation of area in plots

% One solution
area=sum(y(1:end-1)+y(2:end).*diff(x))/2;

% Another solution
area=trapz(x,y);

One function you may not be aware of is the always usefull "lookfor".

>> lookfor integration
CUMTRAPZ Cumulative trapezoidal numerical integration.
TRAPZ  Trapezoidal numerical integration.
lotkademo.m: %% Numerical Integration of Differential Equations
ADAMS Simulink 1.x ADAMS integration algorithm.
EULER Simulink 1.x EULER integration algorithm.
GEAR Simulink 1.x GEAR integration algorithm.
LINSIM Simulink 1.x LINSIM integration algorithm.
RK23 Simulink 1.x rk23 integration algorithm.
RK45 Simulink 1.x RK45 integration algorithm.
SFUNMEM A one integration-step memory block S-function.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources