Borrar filtros
Borrar filtros

problems of this function

2 visualizaciones (últimos 30 días)
HADIMARGO
HADIMARGO el 14 de Dic. de 2018
Abierta de nuevo: HADIMARGO el 18 de Dic. de 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?

Respuesta aceptada

Jan
Jan el 14 de Dic. de 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.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by