Why is my plot shaking but not plotting the noise?

12 views (last 30 days)
clear;
clc;
for x = 0:(pi/200):(2*pi)
e = rand;
y = x*sin(x)+(0.5*e);
x_star = [0:(pi/200):(2*pi)].';
y_star = x_star.*sin(x_star)+0.5*e;
figure(1)
plot(x_star,y_star)
grid on
title('Hw1');
xlabel('x');
ylabel('f(x)');
end

Accepted Answer

Arif Hoq
Arif Hoq on 16 Feb 2022
Edited: Arif Hoq on 16 Feb 2022
x = 0:pi/200:(2*pi);% does't need
e = rand; % does't need
y = x.*sin(x)+(0.5*e); % does't need
x_star = 0:(pi/200):(2*pi); % x_star and x same
y_star = x_star.*sin(x_star)+0.5*rand(size(x_star)); % adding noise 0.5*rand(size(x)) y_star and y same
figure(1)
plot(x_star,y_star)
grid on
title('Hw1');
xlabel('x');
ylabel('f(x)');
  2 Comments
Arif Hoq
Arif Hoq on 16 Feb 2022
Or simply
x = 0:pi/200:(2*pi);
e = 0.5*rand(size(x)); % noise
y = x.*sin(x)+e;
figure(1)
plot(x,y)
grid on
title('Hw1');
xlabel('x');
ylabel('f(x)');

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!