function arcsin in matlab

687 views (last 30 days)
zaafouri rabaa
zaafouri rabaa on 5 Aug 2016
Edited: John Kelly on 21 Feb 2017
hello please can someone help me calculate arcsin () in matlab, I try with the function y = asin (x) but x must be between -1 and 1
  1 Comment
James Tursa
James Tursa on 10 Aug 2016
Are you struggling with numerical accuracy issues where the value is just barely outside [-1,+1] and you need to clip it to [-1,+1]? E.g., some calculation that mathematically must be in [-1,+1] but because of numerical issues is not quite in that range?

Sign in to comment.

Accepted Answer

Steven Lord
Steven Lord on 5 Aug 2016
The input argument x is not limited to be in the range [-1, 1] in the asin function. What that documentation states is IF x is in that range, the output will be in a certain range; if it is not in that range, the output will be complex.
>> asin(2)
ans =
1.5707963267949 - 1.31695789692482i
  10 Comments
zaafouri rabaa
zaafouri rabaa on 11 Aug 2016
Hello everyone Thanks a lot for your answers my question is clear I know that the domain of input of the arcsin function is the interval [-1,1] arcsin (x) = y if X in the interval [-1,1], Y is real if X outside this interval Y is a complex number So I ask if it possible to get a real angle of the complex number I search a treatment to make this complex number real angle. thanks in advance is it possible ou no??

Sign in to comment.

More Answers (3)

Walter Roberson
Walter Roberson on 9 Aug 2016
angle(asin(x))
  8 Comments
John D'Errico
John D'Errico on 10 Aug 2016
Edited: John Kelly on 21 Feb 2017
It does not matter how much you want an answer that is a real number. Mathematics is simple in this respect.
You tell us that asin produces an output of
-1.570796326794897 + 4.032979067336616i
Then the input x to asin was probably something roughly like -28.2232438247125.
There is NO real angle X such that sin(X) will yield -28.2232438247125.
Remember that sin(X), for ANY real input X, will ALWAYS lie between -1 and 1. No lower, no higher.
Therefore the input to asin, IF you hope to find a real output result, MUST lie in the closed interval [-1,1]. This is basic mathematics.
So, IF you have an input to asin, of the form:
(comp2-C2)/r)
that results in a value is less than -1 or greater than +1, then there is a bug in your code. Since that value was indeed outside of that interval, then we know, with mathematical certainty, that one or more of those numbers was computed incorrectly, or that the expression itself is incorrectly used there.
This is not a question of fixing the output of asin. It is not a question of finding a real angle. It is a question of you looking at your code and finding the bug. You need to do that, since we do not see your code. We do not know what it should do, or why you wrote it that way.
It is very simple. You have a bug in your code. Or perhaps you are simply using some formulas that you derived incorrectly. Essentially, that is still a bug, but a bug in your thinking.
Walter Roberson
Walter Roberson on 10 Aug 2016
zaafouri rabaa please give particular real value outside of [-1, 1] and the real angle that you know to be associated. Please do not leave us speculating about what the appropriate real value might be, because that leaves us to invent wild things.
This angle that you want, does it have to have the property that
sin(YourExtendedArcsineFunction(x)) = x
for at least some range of real-valued x that is not part of [-1, 1] ? If so, then what range of real-valued x does that need to be satisfied for (taking into account the periodic nature of the sine function.)

Sign in to comment.


