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?
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 .).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With