Question

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 above equation y = (2*x)/sqrt( 1 + x.^2 ); giving a single value and not a vector of values?

Was it helpful?

Solution

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 .).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top