I began with a set of coordinates, which I then approximated a function to represent them (Fourier series). The function produced is a sum of sin and cos waves:
0.3sin(2x) + 1.7(sin5x) + 1.8(sin43x)...
I would like to take this new function that I generated and produce a new set of coordinates. How can I generate points for every [INTEGER X Value] say from 0-400?
Note: I have 2 complex (2D) functions.
GOAL: Take a function --> Generate Points from this function for every whole integer.
This uses a function handle and (:)
to force a column vector ((:).'
forces a row vector).
The code simply uses the given equation (summing sines and cosines) to calculate a corresponding y coordinate for each given x coordinate.
% MATLAB R2018b
X = 0:400; % x = 0, 1, 2, ..., 400
fh = @(x) 0.3*sin(2*x) + 1.7*sin(5*x) + 1.8*sin(43*x);
Y = fh(X);
P = [X(:) Y(:)];
Note that size(P)
returns 401 x 2. You'll see Y
takes on whatever size X
is, which is a row vector. X
can be declared as as column vector with X = (0:400).'
using .'
which performs a transpose.
Recommend taking a look at MATLAB's documentation, specifically the Getting Started and Language Fundamentals.