How Can You Calculate the Area of a Polygon in MATLAB?

  • Thread starter StephvsEinst
  • Start date
  • Tags
    Matlab
In summary, MATLAB is a high-level programming language and interactive environment used for scientific and numerical computing. It offers built-in functions and commands for complex mathematical operations and data analysis. To solve a problem in MATLAB, you would need to define variables and use appropriate functions and commands. It also has data visualization capabilities and is designed to be user-friendly, although basic programming knowledge can be helpful. Resources such as online tutorials, documentation, and forums are available for learning and improving skills with MATLAB.
  • #1
StephvsEinst
41
1

Homework Statement


H[/B]ow to create a function to determine the area of a polynomial that has N vertexes in MATLAB?

Homework Equations


p = input('Introduce the number of vertexes of the polynomial:')
n=p-2;

The polynomial can be devided by N-2 triangles and the area of each triangle is given by A=(1/2)*det(B) where B=[x1 x2 x3 ... xn; y1 y2 y3 ... yn; 1 1 1 1 1 ... 1(last row is filled with n ones)]

The Attempt at a Solution


p = input('Introduce the number of vertexes of the polynomial:')
n=p-2;
if n<3:
fprintf('error')
else
(...) - I tried 'if cicles' and sums but I don't know know how to ask for all x and y of the polynomial vertexes (because the size of the matrix varies with the number of vertexes of the polynomial).

Would apreciate any kind of help :D
 
Physics news on Phys.org
  • #2
You have to ask all the coordinates of the vertexes
 
  • #3
Already solved it:

function p = area_polinomio(N)
i=1;
area = 0;
A = [0,0,0;0,0,0;0,0,0];
if N < 3
warning('pontos insuficientes')
return
else
a = [input('introduza a abcissa do primeiro ponto: '); input('\n introduza a ordenada do primeiro ponto: '); 1];
for i = 1 : N-1
b = [input('\n introduza a abcissa do ponto seguinte: '); input('\n introduza a ordenada do ponto seguinte: '); 1];
if i == 1
A = [a, b];
end
if i == 2
A = [A, b];
area = area + (1/2)*det(A);
end
if i > 2
A = A(:,[1:1,3,3:2,2,4:end]);
A = A(1:3,1:2);
A = [A, b];
area = area + (1/2)*det(A);
end

i = i+1;
end
end
%A

Thanks.
 
  • #4
The word you're searching for is polygon, a two-dimensional figure with three or more straight sides that intersect at the vertices of the polygon. Triangles, rectangles, and hexagons are examples of polygons.

A polynomial is an expression made up of sums of integer powers of the variable. For example, f(x) = 2x + 3, g(x) = x2 - 3x + 2, and h(x) = x4 - 1 are polynomial functions of degree 1, 2, and 4 respectively.
 
  • #5
LOOOL. That made me laugh xD
A silly misake made by me. Acually when I was solving this I named the function area_polynomial and not area_polygon until it was time to run it, then I changed the name. Was completely focused on the exercise xD
 
  • #6
Are you from Portugal or Brazil? I'm just curious...
 
  • #7
Portugal :)
 

FAQ: How Can You Calculate the Area of a Polygon in MATLAB?

1. What is MATLAB and how does it work?

MATLAB is a high-level programming language and interactive environment designed for scientific and numerical computing. It allows users to easily perform complex mathematical operations and data analysis by using built-in functions and commands.

2. How do I solve a simple problem in MATLAB?

To solve a simple problem in MATLAB, you would first need to define your variables and data, then use the appropriate functions and commands to manipulate and analyze the data. You can also use loops and conditional statements to create more complex solutions.

3. Can I use MATLAB for data visualization?

Yes, MATLAB has powerful data visualization capabilities that allow you to create 2D and 3D plots, charts, and graphs. You can also customize the visualizations to fit your specific needs and preferences.

4. Do I need prior programming experience to use MATLAB?

No, MATLAB is designed to be user-friendly and does not require extensive programming knowledge. However, having a basic understanding of programming concepts such as variables, functions, and loops can be helpful.

5. Are there any resources available to help me learn and improve my skills with MATLAB?

Yes, there are many resources available such as online tutorials, documentation, and forums where you can ask questions and get help from other users. You can also take online courses or attend workshops to improve your skills with MATLAB.

Back
Top