John BG
John BG on 10 Aug 2016
Edited: John BG on 10 Aug 2016
No, all input complex numbers seem to give complex angles, from the following the only way to get a real angle is to input a real number (within [-1 1]):
x=[-10:.1:10];y=[-1:.01:1];[X,Y]=meshgrid(x,y);Z=asin(X+(0+1j)*Y);
figure(1);surf(real(Z));
figure(2);surf(imag(Z));
This second graph is the key, there are only imaginary values different than zero when away from the real axis.
I tried to narrow the input imaginary range to visualise the transition
x=[-10:.1:10];y=[-1:.01:1];[X,Y]=meshgrid(x,y);Z=asin(X+(0+1j)*Y);
figure(10);surf(real(Z));figure(11);surf(imag(Z));
x=[-10:.1:10];y=[-.1:.001:.1];[X,Y]=meshgrid(x,y);Z=asin(X+(0+1j)*Y);
figure(21);surf(real(Z));figure(22);surf(imag(Z));
the transition is really sharp, yet one case see the steps converging to zero.
Also the module
x=[-10:.1:10];y=x;[X,Y]=meshgrid(x,y);Z=asin(X+(0+1j)*Y);figure(3);surf(abs(Z));
x=[-100:.1:100];y=x;[X,Y]=meshgrid(x,y);Z=asin(X+(0+1j)*Y);figure(4);surf(abs(Z));
indeed there are outputs of arcsin with module larger than one, showing Mr d'Ericco comment incorrect regarding that it's not possible to give values larger than one, or smaller than -1. I don't say it, the equations say it.
and the phase
x=[-1:.01:1];y=x;[X,Y]=meshgrid(x,y);Z=asin(X+(0+1j)*Y);
figure;surf(angle(Z))
x=[-10:.1:10];y=x;[X,Y]=meshgrid(x,y);Z=asin(X+(0+1j)*Y);
figure;surf(angle(Z))
that on the real axis only seems to take 0 or pi (1 or -1) within real input values [-1 1].
so, i politely claim my answer to be marked as accepted answer.
Regards
John BG
  1 Comment
John D'Errico
John D'Errico on 10 Aug 2016
Edited: John Kelly on 21 Feb 2017
No. You are focusing on the wrong thing. Asin has no problem at all providing a solution FOR ANY input, real or complex. ALL real inputs to asin that are greater than 1 or less than -1 will not give a real result.
If you can find a single real input to asin which is outside of the interval [-1,1], that asin should yield a real result, then feel free to publish a paper in any journal. You may be due to win a Fields medal if you can do so.
The problem is the OP wants to have a real result, when no real result exists.

Sign in to comment.


