y[n] = 3*2/3^n*cos(pi)

2 次查看(过去 30 天)
Lieke
Lieke 2022-12-7
I want to plot the function above. If i only fill in 3*2/3^n it works and also only cos(pi) works but when i put them in as 3*2/3^n*cos(pi) it doesn't work.
The error:
Error using ^
Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a scalar. To operate on each element of the matrix individually, use POWER (.^) for elementwise power.
Error in Practicum_3_Matlab (line 32)
y8 = 3*2/3^n*cos(pi*n+0);

回答(1 个)

Praveen Thota
Praveen Thota 2022-12-28
Hi,
I understand that you want to plot a custom function but encountering an error message.
Use of element-wise operators for power and division should resolve the issue.
The function should be written like this
>> y = 3*2./3.^n*cos(pi);
You can also refer to the element-wise operations MathWorks Documentation for further reference

类别

Help CenterFile Exchange 中查找有关 Axes Appearance 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by