#### S-LifeLover

##### Junior Member level 1

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);
```