MATLAB Answers

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

1,150 ビュー (過去 30 日間)
Andrew Ayman
Andrew Ayman 2020 年 4 月 9 日
コメント済み: Walter Roberson 2020 年 6 月 21 日
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])

  7 件のコメント

表示 4 件の古いコメント
Abdullah Javed
Abdullah Javed 2020 年 5 月 27 日
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
Walter Roberson 2020 年 5 月 27 日
this will not work for inputs that are not positive integers.
Naveen Gehlot
Naveen Gehlot 2020 年 6 月 6 日
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.

Sign in to comment.

採用された回答

Torsten
Torsten 2020 年 4 月 9 日
編集済み: darova 2020 年 4 月 9 日
function area = tri_area(b,h)
area = 0.5*b*h;
end
From the command window
A = tri_area(3,2)

  14 件のコメント

表示 11 件の古いコメント
AKASH Talapatra
AKASH Talapatra 2020 年 6 月 19 日
kindly can anyone point out me where I was wrong?
Alric Duarte
Alric Duarte 2020 年 6 月 21 日
someone please tell the solution for random inputs. i got the same error as above

Sign in to comment.

その他の回答 (1 件)

Ramakant Gupta
Ramakant Gupta 2020 年 5 月 15 日
編集済み: Walter Roberson 2020 年 6 月 2 日
function area = tri_area(b,h)
area = 0.5*b*h;
end

  2 件のコメント

Walter Roberson
Walter Roberson 2020 年 6 月 2 日
How does this differ from Torsten's Answer?
madhan ravi
madhan ravi 2020 年 6 月 2 日
Maybe he wanted to test his first answer xD in the forum.

Sign in to comment.


Translated by