for loop - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

for loop

Bob44Bob44 Posts: 2Member

I'm looking for some help with a problem I'm trying to solve and wondered if anyone could help.

I'm trying to calculate the largest possible area of a trapezium whose sides are at a variety of angles and lengths.

I used a for loop to calculate the different values for area with sides varying angle and fixed length. I then used another for loop to calculate values for area with varying side lengths and fixed angle.

It seems to be that the values for area continue to increase even when area should begin to reduce (after the peak value). So I'm basically getting the max area when the sides are at 90 degrees (when the shape is just a rectangle). Any suggestions what I might be doing wrong?


  • xhcpxdoofyxhcpxdoofy Posts: 1Member
    The way you worded this question is kind of confusing, but from what I gather you have the angles and lengths for a certain number of trapezoids, and you want to know which trapezoid has the largest area. I would create two matrices: one with the angles, and one with the lengths, like so:


    Then, I would make a for loop that finds the area of each trapezoid, places the areas in a vector, and keeps track of the maximum area value, like so:

    for i=1:r
    if area(i)>areamax

Sign In or Register to comment.