Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 523
bobobobo Avatar asked Dec 15 '25 09:12

bobobobo


1 Answers

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

like image 74
gnovice Avatar answered Dec 17 '25 08:12

gnovice



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!