- #1

- 690

- 33

## Main Question or Discussion Point

Hi

Could you please help me to fix the code below? I know that the code is completely wrong but I have tried to write it down so that you can get an idea what I'm trying to do. Thank you.

Could you please help me to fix the code below? I know that the code is completely wrong but I have tried to write it down so that you can get an idea what I'm trying to do. Thank you.

Code:

```
%%file name fourier.m
clear all; close all; clc;
f = 0; %% 0 Hz to 100 Hz, with 0.1 step, there would be 1000 frequencies
cos_v=[1:1:1000]; %%vector to store values
f_w=[]; %% defining a vector
for i1=[0:1000]; %% for loops begins, with loop index i1
f_w = sqrt(1/(4*f));
cos_v(i1)=f_w*cos(2*pi*f*x); %% i1 serves as an index for cos_v vector elements too
f=f+0.1;
end
combined_sinusoids=sum(cos_v); %% cos_v(1)+cos_v(2)+cos_v(3)+...
x = [0:0.2:500];
y = combined_sinusoids;
plot(x, y)
```