Matlab

Moderators: None (Apply to moderate this forum)
Number of threads: 1471
Number of posts: 2147

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
for loop Posted by Bob44 on 30 Nov 2011 at 8:49 AM
Hi

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?
Report
Re: for loop Posted by xhcpxdoofy on 7 Dec 2011 at 4:34 PM
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:

A=[theta1,theta2,theta3,theta4;...
theta1,theta2,theta3,theta4;...
theta1,theta2,theta3,theta4];
L=[L1,L2,L3,L4;...
L1,L2,L3,L4;...
L1,L2,L3,L4];

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:

[r,c]=size(A);
areamax=0;
for i=1:r
area(i)=.5*L(i,1)*sind(A(i,1))*(L(i,2)+L(i,4));
if area(i)>areamax
areamax=area(i);
end
end

Attachment: trapezoid.jpg (8803 Bytes | downloaded 19 times)



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.