Scilab erreur Multiplication Incoherente.

Résolu
keurdange Messages postés 816 Statut Membre -  
keurdange Messages postés 816 Statut Membre -
Bonjour,

Je voudrais tracer les fonctions suivantes mais il me dit qu'il y a une erreur de Multiplication à la ligne 12 (mis en gras et souligné ici). Aidez moi.

Merci d'avance.

S1=0;S2=0;S3=0;S4=0;S5=0;
function test(n,f,a,to)
T=1/f;
fo=1/to;
Te=T/100;
Fe=1/Te;
t=0:Te:5*T;
for P=0:n
s=((-1)^n/(2*n+1))*cos(2*%pi*(2*n+1)*fo*t);
S1=S1+s;
s=(1/(2*n+1))*sin(2*%pi*(2*n+1)*fo*t);
S2=S2+s;
s=(sinc(%pi*n*fo*t))*cos(2*%pi*n*fo*t);
S3=S3+s;
s=((-1)^n/(2*n+1)^2)*sin(2*%pi*(2*n+1)*fo*t);
S4=S4+s;
end
for M=1:n
s=(1/(4*(n^2)-1))*cos(4*%pi*n*fo*t);
S5=S5+s;
end
S1=((4*a)/%pi)*S1;
S2=((4*a)/%pi)*S2;
S3=((2*a*t)/to)*S3;
S4=((8*a)/(%pi)^2)*S4;
S5=((-2*a)/%pi)*S5;
xset('window',5);
subplot(5,2,1)
plot2d(t,S1)
xtitle('Representation temporelle','t','S1');
N1=length(S1);
S1f=fft(S1)/N1;
subplot(5,2,2)
plot2d(f,abs(S1f));
xtitle('Representation frequentielle','f','S1f')
subplot(5,2,3)
plot(t,S2)
xtitle('Representation temporelle','t','S2')
N2=length(S2);
S2f=fft(S2)/N2;
subplot(5,2,4)
plot2d3(f,abs(S2f))
xtitle('Representation frequentielle','f','S2f')
subplot(5,2,5)
plot2d(t,S3)
xtitle('Representation temporelle','t','S3')
N3=length(S3);
S3f=fft(S3)/N3;
subplot(5,2,6)
plot2d3(f,abs(S3f))
xtitle('Representation frequentielle','f','S3f')
subplot(5,2,7)
plot2d3(t,S4)
xtitle('Representation temporelle','t','S4')
N4=length(S4);
S4f=fft(S4)/N4;
subplot(5,2,8)
plot2d(f,abs(S4f))
xtitle('Representation frequentielle','f','S4f')
subplot(5,2,9)
plot2d3(t,S5)
xtitle('Representation temporelle','t','S5')
N5=length(S5);
S5f=fft(S5)/N5;
subplot(5,2,10)
plot2d3(f,abs(S5f))
xtitle('Representation frequentielle','f','S5f')
endfunction
xset('window', 6); //T=1/f=1/100=0.01 or to=T/8=0.01/8
test(3,100,3,0.00125);
xset('window', 7)
test(10,100,3,0.00125);
xset('window', 8)
test(50,100,3,0.00125);
xset('window', 9)
test(100,100,3,0.00125);



--
Dieu n'a fait qu'ébaucher l'homme, c'est sur terre que chacun se crèe

