f

#### What is the difference between (x^2+y^2) and (x.^2+y.^2) in matlab?

```z=sqrt(x^2+y^2)
c=(z<15)
imshow(c)
gives a square cut diagonally half with lower right side being white and other being black

z=sqrt(x.^2+y.^2)
c=(z<15)
imshow(c)
gives a square with circle in centre

What is the difference between (x^2+y^2) and (x.^2+y.^2) in matlab?
```
 0
Sagar
1/29/2016 1:33:04 AM
comp.soft-sys.matlab 211264 articles. 26 followers. lunamoonmoon (257) is leader.

1 Replies
2008 Views

Similar Articles

[PageSpeed] 8

```"Sagar Chand" <sagarchand_9@rediffmail.com> wrote in message <n8efgg\$100\$1@newscl01ah.mathworks.com>...
> z=sqrt(x^2+y^2)
> c=(z<15)
> imshow(c)
> gives a square cut diagonally half with lower right side being white and other being black
>
> z=sqrt(x.^2+y.^2)
> c=(z<15)
> imshow(c)
> gives a square with circle in centre
>
> What is the difference between (x^2+y^2) and (x.^2+y.^2) in matlab?

The ^ operator (without the period) is matrix power.  The .^ operator (with the period) is element-by-element power.  Hence you will get different results if x or y are not scalar.

James Tursa
```
 0
James
1/29/2016 2:12:03 AM