# write a function called tri_area returns the area of a triangle with base b and height h

1,577 views (last 30 days)
Andrew Ayman on 9 Apr 2020
Commented: Walter Roberson on 21 Jun 2020 at 21:28
hello this is my function code and command window code and there is a message of invalid expression at line 2 and i dont know what is the wrong can anyone help me
function [area] = tri_area([b,h]);
tri_area([b,h])=(0.5)*(b)*(h)
area=tri_area([b,h])
end
%command window
area = tri_area[3,2])

Abdullah Javed on 27 May 2020
Make a little change in your code and it will work.
function [area] = tri_area(b,h)
tri_area(b,h)=(0.5)*(b)*(h)
area=tri_area(b,h)
end
Walter Roberson on 27 May 2020
this will not work for inputs that are not positive integers.
Naveen Gehlot on 6 Jun 2020 at 19:35
function [area, tri_area]= tri_area (b, h)
area=(1/2)*(b)*(h)
vca = area(:);
tri_area = sum(vca);
end
use this function for randow inputs
it will works.

Torsten on 9 Apr 2020
Edited: darova on 9 Apr 2020
function area = tri_area(b,h)
area = 0.5*b*h;
end
From the command window
A = tri_area(3,2)

AKASH Talapatra on 19 Jun 2020 at 7:59 kindly can anyone point out me where I was wrong?
Alric Duarte on 21 Jun 2020 at 13:22
someone please tell the solution for random inputs. i got the same error as above
Walter Roberson on 21 Jun 2020 at 21:28

Ramakant Gupta on 15 May 2020
Edited: Walter Roberson on 2 Jun 2020 at 23:09
function area = tri_area(b,h)
area = 0.5*b*h;
end