Is it possible to make Acos return values greater than pi?

I know the a, b and c and x values. I want to find Theta value. I use the command 'acos' for this, but 'acos' returns a value between [0, pi]. For example, it needs to return 240 degrees, but it retuns 120 deg. Since theta value is a phase shift, it is problematic. Any advice?

6 Kommentare

Can you share your code?
Just generate both first and second quandrant solutions and discard the one that doesn't check.
w = 5;
a=5;
b=10;
phase = degtorad(200);
t=0:0.01:5;
A = a*sin(w*t);
B = b*sin(w*t + phase);
C = A+B;
% plot(t,A); hold on; plot(t,B,'r--'); hold on; plot(t,C,'g-o');
[val_Cpeak,loc_Cpeak] = findpeaks(C);
c = max(val_Cpeak);
faz = real(acos((c^2-a^2-b^2)/(2*a*b)));
So faz should be roughly equal to phase? What are you trying to do (big picture)?
What I really want to do is to give the system a sinusoidal input (A.sin (wt)) and find the frequency transfer function of the system by looking at the system's steady state output (A. | G (w) | .sin (wt + phase)). So I need to determine this phase and yes, 'faz' must be directly equal to phase.
I am still a bit confused. If you are only given C (sinusoidal input) how do you know what (a) and (c) are? If you know what A and B are, then you already know the (phase). Like I said before you could try all the possible solutions of (faz) and discard those that don't result in the equation equality.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

David Goodmanson
David Goodmanson am 2 Apr. 2020
Bearbeitet: David Goodmanson am 2 Apr. 2020
Hi Berke,
I wrote a clarification to your previous question which I think should resolve that issue. It looks like you have determined (or can determine) a, c and phi and wish to solve for b and theta. The first equation in your question is just the imaginary part of
a*exp(i*x) + b*exp(i*x + i*theta) = c*exp(i*x + i*phi)
Factoring out the exp(i*x) leaves
a + b*exp(i*theta) = c*exp(i*phi)
so the sum of two phasors is a third one. [ note that multiplying this equation by its complex counjugate gives the second equation in the question ]. Solving this gives
b = abs(c*exp(i*phi) - a)
theta = angle(c*exp(i*phi) - a)
Just like acos, angle has a convention that deals with 2pi ambiguity, which is -pi < angle <=pi. This means that for the case that you mentioned, angle will produce -120 degrees, not 240. That's how it is, but if you want only positive angles, then (for degrees) it would be mod(angle,360).

1 Kommentar

Hi David,
Thank you for explaining everything very clearly. This worked really well for me!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Guillaume
Guillaume am 1 Apr. 2020
"Is it possible to make Acos return values greater than pi?"
No. The function codomain is mathematically defined as [0, π]. You can define your own reciprocal of the cosinus function with a different codomain but that won't be arccos.eg:
function y = myaccosd(x)
y = -accosd(x);
end
which would return your 240 degrees (mod 360) for an input of -0.5.

4 Kommentare

"For real values of X in the interval [-1, 1], acosd(X) returns values in the interval [0, 180]. "
How can I get 240 degrees output from this function?
"How can I get 240 degrees output from this function?"
360 - acosd(x)
What if the actual phase value is 120 degrees, then it will still get 240 degrees.
Walter Roberson
Walter Roberson am 1 Apr. 2020
Bearbeitet: Walter Roberson am 1 Apr. 2020
What information do you have that would permit you to distinguish whether 120 or 240 was the "actual" phase" ? And not (say) 600 ?

Melden Sie sich an, um zu kommentieren.

Produkte

Version

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by