- 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일)
이전 댓글 표시
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!