Unable to get correct 2θ value from tan2θ = (2*a12)/(a11-a22) by writing as p= A(1,1) - A(2,2) q= 2 * A(1,2) theta = atan (p/q).Please help

1 view (last 30 days)
Unable to get correct 2θ value from tan2θ = (2*a12)/(a11-a22) by writing as
p= A(1,1) - A(2,2)
q= 2 * A(1,2)
theta = atan (p/q) for a (2 x 2) matrix.My code and output are
INPUT >>>>>
% Write down Matrix elements in [A(1,1) A(1,2);A(2,1) A(2,2)] format
Matrix = 'Write down Matrix elements.'
A = input(Matrix)
if ne(A(1,2),A(2,1))
disp('This is a asymmetric matrix')
else
disp('1.This is a symmetric matrix')
% Write down Matrix elements in [A(1,1),A(1,2);A(2,1),A(2,2)] format
p= A(1,1) - A(2,2)
q= 2 * A(1,2)
theta = atan (p/q)
end
OUTPUT >>>>>
Matrix =
'Write down Matrix elements.'
Write down Matrix elements.
[1 2;2 4]
A =
1 2
2 4
1.This is a symmetric matrix
p = -3
q = 4
theta = -0.6435
while correct value from calculator is -0.9272 rad.
Please help me.

Accepted Answer

Geoff Hayes
Geoff Hayes on 22 Apr 2019
Amar - I think that you should have q/p instead so that
theta = atan (q / p)
and theta will be -0.9272. Not sure if you still need to divide that result by two since you really have
2*theta = atan(q / p)
  2 Comments
Amar Kumar
Amar Kumar on 22 Apr 2019
A lots of thanks sir.I have got right answer.
one more question.when i am trying to write 2*theta by simple expression like 2*theta = atan (2 * A(1,2)/A(1,1) - A(2,2))
i have got as input and output ----
% Write down Matrix elements in [A(1,1) A(1,2);A(2,1) A(2,2)] format
Matrix = 'Write down Matrix elements.'
A = input(Matrix)
if ne(A(1,2),A(2,1))
disp('This is a asymmetric matrix')
else
disp('1.This is a symmetric matrix')
% Write down Matrix elements in [A(1,1),A(1,2);A(2,1),A(2,2)] format
theta = atan (2 * A(1,2)/A(1,1) - A(2,2))
end
Matrix =
'Write down Matrix elements.'
Write down Matrix elements.
[1 2 ; 2 4]
A =
1 2
2 4
1.This is a symmetric matrix
theta =
0
Geoff Hayes
Geoff Hayes on 22 Apr 2019
Amar - I think that you are missing some brackets around the denominator
theta = (atan (2 * A(1,2)/(A(1,1) - A(2,2)))) / 2.0;

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!