How to plot a smooth graph?

조회 수: 3 (최근 30일)
donghun lee
donghun lee 2020년 4월 2일
댓글: donghun lee 2020년 4월 2일
clc,clear all
b0 = 0.015;
b1 = 0.015;
b2 = 0.035;
b3 = 0.050;
v = 40; %velocity
L = 2;
w = (2*pi*v)/L; %angular frequency
F = w*(1/(2*pi)); %in Hz
t = linspace(0,10,18);
b = b0 + b1*sin(w*t) + b2*sin(2*w*t)
+b3*sin(3*w*t);
plot(t,b)
Hi, I want to make this graph as being a smooth graph.
Thank you for your time.
  댓글 수: 1
Rik
Rik 2020년 4월 2일
Although you could resample your function to draw a smooth curve through your data points, that would not accurately describe your function. You can greatly increase the number of points in your t vector to see that you have an enormous amount of aliasing going on here. See this Wikipedia page for more information.

댓글을 달려면 로그인하십시오.

채택된 답변

Birdman
Birdman 2020년 4월 2일
편집: Birdman 2020년 4월 2일
You need to increase the step size of your t vector:
t = linspace(0,10,100);
Code:
b0 = 0.015;
b1 = 0.015;
b2 = 0.035;
b3 = 0.050;
v = 40; %velocity
L = 2;
w = (2*pi*v)/L; %angular frequency
F = w*(1/(2*pi)); %in Hz
t = linspace(0,10,100);
b = b0 + b1*sin(w*t)+b2*sin(2*w*t)+b3*sin(3*w*t);
plot(t,b)
  댓글 수: 5
Rik
Rik 2020년 4월 2일
That is why I suggested to zoom in. The weirdness is not from me, but actually from your function. If you want a true plot of your function you should increase the number of samples until further increasing it no longer changes your graph. For this function that starts at about 2500 samples. With about 10000 samples I no longer notice an improvement in smoothness.
You could avoid having to do this yourself by using fplot:
b0 = 0.015;
b1 = 0.015;
b2 = 0.035;
b3 = 0.050;
v = 40; %velocity
L = 2;
w = (2*pi*v)/L; %angular frequency
F = w*(1/(2*pi)); %in Hz
t_max=10;
b_fun =@(t) b0 + b1*sin(w*t)+b2*sin(2*w*t)+b3*sin(3*w*t);
fplot(b_fun,[0 t_max])
axis([0 1 -0.125 0.125])%zoom in to see detail
donghun lee
donghun lee 2020년 4월 2일
Ah!! Thank you soooo much for your help. I got what you mean now! I really appreciate it.
Thank you for your time again Rik!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2020년 4월 2일
t = linspace(0,10,18);
Increase the 18 to something larger, such as 50.
  댓글 수: 1
donghun lee
donghun lee 2020년 4월 2일
Thank you very much for your comment.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by