Operation returns a scalar value when a vector of values is expected
I'm evaluating a simple function:
y = (2*x)/sqrt( 1 + x.^2 );
Where x
is a vector with about 100 values in it. However, MATLAB makes y
equal to a single scalar value in this instance. If I do:
y = 2*x;
I get a vector of values in y
as expected. If I do:
y = x.^2;
I also get a vector of values in y
as expected.
Why is the abov开发者_开发百科e equation y = (2*x)/sqrt( 1 + x.^2 );
giving a single value and not a vector of values?
The operation B/A
(given B = 2*x
and A = sqrt(1+x.^2)
) will attempt to perform matrix right division, which for a row vector x
will be the solution in the least squares sense to the system of equations yA = B
, which results in a scalar value for y
.
For element-wise array division, perform the operation B./A
instead (note the .
).
精彩评论