When I run the below code, why dont I get value of Q=[ 2 3]

1 visualizzazione (ultimi 30 giorni)
In the equation y=sin(2x + 3) , a=2 and b=3 (general form y=sin(a*x + b)). When I run the following code why don't I get Q=[2 3] .
x=(0:0.01:2*pi);
y=sin(2*x + 3);
for i=1:62
P=[x(i) 1;
x(i+1) 1];
R=[asin(y(i));
asin(y(i+1))];
Q=R\P % %Q=[a b];
end

Risposta accettata

James Tursa
James Tursa il 1 Mar 2018
Modificato: James Tursa il 1 Mar 2018
Your fundamental problem is that asin( ) is multi-valued and you are treating it as single-valued. To recover the 2 and 3, you would need to know ahead of time exactly which of these multi-values that you want, and you don't. And which of these multi-values you want will of course change as you go through the sin( ) cycles. E.g., to recover the 2 and 3 from the first pair you would need to do this:
x = (0:0.01:2*pi);
y = sin(2*x + 3);
P = [x(1) 1; x(2) 1];
Q = P \ [pi-asin(y(1));pi-asin(y(2))]
Q =
2.000000000000002
3.000000000000000
But the form I chose for the "R" part was specific to the range of the result that I wanted to get.
Picking your formulation we get this:
Q = P \ [asin(y(1));asin(y(2))]
Q =
-2.000000000000000
0.141592653589793
But these are legitimate results also, just in a different range. E.g., using this Q to see if they work:
>> sin(Q(1)*x(1)+Q(2)) - y(1)
ans =
0
>> sin(Q(1)*x(2)+Q(2)) - y(2)
ans =
0
Yep, they work.
Bottom line is you can't recover your original a and b constants using this method because you don't have enough information about which asin( ) result is needed.
(Plus, you had a typo anyway ... your Q = R\P should have been Q = P\R)

Più risposte (0)

Categorie

Scopri di più su Special Functions in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by