Code covered by the BSD License  

Highlights from
Kronecker Delta

2.33333

2.3 | 3 ratings Rate this file 16 Downloads (last 30 days) File Size: 1.24 KB File ID: #26485

Kronecker Delta

by Richard Rieber

 

26 Jan 2010

Given 2 subscripts, j & k, KronD will return 1 if j == k and 0 if j != k.

| Watch this File

File Information
Description

Given 2 subscripts, j & k, KronD will return 1 if j == k and 0 if j != k.

A very simple function with only a single if-else statement. Saves a bit of typing when the Kronecker Delta is needed.

MATLAB release MATLAB 7.6 (R2008a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (5)
26 Jan 2010 Jos (10584)

j==k is shorter!

Too simple and too inefficient ...

26 Jan 2010 Matt Fig

eq(j,k) does the same thing. If you are looking for a function which takes arguments, as opposed to an operator (i==j), why not use the built-in?

30 Jan 2010 Rody Oldenhuis

I think this sort of simple little thing does have significant use; it brings programming in ML closer to mathmatical notation. For example, why use csc(x) in stead of just 1./sin(x)? Because it's shorter and more clear. Why invent something like isvector(x) in stead of using any(size(x)==1) (+additional checks if you expect more dimensions)? Because it's another small little thinking step you can skip while reading code, making that code much more readable.

But only two stars for this version I'm afraid...indeed d=j==k is much shorter (and faster). Moreover, your function explicitly says d = 1; etc., which makes class(d) double i.s.o. logical. Also, you could use error(nargchk(2,2,nargin)) to do everything your entire error-check block does.

01 Sep 2011 John Wang  
21 Nov 2011 Chandana

Thanks Richard.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
kronecker delta Richard Rieber 26 Jan 2010 14:13:43
mathematics Richard Rieber 26 Jan 2010 14:13:43
kronecker delta Abraham 08 Oct 2011 15:43:32

Contact us at files@mathworks.com