Want to plot this function: y=1/(x^2-1)
>> x = -3:0.1:3;y = 1/(x.^2-1);
??? Error using ==> mrdivide
Matrix dimensions must agree.
>> x = -3:0.1:3;y = 1/(x^2-1);
??? Error using ==> mpower
Matrix must be square.
>> x = -3:0.1:3;y = (x^2-1);
??? Error using ==> mpower
Matrix must be square.
>> x = -3:0.1:3;y = (x.^2-1);
works...
but, how to plot y=1/(x^2-1)?
OK, here is the right answer, we need to add dot before divide operator, too
x = -3:0.1:3;y = 1./(x.^2-1);
analysis:
x = -3:0.1:3; -> makes x a array of size 1x31
m = (x.^2-1); -> makes m a array of size 1x31,too
so, we do need add dot before divide operator ./, then y will be a array of size 1x31
some comment on http://www.experts-exchange.com/Programming/Languages/MatLab/Q_23558168.html
Error using ==> mpower . Matrix must be square
When 'x' is a vector or a matrix, just writing something like x^2, makes matlab think you want to square a matrix, which is only possible with square matrices. If you have a row vector, then you have a 1 x N matrix, so unless N = 1, you don't have a square matrix, and you get an error. If you merely want to square each entry in x, then you use the " .^ " operator to indicate point-by-point operations (such as division, multiplication, or raising to a power). Whether you need the "dot" before the symbol (/ * or ^) depends on what you're doing. From the looks of it to me, you need the dot if you have a row vector that you only want to use to simulate continuous time.
2010-11-16 11:01:40
------------------------------------------------------------------------------------------------------------------分界线
如何用plot画竖直线
in matlab how to use plot to draw a vertical line
plot([x1,x2],[y1,y2]);
this can draw a line from (x1,y1) to (x2,y2)
if you want to draw a vertical line
then make x1=x2;
the horizontal line is the same;