write a function called tri_area returns the area of a triangle with base b and height h
381 ビュー (過去 30 日間)
表示 古いコメント
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 件のコメント
Christine Mizzi
2020 年 8 月 27 日
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?
採用された回答
その他の回答 (8 件)
Ramakant Gupta
2020 年 5 月 15 日
編集済み: Walter Roberson
2020 年 6 月 2 日
function area = tri_area(b,h)
area = 0.5*b*h;
end
2 件のコメント
prudhvi gandham
2020 年 11 月 6 日
function area = tri_area(b,h)
area = 0.5*b*h;
end
1 件のコメント
Walter Roberson
2021 年 4 月 4 日
Siya Desai
2021 年 4 月 4 日
編集済み: Walter Roberson
2021 年 4 月 4 日
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 件のコメント
Walter Roberson
2021 年 4 月 4 日
result = tri_area(2,3) %any random input
function [area] = tri_area (b,h)
tri_area = (0.5)*(b)*(h)
end
Pelden Chodon
2021 年 5 月 27 日
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 件のコメント
raj akshat
2022 年 2 月 14 日
function area = tri_area (b,h)
tri_area([b,h]) =(0.5)*(b)*(h);
area= tri_area([b,h]);
end
0 件のコメント
Partha Singha
2022 年 2 月 26 日
function [area, tri_area] = tri_area(b,h) ;
area = (0.5)*(b)*(h);
v = area(:);
tri_area = sum(v);
end
1 件のコメント
Walter Roberson
2022 年 2 月 26 日
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
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!