Code for an equation
2 次查看(过去 30 天)
显示 更早的评论
I want to plot y = (3.5^(-.5x))*cos(6x) for x= -2 to x= 4 with interval of 0.01 without using for loop.
Following is the code I am writing:
clc
x = [-2:.01:4];
y = (3.5.^(-.5*x))*(cos(6*x));
plot(x,y);
But I recieve this error
Error using *
Inner matrix dimensions must agree.
0 个评论
采纳的回答
Aviel Moos
2019-7-23
编辑:Aviel Moos
2019-7-23
You need to use elementwise multimplication.
let look at this:
A = (3.5.^(-.5*x)); % Here you will get a vector with 601 elements
B = (cos(6*x)); % Here you will get also a vector with 601 elements
You cannot just multiply, You need to multiplay each element in place K of A with element in place K of B.
So just replace:
y = (3.5.^(-.5*x))*(cos(6*x));
with this:
y = (3.5.^(-.5*x)).*(cos(6*x));
更多回答(2 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!