Hello all,
I have a Matlab homework problem that I'm struggling a little bit with. I would post this under the "Homework" board but that is categorized under "Electronics" and isn't very fitting.
Here is the question:
Here is my .m file:
Here are the results:
Whats wrong?! I thought all my math was being done element wise (with the .* and ./ instead of * and /), so why is it complaining about matrix dimensions?
I have a Matlab homework problem that I'm struggling a little bit with. I would post this under the "Homework" board but that is categorized under "Electronics" and isn't very fitting.
Here is the question:
Here is my .m file:
Rich (BB code):
function [y] = lab10(T,sclr)
wd = sqrt(1.-(sclr.^2));
we = 1-(2.*sclr.^2);
y = exp((-1.*sclr).*T).*(2.*sclr.*cos(wd.*T)+(we./wd).*sin(wd.*T));
Rich (BB code):
>> T=[0:pi/10:4*pi]
T =
Columns 1 through 8
0 0.3142 0.6283 0.9425 1.2566 1.5708 1.8850 2.1991
Columns 9 through 16
2.5133 2.8274 3.1416 3.4558 3.7699 4.0841 4.3982 4.7124
Columns 17 through 24
5.0265 5.3407 5.6549 5.9690 6.2832 6.5973 6.9115 7.2257
Columns 25 through 32
7.5398 7.8540 8.1681 8.4823 8.7965 9.1106 9.4248 9.7389
Columns 33 through 40
10.0531 10.3673 10.6814 10.9956 11.3097 11.6239 11.9381 12.2522
Column 41
12.5664
>> sclr=[0,.2,.3,.4,.5]
sclr =
0 0.2000 0.3000 0.4000 0.5000
>> lab10(T,sclr)
??? Error using ==> times
Matrix dimensions must agree.
Error in ==> lab10 at 4
y = exp((-1.*sclr).*T).*(2.*sclr.*cos(wd.*T)+(we./wd).*sin(wd.*T));