write a function called tri_area returns the area of a triangle with base b and height h
377 views (last 30 days)
Show older comments
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])
10 Comments
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?
Accepted Answer
More Answers (8)
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 Comments
prudhvi gandham
on 6 Nov 2020
function area = tri_area(b,h)
area = 0.5*b*h;
end
1 Comment
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)
code to call your function
tri_area(2,3) %any random input
1 Comment
Walter Roberson
on 4 Apr 2021
result = tri_area(2,3) %any random input
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)
0 Comments
raj akshat
on 14 Feb 2022
function area = tri_area (b,h)
tri_area([b,h]) =(0.5)*(b)*(h);
area= tri_area([b,h]);
end
0 Comments
Partha Singha
on 26 Feb 2022
function [area, tri_area] = tri_area(b,h) ;
area = (0.5)*(b)*(h);
v = area(:);
tri_area = sum(v);
end
1 Comment
Walter Roberson
on 26 Feb 2022
how does this differ from https://www.mathworks.com/matlabcentral/answers/516676-write-a-function-called-tri_area-returns-the-area-of-a-triangle-with-base-b-and-height-h#answer_710385
See Also
Categories
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!