Info

# I need some assistance with my function program?

1 view (last 30 days)
Aaron on 22 Jul 2012
Closed: MATLAB Answer Bot on 20 Aug 2021
I'm not sure where my mistakes are. The following is my main program:
a = input('Enter value for side a: ');
if a <= 0
disp('Not a valid input! Side "a" must be greater than zero.');break;
end
b = input('Enter value for side b: ');
if b <= 0
disp('Not a valid input! Side "b" must be greater than zero.');break;
end
c = input('Enter value for side c: ');
if c <= 0
disp('Not a valid input! Side "c" must be greater than zero.');break;
end
if a > b+c
fprintf('\n');
disp('Error: Side "a" must be less than the sum of sides b & c.');break;
elseif b > a+c
fprintf('\n');
disp('Error: Side "b" must be less than the sum of sides a & c.');break;
elseif c > a+b
fprintf('\n');
disp('Error: Side "c" must be less than the sum of sides a & b.');break;
end
fprintf('\n');
[Angle_A,Angle_B,Angle_C] = angle_calc(a,b,c) % This is the correct name of my function program
My function program is:
function [law_cosines] = angle_calc (side_A,side_B,side_C)
angle_A = acosd((b^2+c^2-a^2)/(2*b*c));
angle_B = acosd((a^2+c^2-b^2)/(2*a*c));
angle_C = acosd((a^2+b^2-c^2)/(2*a*b));

Image Analyst on 22 Jul 2012
Your "function program" needs to look like this:
function [angle_A, angle_B, angle_C] = angle_calc (a, b, c)
angle_A = acosd((b^2+c^2-a^2)/(2*b*c));
angle_B = acosd((a^2+c^2-b^2)/(2*a*c));
angle_C = acosd((a^2+b^2-c^2)/(2*a*b));

Walter Roberson on 22 Jul 2012
function [law_cosines] = angle_calc (side_A,side_B,side_C)
should be
function [angle_A, angle_B, angle_C] = angle_calc (side_A,side_B,side_C)