problems of this function

1 回表示 (過去 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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by