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

469 views (last 30 days)
Andrew Ayman on 9 Apr 2020
Answered: Pelden Chodon on 27 May 2021
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])
Christine Mizzi on 27 Aug 2020
What is the purpose for writing two output arguments in the code? i.e. [area, tri_area]
If the user is calling the area of a triangle wouldn't that be only one output argument?

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)
Anees Fatima on 16 May 2021
what will be the random input here?

Eshan Pansare on 28 Aug 2020
How to solve the random inputs part?

Imane Tahar on 19 Nov 2020
function area = tri_area(b,h)
area = (b*h)/2
end

Ramakant Gupta on 15 May 2020
Edited: Walter Roberson on 2 Jun 2020
function area = tri_area(b,h)
area = 0.5*b*h;
end
##### 2 CommentsShowHide 1 older comment
madhan ravi on 2 Jun 2020
Maybe he wanted to test his first answer xD in the forum.

prudhvi gandham on 6 Nov 2020
function area = tri_area(b,h)
area = 0.5*b*h;
end
Walter Roberson on 4 Apr 2021

Siya Desai on 4 Apr 2021
Edited: Walter Roberson on 4 Apr 2021
function
function [area] = tri_area (b,h)
tri_area = (0.5)*(b)*(h)
tri_area(2,3) %any random input
Walter Roberson on 4 Apr 2021
result = tri_area(2,3) %any random input
tri_area = 3
Output argument "area" (and maybe others) not assigned during call to "solution>tri_area".
function [area] = tri_area (b,h)
tri_area = (0.5)*(b)*(h)
end

Pelden Chodon on 27 May 2021
function [area, tri_area] = tri_area(b,h) ;
area = (0.5)*(b)*(h);
v = area(:);
tri_area = sum(v);
end
% Test that your function runs as expected before pressing Submit
[area, tri_area] = tri_area(2,3)