필터 지우기
필터 지우기

ploting in for loop

조회 수: 1 (최근 30일)
Ahmet Oguz
Ahmet Oguz 2016년 11월 13일
편집: Ahmet Oguz 2016년 11월 15일
I wrote sum which is xs for below calculation There is something wrong with my code below that i can not figure it out?
clc
t=cputime;
k=0;
for p=1:1:7
dt=10^-p;
k=0:1.35/dt;
xs = 2/(sqrt(pi))*sum(exp(-(k*dt).^2)*dt)
e=cputime-t;
semilogx(e,dt)
end

채택된 답변

Walter Roberson
Walter Roberson 2016년 11월 14일
Try this:
k=0;
for p=1:1:7
t=cputime;
dt(p)=10^-p;
k=0:1.35/dt(p);
xs = 2/(sqrt(pi))*sum(exp(-(k*dt(p)).^2)*dt(p))
e(p)=cputime-t;
end
semilogx(1./dt, e)
You were plotting timestep as if it were a consequence of execution time. Also, as p increases, dt decreases, so if you plot dt then it is getting smaller and smaller and so your datapoints were getting further left, which is more difficult for people to understand. If you plot against 1./dt then you are plotting time as a consequence of number of data samples used, which is much more natural for people.
  댓글 수: 1
Ahmet Oguz
Ahmet Oguz 2016년 11월 14일
Thanks i figure it out now.

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

추가 답변 (1개)

Daniel kiracofe
Daniel kiracofe 2016년 11월 13일
편집: Daniel kiracofe 2016년 11월 13일
"there is something wrong" is pretty vague, so I'm totally guessing at what your problem is. But this seems like a reasonable guess. If this doesn't answer you question then you need to post more detail about what is your specific problem.
clc
t=cputime;
k=0;
for p=1:1:7
dt(p)=10^-p;
k=0:1.35/dt(p);
xs = 2/(sqrt(pi))*sum(exp(-(k*dt(p)).^2)*dt(p))
e(p)=cputime-t;
end
semilogx(e,dt)
  댓글 수: 2
Ahmet Oguz
Ahmet Oguz 2016년 11월 14일
same mistake accured there is no graph
Walter Roberson
Walter Roberson 2016년 11월 14일
I would make a small change, and move the
t=cputime;
to inside the for p loop. Otherwise you are getting cumulative time since you started, instead of time for that particular refinement.

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

카테고리

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

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by