- You don't need to declare numerical values with syms
- your variable sum is the same as the function sum for matlab, this can cause many problems
- (This is what prevent your code to run) your t is a vector, so you actually don't need to make a for loop for each time point since sum will already be a vector, otherwise you try to put a vector in a single variable spot and thus you get the wrong size problem
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Paul Velasco
il 10 Nov 2019
Commentato: Paul Velasco
il 10 Nov 2019
Hi im currently a student and not very good at matlab (or coding in general). Im trying to run this code but keep getting this error mesage. Thank you in advance.
syms t T p
T=input('what is the period');
p=input('how many coefficients');
t=linspace(0,3*T,100);
N=10;
bp=sin(80)/320 - cos(80)/4;
ap=sin(80)/4 - sin(40)^2/160;
for i=1:100
sum=0;
for p=1:N
sum=(sum+(N*ap*cos(2*pi*p*t/T))+(N*bp*sin(2*pi*p*t/T)));
end
F(i)=sum;
end
figure(1);
plot(t,F);
0 Commenti
Risposta accettata
Thiago Henrique Gomes Lobato
il 10 Nov 2019
This version of your code should work:
T=input('what is the period');
p=input('how many coefficients');
t=linspace(0,3*T,100);
N=10;
bp=sin(80)/320 - cos(80)/4;
ap=sin(80)/4 - sin(40)^2/160;
sum=0;
for p=1:N
Sum=(Sum+(N*ap*cos(2*pi*p*t/T))+(N*bp*sin(2*pi*p*t/T)));
end
F=Sum;
figure(1);
plot(t,F);
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Number Theory in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!