help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Arrays: Multidimensional manipulating


From: William Krekeler
Subject: RE: Arrays: Multidimensional manipulating
Date: Tue, 12 Apr 2011 16:33:53 +0000


-----Original Message-----
From: address@hidden [mailto:address@hidden On Behalf Of dirac
Sent: Tuesday, April 12, 2011 11:23 AM
To: address@hidden
Subject: Arrays: Multidimensional manipulating

Hi there,

I am having problems with a multidimensional array at the moment and have
looked online to see similar problems...

I basically have an equation

p = exp(-1*(a*(|k|^b)))

which I write:

p = exp(-1*abs(k).^b).

This is simple enough so far; if I want to vary a, k, and b, I could use for
loops or I could do it using a multidimensional array (what I want to do as
I assume it'll be faster). I started by defining vectors for a, b, and k:

k = [-20:0.05:20];
b = [0:0.01:2];
a = [0:0.001:0.01];


and then tried to find p for all of the possible values of a, b and k and
store in an array of three dimansion; I tried this:

p = zeros(length(a),length(k),length(b));   %allocating memory

p = exp(-1.*a.*(abs(k)).^b)

Which doesn't seem to work. 
Is this something that you can do with Octave or will I have to use for
loops?

Thanks in advance
Martin

-----
Still learning everyday.
--
View this message in context: 
http://octave.1599824.n4.nabble.com/Arrays-Multidimensional-manipulating-tp3445070p3445070.html
Sent from the Octave - General mailing list archive at Nabble.com.
_______________________________________________
Help-octave mailing list
address@hidden
https://mailman.cae.wisc.edu/listinfo/help-octave


Martin,

Maybe you could try using meshgrid.

[A,B,K] = meshgrid(a,b,k);
p = size(A);
p = exp(-1.*A.*(abs(K)).^B);

William Krekeler



reply via email to

[Prev in Thread] Current Thread [Next in Thread]