1 réponse

  1. KX Messages postés 19031 Statut Modérateur 3 020
     
    Quand tu fais t=0:Te:5*T; t est une matrice.
    Donc avec s=((-1)^n/(2*n+1))*cos(2*%pi*(2*n+1)*fo*t); s est alors une matrice aussi.
    Or S1 est un nombre, et on ne peut pas additionner un nombre et une matrice !

    Je pense que tu devrais mettre P à la place de t dans tes calculs de s. Il y a d'autres erreurs, mais je te laisse essayer de les corriger seuls selon ce que tu veux faire.

    PS : dans les forums sur CCM, de même qu'il y a les balises, gras, italique, et souligné, il y a les balises de code, ce qui est très pratique pour conserver l'indentation des programmes.
    N'hésite pas à t'en servir ;-)
    1
    1. keurdange Messages postés 816 Statut Membre 232
       
      mais le signal c'est genre sin(2pi*f*t). remplacer le t par p change toute la donne. y'aurait t-il pas un autre moyen?
      0
    2. keurdange Messages postés 816 Statut Membre 232
       
      function carre(n,fo,d)
      to=1/fo;
      pas=to/100;
      t=0:pas:d*to;
      s1=0;
      for k=0:n,
      a=4/%pi*sin(2*%pi*(2*k+1)*fo*t)/(2*k+1);
      s1=s1+a;
      end
      plot2d (t,s1)
      endfunction

      il ya t et ca marche
      0
    3. keurdange Messages postés 816 Statut Membre 232
       
      c'etait au niveau du S3 l'erreur. j'ai juste remplacé le premier t par taux.

      function test(n,f,a,to)
      T=1/f;
      to=T/8;
      fo=1/to;
      Te=T/100;
      Fe=1/Te;
      t=0:Te:5*T;
      S1=0;S2=0;S3=0;S4=0;S5=0; taux=100;
      for P=0:n
      s=((-1)^n/(2*n+1))*cos(2*%pi*(2*n+1)*fo*t);
      S1=S1+s;
      s=(1/(2*n+1))*sin(2*%pi*(2*n+1)*fo*t);
      S2=S2+s;
      s=(sinc(%pi*n*fo*taux))*cos(2*%pi*n*fo*t);
      S3=S3+s;
      s=((-1)^n/(2*n+1)^2)*sin(2*%pi*(2*n+1)*fo*t);
      S4=S4+s;
      end
      for M=1:n
      s=(1/(4*(n^2)-1))*cos(4*%pi*n*fo*t);
      S5=S5+s;
      end
      S1=((4*a)/%pi)*S1;
      S2=((4*a)/%pi)*S2;
      S3=((2*a*taux)/to)*S3;
      S4=((8*a)/(%pi)^2)*S4;
      S5=((-2*a)/%pi)*S5;
      xset('window',5);
      subplot(5,2,1)
      plot2d(t,S1)
      xtitle('Representation temporelle','t','S1');
      N1=length(S1);
      S1f=fft(S1)/N1;
      subplot(5,2,2)
      plot2d(f,abs(S1f));
      xtitle('Representation frequentielle','f','S1f')
      subplot(5,2,3)
      plot(t,S2)
      xtitle('Representation temporelle','t','S2')
      N2=length(S2);
      S2f=fft(S2)/N2;
      subplot(5,2,4)
      plot2d3(f,abs(S2f))
      xtitle('Representation frequentielle','f','S2f')
      subplot(5,2,5)
      plot2d(t,S3)
      xtitle('Representation temporelle','t','S3')
      N3=length(S3);
      S3f=fft(S3)/N3;
      subplot(5,2,6)
      plot2d3(f,abs(S3f))
      xtitle('Representation frequentielle','f','S3f')
      subplot(5,2,7)
      plot2d3(t,S4)
      xtitle('Representation temporelle','t','S4')
      N4=length(S4);
      S4f=fft(S4)/N4;
      subplot(5,2,8)
      plot2d(f,abs(S4f))
      xtitle('Representation frequentielle','f','S4f')
      subplot(5,2,9)
      plot2d3(t,S5)
      xtitle('Representation temporelle','t','S5')
      N5=length(S5);
      S5f=fft(S5)/N5;
      subplot(5,2,10)
      plot2d3(f,abs(S5f))
      xtitle('Representation frequentielle','f','S5f')
      endfunction
      xset('window', 6); //T=1/f=1/100=0.01 or to=T/8=0.01/8
      test(3,100,3,0.00125);
      xset('window', 7)
      test(10,100,3,0.00125);
      xset('window', 8)
      test(50,100,3,0.00125);
      xset('window', 9)
      test(100,100,3,0.00125);
      0
    4. Serge
       
      il faut remplacer
      s=(sinc(%pi*n*fo*t))*cos(2*%pi*n*fo*t);
      par
      s=(sinc(%pi*n*fo*t)).*cos(2*%pi*n*fo*t); //.* au lieu de * pour multiplier les elements de 2 vecteurs

      et
      S3=((2*a*t)/to)*S3;
      par
      S3=((2*a*t)/to).*S3; //.* au lieu de *
      0
    5. keurdange Messages postés 816 Statut Membre 232
       
      ok
      0