The assignment asks to write a function to find unique isosceles triangles of integer sides and area.
A=sqrt(m*(m-a)(m-b)(m-a)
where
m = (a+a+b)/2 or P/2.
for example P=16 produces a=5, b=6 A=12
clear; for P = 1:100 [a,b,A] = IsoTrig(P); fprintf('P: %d, a: %d, b: %d, A: %d\n', P, a, b, A); end;function [a,b,A] = IsoTrig(P) if P<0 || fix(P) ~=P; disp('error, input is not a non negative integer') return end n = 0 % variable to sum loop passes
m=P/2; for ii=1:P; a=ii/2; b=P-(2*a); if b>= 2*a || b<=0; continue end for A=sqrt((m*(m-a)*(m-b)*(m-a))); if fix(A)== A && A ~= 0 && fix(a)==a && fix(b) == b && n == 0 a=a; b=b; A=A; n = n+1; else fix(A) ~= A || fix(a) ~= a || fix (b) ~= b || A == 0 || n == 1; a = 0; b = 0; A = 0; continue end [P,a,b,A] end endend
- So we are talking about unique Heronian isosceles triangle.
*My code doesn't output what I want, the [P,a,b,A] gives me Heronian isosceles results but the function output itself is different.
*As can be seen my [P,a,b,A] call results is different to the fprintf results. The current program doesn't find any results to fprintf.
*I don't know how to isolate the unique triangles (where 1 heronian isosceles exists for given P) My code if working only reduces the output to 1 not per given P not find unique.
OUTPUT as standsP: 101, a: 5.050000e+01, b: 0, A: 0P: 102, a: 51, b: 0, A: 0P: 103, a: 5.150000e+01, b: 0, A: 0P: 104, a: 52, b: 0, A: 0P: 105, a: 5.250000e+01, b: 0, A: 0P: 106, a: 53, b: 0, A: 0P: 107, a: 5.350000e+01, b: 0, A: 0ans = 108 30 48 432 <- from [P,a,b,A] callP: 108, a: 54, b: 0, A: 0P: 109, a: 5.450000e+01, b: 0, A: 0P: 110, a: 55, b: 0, A: 0P: 111, a: 5.550000e+01, b: 0, A: 0ans = 112 35 42 588P: 112, a: 56, b: 0, A: 0P: 113, a: 5.650000e+01, b: 0, A: 0P: 114, a: 57, b: 0, A: 0P: 115, a: 5.750000e+01, b: 0, A: 0P: 116, a: 58, b: 0, A: 0P: 117, a: 5.850000e+01, b: 0, A: 0P: 118, a: 59, b: 0, A: 0P: 119, a: 5.950000e+01, b: 0, A: 0P: 120, a: 60, b: 0, A: 0P: 121, a: 6.050000e+01, b: 0, A: 0P: 122, a: 61, b: 0, A: 0P: 123, a: 6.150000e+01, b: 0, A: 0P: 124, a: 62, b: 0, A: 0P: 125, a: 6.250000e+01, b: 0, A: 0ans = 126 35 56 588P: 126, a: 63, b: 0, A: 0P: 127, a: 6.350000e+01, b: 0, A: 0ans = 128 34 60 480P: 128, a: 64, b: 0, A: 0P: 129, a: 6.450000e+01, b: 0, A: 0P: 130, a: 65, b: 0, A: 0P: 131, a: 6.550000e+01, b: 0, A: 0P: 132, a: 66, b: 0, A: 0P: 133, a: 6.650000e+01, b: 0, A: 0P: 134, a: 67, b: 0, A: 0P: 135, a: 6.750000e+01, b: 0, A: 0P: 136, a: 68, b: 0, A: 0P: 137, a: 6.850000e+01, b: 0, A: 0P: 138, a: 69, b: 0, A: 0P: 139, a: 6.950000e+01, b: 0, A: 0P: 140, a: 70, b: 0, A: 0P: 141, a: 7.050000e+01, b: 0, A: 0P: 142, a: 71, b: 0, A: 0P: 143, a: 7.150000e+01, b: 0, A: 0ans = 144 37 70 420P: 144, a: 72, b: 0, A: 0P: 145, a: 7.250000e+01, b: 0, A: 0P: 146, a: 73, b: 0, A: 0P: 147, a: 7.350000e+01, b: 0, A: 0P: 148, a: 74, b: 0, A: 0P: 149, a: 7.450000e+01, b: 0, A: 0
Best Answer