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);

Réponses (1)

Friedrich
Friedrich le 8 Avr 2011

1 vote

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

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by