I need help with Matlab ... I just need help starting off entering the coordinat
ID: 3650153 • Letter: I
Question
I need help with Matlab ... I just need help starting off entering the coordinates Write a script that will prompt the user to enter the coordinates of three points that determine a triangle (e.g., the x and y coordinates of each point). The script will then calculate and print the area of the triangle. It will call one function to calculate the area of the triangle. This function will call a subfunction, which calculates the length of the side formed by any two points (the distance between them).Explanation / Answer
Please rate...
Save the follwing files in the same working directory and then execute the file "trianglearea.m" in the matlab command area.
=============================================================
"trianglearea.m"
=====================================================
x1=input('Enter the x co-ordinate of 1st point: ');
y1=input('Enter the y co-ordinate of 1st point: ');
x2=input('Enter the x co-ordinate of 2nd point: ');
y2=input('Enter the y co-ordinate of 2nd point: ');
x3=input('Enter the x co-ordinate of 3rd point: ');
y3=input('Enter the y co-ordinate of 3rd point: ');
a=areatri(x1,y1,x2,y2,x3,y3);
disp('The area of the triangle is: ');
disp(a);
================================================================
"lengthtriangle.m"
===============================================================
function [ l ] = lengthtriangle( x1,y1,x2,y2 )
l=sqrt(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1)));
end
==============================================================
"areatri.m"
============================================================
function [ a ] = areatri( x1,y1,x2,y2,x3,y3 )
s1=lengthtriangle(x1,y1,x2,y2);
s2=lengthtriangle(x2,y2,x3,y3);
s3=lengthtriangle(x3,y3,x1,y1);
sp=(s1+s2+s3)/2;
a=sqrt((sp*(sp-s1)*(sp-s2)*(sp-s3)));
end
=============================================================
Sample output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.