Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7458391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:26:27+00:00 2026-05-29T13:26:27+00:00

I’m using the trapz function on two sets of data and there’s something wrong.

  • 0

I’m using the trapz function on two sets of data and there’s something wrong.

Here is a view of the data:
pressure drag coefficient and lift coefficient

So you can understand my problem; y-axis is pressure coefficient Cp, x-axis is angle (49 values in total, 0:7.5:360), data with the green square matrix is the data obtained from the experiment, the red curve is basically Cpsin(angle) while the pink one is Cpcos(angle)

Using trapz on the red one works perfectly, it gives 7.5, and if I reverse the input arguments for trapz I get the negative of this number! The problem is with the pink graph, using trapz gives a huge number (it’s wrong, I shouldn’t be getting this) and when switching the input arguments I get another huge number, not the negative of the first number, that is weird, I don’t know what is wrong, so I used quad (needs a function) to test the results of trapz

for i = 1:48
    y = @(x) (Cp(i+1) - Cp(i)) / ( theta_rad(i+1) - theta_rad(i) ) * x .* sin(x);
    clll(i) = -0.5* quad(y,theta_rad(i), theta_rad(i+1));

end
clll = sum(clll);

for j = 1:48
    f = @(t) (Cp(j+1) - Cp(j)) / ( theta_rad(j+1) - theta_rad(j) ) * t .* cos(t);
    cdddp(i) = 0.5* quad(f,theta_rad(j), theta_rad(j+1));

end

cdddp = sum(cdddp);

For the first loop (quad of the red curve) I got a very close answer, the error was probably due to the linear interpolation I used between points and for the second loop I got a sensible answer, a very small number which is in the range of the answer I’m looking for. I also tried trapezoidal rule in Excel and I got this huge number again, so it’s something I’m doing wrong.


Edit:

I just found a mistake, I was using the trapezoidal using angles in degrees rather than radians! Now I’m getting much smaller numbers but I think there’s another mistake because the integral using quad gives a more sensible answer.

Here’s the code I’m using for trapz

Cdp = 0.5*trapz( theta*pi/180, Cp.*cosd(theta) ); %pressure drag coefficient

Cl = -0.5*trapz(theta*pi/180, Cp.*sind(theta) ); %lift coefficient
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T13:26:28+00:00Added an answer on May 29, 2026 at 1:26 pm

    I got it working now, after using radians in the trapz function I got the correct answer. The interpolation I was trying to do is nonsense! I managed to create a fit using Curve Fitting Tool, it’s very efficient

    This

    Cdp = 0.5*trapz( theta*pi/180, Cp.*cosd(theta) ); %pressure drag coefficient
    

    can be achieved using the tool by:

    fit1 = createFit( theta*pi/180, Cp.*cosd(theta) ); 
    ##createFit is generated by MatLab and I only need parts of it, all the plots commands were removed.
    Cdp = 0.5*integrate(fit1,0,2*pi) ##"integrate" < this is why the tool is great, No need to export the coefficients to the workspace, create a function handle then use quad
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I want to construct a data frame in an Rcpp function, but when I
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am currently running into a problem where an element is coming back from
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.