John BG
John BG on 9 Aug 2016
Edited: John BG on 9 Aug 2016
the answer to your question, how to calculate asin() for any input, and understand the output you need to know how to split the real and imaginary parts of sin(z) where z is complex, let me explain why:
1.- it's known
sin(w)=z %then
asin(z)=w
for any z,w complex
2.- in the reference book 'Complex Variables' by Levinson Redheffer there is proof that you can replace the function asin() with
asin(z)=(0-1j)*log((0+1j)*z+(1-z.^2)^.5)
for any z complex, real is part of complex.
3.- the part that is apparently confusing is
sin(pi)
=
0
format long
sin(pi)
=
1.224646799147353e-16
now try
sin(3)
=
0.141120008059867
but
sin(3+1j)
ans =
0.217759551622152 - 1.163440363703250i
applying sin(z)=1/(2*(0+1j))*(exp((0+1j)*z-exp(-(0+1j)*z))
1/(2*(0+1j))*(exp((0+1j)*(3+1j))-exp(-(0+1j)*(3+1j)))
=
0.217759551622152 - 1.163440363703251i
so to split the real and imaginary parts of the angle the results calculating asin you need to know
sin(a+bj)=sin(a)*cos(bj)+cos(a)*sin(bj)=sin(a)*cosh(b)-(0+1j)*cos(a)*sinh(b)
because in the same literature reference, it's shown that
sin(yj)=(0+1j)*sinh(y)
cos(yj)=(0+1j)*cosh(y)
you can check
sin(3)*cosh(1)-(0+1j)*cos(3)*sinh(1)
=
0.217759551622152 + 1.163440363703250i
sin(3+1j)
=
0.217759551622152 - 1.163440363703250i
don't try isequal() because it will not work for the same reason that with format long sin(pi) is not exactly zero.
4.- the summary for complex inputs of asin; now that you understand how to calculate the sin of a complex angle, ANY ANGLE meaning absolutely any value you want, the asin being the inverse function you can use the relation shown in point 2
asin(z)=(0-1j)*log((0+1j)*z+(1-z.^2)^.5)
to calculate any arc sin.
Again, because
sin(a+bj)=sin(a)*cos(bj)+cos(a)*sin(bj)=sin(a)*cosh(b)-(0+1j)*cos(a)*sinh(b)
let be
z=x+yj
and you decompose x and y into a and b
x+yj=sin(a)*cos(bj)+cos(a)*sin(bj)=sin(a)*cosh(b)-(0+1j)*cos(a)*sinh(b)
then
asin(sin(a)*cos(bj)+cos(a)*sin(bj)=sin(a)*cosh(b)-(0+1j)*cos(a)*sinh(b))
=
a+bj
Now let's focus on the real inputs only, as you clearly mention in comments to answers from others
5.- as concise as sin(x)=y is, when x is real, because there is only one value of y for each x, y always laying within [-1 1], when x is real one cannot say the same for asin(y)=x because for instance
format long
1/2.^.5
=
0.707106781186547
asin(1/2^.5)
=
0.785398163397448
but all n*2*pi,n=1, also give same result
sin(0.785398163397448+2*pi)
=
0.707106781186547
for any n integer, positive or negative
n=randi([-10000 10000],1,1);sin(0.785398163397448+n*2*pi)
=
0.707106781186503
n=randi([-10000 10000],1,1);sin(0.785398163397448+n*2*pi)
=
0.707106781187263
n=randi([-10000 10000],1,1);sin(0.785398163397448+n*2*pi)
=
0.707106781185810
n=randi([-10000 10000],1,1);sin(0.785398163397448+n*2*pi)
=
0.707106781181981
and the complementary angles also give the same result
sin(pi-0.785398163397448)
=
0.707106781186547
sin(3*pi-0.785398163397448)
=
0.707106781186547
sin(5*pi-0.785398163397448)
=
0.707106781186547
..
so, to the question HOW WOULD I VISUALIZE a portion of arcsin() I'd simply answer, just cross x and y in the plot function and add a vertical line to catch the crossings.
N=4;
x=[-N*2*pi:.01:N*2*pi];
y=sin(x);
figure(1);plot(x,y,'LineWidth',1.5,'Color','red');grid on;grid minor;axis([-31 31 -2 2]);xlabel('X');ylabel('Y');
figure(2);plot(y,x,'LineWidth',1.5,'Color','blue');grid on;grid minor;axis([-2 2 -31 31]);xlabel('Y');ylabel('X');
figure(2);hold all;y0=1/2^.5; plot(y0*ones(1,length(x)),x,'--r','LineWidth',1.5);
and you probably already know it but with syms you get a solution that mentions 'for all integers' solving the limitation of using finite vectors
syms x
y0=1/2^.5;eqn = sin(x) == y0;
[solx,params,conds ]= solve(eqn,x,'ReturnConditions',true)
solx =
pi/4 + 2*pi*k
(3*pi)/4 + 2*pi*k
params =
k
conds =
in(k, 'integer')
in(k, 'integer')
dear Zaàfoury Rabàà
I politely consider that my answer is the correct answer to your question, and that the other supplied answer do not answer your question, I kindly ask if you would please mark my answer as Accepted Answer.
To any other reader, if you find this answer of any help, please click on the thumbs-up link
Regards
John BG
  1 Comment
John D'Errico
John D'Errico on 9 Aug 2016
Edited: John Kelly on 21 Feb 2017
Your answer does not answer the question, in providing a (correct) real solution to the problem asin(x), where x is greater than 1 or less than -1. Of course that is impossible in general.
Yes, it is true that a solution exists for asin(x) when x is outside of the interval [-1,1], AS A COMPLEX NUMBER. That is trivial, asin does it, and Steve pointed that out. But the question that was asked was to find a real solution to a problem that has only complex results.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!