Solve simple sinusoidal equation

Status
Not open for further replies.

S-LifeLover

Junior Member level 1
Joined
Oct 5, 2012
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,464
Good day!
Please help me to solve a system of equations:

Code:
amplitude sin(phase) = 0
 
               /         pi frequency \ 
  amplitude sin| phase + ------------ | = -1/2 
               \              4       /
 
               /         pi frequency \ 
  amplitude sin| phase + ------------ | = 0 
               \              2       /




A simple example. However, I need an algorithmic solution that is suitable for any three points on the graph.
Our desired sine describes three unknown parameters: amplitude, frequency and phase. A system of equations can be solved, the number of unknowns is not less than the number of equations. The conclusion is that we can find the 3 parameters by 3 any points. However, I was not able to write code to do this. Can you help me?
Thank you in advance

- - - Updated - - -

Code:
clear all;
close all force;
clc;

syms x y frequency amplitude phase
f_sin = 'amplitude * sin(x * frequency + phase) = y';
f_sin_const = subs(f_sin, [frequency amplitude phase], [2 0.5 pi]);
ezplot(f_sin_const, [0, pi, -0.5, 0.5])
hold on;

%Calculate the 3 points
x_vals = [0, pi / 4, pi / 2];
y_vals = [];
temp = subs(f_sin_const, x, x_vals(1));
y_vals(1) = solve(temp, y);
temp = subs(f_sin_const, x, x_vals(2));
y_vals(2) = solve(temp, y);
temp = subs(f_sin_const, x, x_vals(3));
y_vals(3) = solve(temp, y);

plot(x_vals, y_vals, 'o', 'Color', 'Red');

equation1 = subs(f_sin, [x y], [x_vals(1) y_vals(1)]);
equation2 = subs(f_sin, [x y], [x_vals(2) y_vals(2)]);
equation3 = subs(f_sin, [x y], [x_vals(3) y_vals(3)]);

pretty(equation1);
pretty(equation2);
pretty(equation3);
 

This reminds me of the problem where you find the unique circle which contains all 3 points.

If you can transfer the 3 points on the sinewave, geometrically, to become 3 points on an x-y grid...

Then you might approach it as finding a circle containing all 3 points...

which would give you the sine formula, etc.
 

Is the variable "frequency" an integer? If so, the first and third equations are not independent; that is, sin(phase)=0 implies that sin(phase+(freq*pi))=0 for all integer values of 'freq', so the system is underdetermined. If you were assuming integer frequency, this system of equations will always be underdetermined.

Also: keep in mind that the periodicity of sine and cosine means that for non-integer frequency, there are an infinite number of solutions corresponding to alias frequencies. So the key to solving this is:

(a) stick to non-integer frequencies if applicable;
(b) decide what half-unit interval of frequencies applies.

In practical terms, (b) means describing the solution with an arc-sine function whose range you know, and offsetting/reflecting it to produce a solution in your acceptable interval. Since each half of the sine cycle is symmetrical about an odd multiple of pi/4, the alias solutions should be arranged in pairs of frequencies spaced <= 0.5 apart, separated by empty intervals of >= 0.5.

Could you describe the original problem you're trying to solve? I might be able to fully constrain the desirable solutions with more information.
 

If we have the general system of three equations:

A*sin(θ)=x
A*sin(θ+ω/M)=y
A*sin(θ+ω/N)=z

where x,y,z,M and N are known, since sin(a+b)=sin(a)*cos(b)+cos(a)*sin(b), then:

A*sin(θ)=x
A*sin(θ)*cos(ω/M)+A*cos(θ)*sin(ω/M)=y
A*sin(θ)*cos(ω/N)+A*cos(θ)*sin(ω/N)=z

substituting now the first one in the other two:

x*cos(ω/M)+sqrt(1-x²)*sin(ω/M)=y
x*cos(ω/N)+sqrt(1-x²)*sin(ω/N)=z

that are of the form a*sin(α)+b*cos(α) that is rewritable as c*sin(α+φ), so that:

a=c*cos(φ)
b=c*sin(φ)

then:

φ=arctg(b/a) and c=a/cos(φ)

applying this to the first of our two last equations:

φ=arctg(x/sqrt(1-x²)) and c=sqrt(1-x²)/cos(φ)

-----------------------
| ω=M*[arcsin(y/c)-φ] |
-----------------------

dividing now the two equation one each other:

A*sin(θ)*cos(ω/M)+A*cos(θ)*sin(ω/M).....y
---------------------------------------- = --
A*sin(θ)*cos(ω/N)+A*cos(θ)*sin(ω/N).....z

from which:

z*sin(θ)*cos(ω/M)+z*cos(θ)*sin(ω/M) = y*sin(θ)*cos(ω/N)+y*cos(θ)*sin(ω/N)

dividing by cos(θ) and rearranging:

tg(θ)*[z*cos(ω/M)-y*cos(ω/N)]=y*sin(ω/M)-z*sin(ω/N)

then:

----------------------------------------------------------------
| θ = arctg{[y*sin(ω/M)-z*sin(ω/N)]/[z*cos(ω/M)-y*cos(ω/N)]} |
----------------------------------------------------------------

and

A=x/sin(θ)

Please check the calculations are correct since I didn't verified them
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…