필터 지우기
필터 지우기

problems of this function

조회 수: 2 (최근 30일)
HADIMARGO
HADIMARGO 2018년 12월 14일
다시 열림: HADIMARGO 2018년 12월 18일
i want to draw this function
but my code has an error:
code:
x=linspace(-5,5,1000);
n=double(1:1:100);
l=2;
f=sin(x);
g=cos(x);
s=0;
landa=((n*pi)/l );
a=(2/l)*int(f.*sin((n*pi)/l)*x,0,l);
b=(2/(l*landa))*int(g*sin((n*pi*x)/l,0,l));
for n=1:1:1000
p=((a*cos(landa*t)+ b*sin(landa*t))*sin((n*pi*x)/l));
s=s + p;
end
plot (x,t,s)
error:
>> f1
Matrix dimensions must agree.
Error in f1 (line 8)
a=(2/l)*int(f.*sin((n*pi)/l)*x,0,l);
where is the problem of this error and code?

채택된 답변

Jan
Jan 2018년 12월 14일
Use the debugger to find the problem. Type this in the command window:
dbstop if error
Then run the code again until it stops at the error. Now split the command into parts and check them in the command window:
% a = (2 / l) * int(f .* sin((n * pi) / l) * x, 0, l);
size(2 / l)
size((n * pi) / l)
size(sin((n * pi) / l) * x) % I assume this fails
size(f)
size(f .* sin((n * pi) / l) * x)
This method let you identify, which part causes the error message. This should help you to fix the problem.
It looks strange that you define n as vector at first and use it a loop index again. I guess you want to calculate the integrals inside the loop.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by