Error: Inner matrix dimensions must agree.

[EDIT: Fri Jun 10 17:09:13 UTC 2011 - Reformat - MKF]
My Code
chuky=240*10^-6;
biendo=24;
k=[1:20];
omega=2*pi/chuky;
omega1=omega*k;
a0=2*chuky/pi;
a1=chuky*biendo./((k+1)*pi);
a2=2*sin((k+1)*pi/2);
a3=chuky*biendo./((k-1)*pi);
a4=2*sin((k-1)*pi/2);
ak=a1.*a2+a3.*a4;
t=[-0.0005:0.000001:0.0005];
u10=a0;
for i=1:10;
u10=u10+ak(i)*cos(i*omega1*t);
end
plot(t,u10);
My error
Error in ==> ltm2 at 25
for i=1:10;u10=u10+ak(i)*cos(i*omega1*t);end;

답변 (1개)

Matt Fig
Matt Fig 2011년 6월 10일

0 개 추천

omega1 is 1x20
t is 1x1001
How do you recommend to multiply them??
You could use this:
u10 = a0 + sum(bsxfun(@times,ak,cos(bsxfun(@times,omega1,t.'))),2)
but because a3 divides by zero, you introduce a nan which propigates through the whole array...

이 질문은 마감되었습니다.

태그

질문:

2011년 6월 10일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by