Clear Filters
Clear Filters

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

2 views (last 30 days)
Lieke
Lieke on 7 Dec 2022
Answered: Praveen Thota on 28 Dec 2022
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);

Answers (1)

Praveen Thota
Praveen Thota on 28 Dec 2022
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

Categories

Find more on Axes Appearance in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!