- 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 回表示 (過去 30 日間)
古いコメントを表示
Paul Velasco
2019 年 11 月 10 日
コメント済み: Paul Velasco
2019 年 11 月 10 日
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 件のコメント
採用された回答
Thiago Henrique Gomes Lobato
2019 年 11 月 10 日
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);
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Number Theory についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!