Need help to plot a function
이전 댓글 표시
Hi, I'm a beginner Matlab user and I'm trying (for the first time) plot a function. But for some reason the program do not plot. I cant find the error.
N = 6;
tau = [-150:150]/100;
Xquad = ones(1,301)*1/(16*(pi^2));
A = zeros(1,301);
for n = 1:1:N
A = (4*sin(n*(pi)./(4*tau)))/((n^2)*(pi^2)*(((4*(pi^2) - (n^2)*(4*(pi^2)))./(tau^2))^2 + (16/100)*(n^2)*(4*(pi^2)./(tau^2)))) ;
Xquad = Xquad+ A;
end
Xrms = sqrt(Xquad);
plot(tau, Xrms);
답변 (1개)
Friedrich
2011년 4월 8일
Hi Pedro,
I think you missed some dots in your code, e.g.
tau^2
will not work since tau is a vector. You have to use
tau.^2
instead. The following modified code works for me
N = 6;
tau = [-150:150]/100;
Xquad = ones(1,301)*1/(16*(pi^2));
A = zeros(1,301);
for n = 1:1:N
A = (4*sin(n*(pi)./(4*tau)))./((n^2)*(pi^2)*(((4*(pi^2) - (n^2)*(4*(pi^2)))./(tau.^2)).^2 + (16/100)*(n^2)*(4*(pi^2)./(tau.^2)))) ;
Xquad = Xquad+ A;
end
Xrms = sqrt(Xquad);
plot(tau', Xrms');
I hope this helps,
Friedrich
카테고리
도움말 센터 및 File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!