matlab的一个小问题

来源:百度知道 编辑:UC知道 时间:2024/05/28 18:57:15
function A=triarea(a,b,c)
if a<0|b<0|c<0
disp('the a,b,c must be positive number.'),break
end
if a+b<c|a+c<b|b+c<a
disp('this is impossible.'),break
s=(a+b+c)/2;
A=(s*(s-a)(s-b)(s-c))^(1/2);
为什么一运行triarea这个,老是出错,错误是Undefined function or method 'triarea' for input arguments of type 'double'.请高手指点

你改成这样试试:
function A=triarea(a,b,c)
if a<0|b<0|c<0
disp('the a,b,c must be positive number.'),
return
end
if a+b<=c|a+c<=b|b+c<=a
disp('this is impossible.'),
return
end
s=(a+b+c)/2;
A=(s*(s-a)*(s-b)*(s-c))^(1/2);