Effacer les filtres
Effacer les filtres

problems of this function

2 vues (au cours des 30 derniers jours)
HADIMARGO
HADIMARGO le 14 Déc 2018
Rouvert : HADIMARGO le 18 Déc 2018
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?

Réponse acceptée

Jan
Jan le 14 Déc 2018
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.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by