Small Help in MatLap ( square matrix ? )

  • Thread starter Thread starter ahmedking
  • Start date Start date
  • Tags Tags
    Matrix Square
AI Thread Summary
The discussion revolves around a MATLAB coding issue where the user is trying to plot the discrete function x[n] = 0.7^n * u[n] for the range -5 < n < 17. The user encounters an error stating "Matrix must be square" due to improper use of the power operator. The solution involves using the element-wise power operator (.^) instead of the matrix power operator (^). Additionally, the variable u is incorrectly defined as a scalar (1) while it should represent an array, leading to further indexing issues with u(n). The correct approach requires defining u[n] properly, ensuring that n is an integer for indexing, and adjusting the code to plot the desired function accurately. A link to MATLAB documentation is provided for further assistance.
ahmedking
Messages
2
Reaction score
0
Small Help in MatLap ( square matrix ?!? )

>> n=-5:0.01:17;
>> u=1;
>> x=0.7^n*u(n);
? Error using ==> mpower
Matrix must be square.

how can i solve this problem

as iam a beginner in the matlap :)the main question is

plot the following discrete functions

1- x[n]=0.7^n*u[n] -5<n<17

please help me thanks in advance
 
Physics news on Phys.org


please help i need it urgently :)
 
ahmedking said:
how can i solve this problem

as iam a beginner in the matlap :)
I'm pretty sure you mean matlab.
ahmedking said:
>> n=-5:0.01:17;
>> u=1;
>> x=0.7^n*u(n);
? Error using ==> mpower
Matrix must be square.
Your variable n is an array, so you need to use the element-by-element power operator, which is .^

Also, you are setting u to 1 in the second line, above, but u appears to be an array in the third line. You're going to run into another problem with u(n), since the index of an array has to be an integer >= 1. IOW, the value of n must be an integer >= 1 in an expression u(n).

Here's a link to some documentation on MATLAB. I have found it to be pretty helpful.
http://www.mathworks.com/access/helpdesk/help/pdf_doc/matlab/getstart.pdf
ahmedking said:
the main question is

plot the following discrete functions

1- x[n]=0.7^n*u[n] -5<n<17

please help me thanks in advance
 
Back
Top