Without even trying to exceute your code...
You set theta to zero.
The value of theta will ONLY ever be changed if a test is satisfied for exact equality between two floating point numbers. So tests like this:
if theta1_1_a==theta1_2_a || theta1_1_a==theta1_2_b
Now, l'll look at the result of your code.
[theta1_1_a, theta1_2_a]
ans =
64.4196851608345 -64.4196851608345
>> [theta1_1_a, theta1_2_b]
ans =
64.4196851608345 244.419685160834
So that test must fail.
Then you have an elseif clause.
elseif (theta1_1_b==theta1_2_a) || (theta1_1_b==theta1_2_b)
Is it satisfied?
[theta1_1_b, theta1_2_a]
ans =
-64.4196851608345 -64.4196851608345
Gosh, it looks like they are the same numbers. Are they really the same?
[theta1_1_b == theta1_2_a]
ans =
logical
0
theta1_1_b - theta1_2_a
ans =
1.4210854715202e-14
As you can see, they are not in fact identical.
NEVER TEST FOR EXACT EQUALITY BETWEEN FLOATING POINT NUMBERS. At least not until you truly understand why I just told you not to do so, and you understand when you can expect such a test to be valid. And even then, be careful.
Learn to use tolerances.
Best Answer