matlab编程问题?Error using ==> mtimes Inner matrix dimensions must agree.t=0:0.01:10;x=2*t; y=1-exp(-0.5*t)*cos(x); Error using ==> mtimesInner matrix dimensions must agree.只要cos里面是2*t就会有这问题,如果仅仅是2就没问题.为

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/18 18:26:46
matlab编程问题?Errorusing==>mtimesInnermatrixdimensionsmustagree.t=0:0.01:10;x=2*t;y=1-exp(-0.5*t)*cos(x

matlab编程问题?Error using ==> mtimes Inner matrix dimensions must agree.t=0:0.01:10;x=2*t; y=1-exp(-0.5*t)*cos(x); Error using ==> mtimesInner matrix dimensions must agree.只要cos里面是2*t就会有这问题,如果仅仅是2就没问题.为
matlab编程问题?Error using ==> mtimes Inner matrix dimensions must agree.
t=0:0.01:10;
x=2*t;
y=1-exp(-0.5*t)*cos(x);
Error using ==> mtimes
Inner matrix dimensions must agree.
只要cos里面是2*t就会有这问题,如果仅仅是2就没问题.为什么?题目要求是2t的,要怎么改?

matlab编程问题?Error using ==> mtimes Inner matrix dimensions must agree.t=0:0.01:10;x=2*t; y=1-exp(-0.5*t)*cos(x); Error using ==> mtimesInner matrix dimensions must agree.只要cos里面是2*t就会有这问题,如果仅仅是2就没问题.为
改成
y = 1 - exp(-0.5*t) .* cos(x);
因为 t和x都是向量,exp结果是一个向量,cos也是向量,
所以用 .* 点乘,使得向量元素对应相乘.
如果用 * ,就导致当作两个数组相乘,数组相乘的要求相信你也知道,我就不多说了.