Re: matrix multiplication question

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Sun Jun 23 2013 - 15:28:56 MDT

Hi Sam,

You can use the "conform" or "conform_dims" function to conform the "f" array to be the same size as the "curl" array. You don't need to conform scalars.

http://www.ncl.ucar.edu/Document/Functions/Built-in/conform_dims.shtml

curl = curl/(rho * conform(curl,1,f)) ; "f" conforms to the 1-th (second) dimesion of "curl"

If you want to be more explicit about what you're doing:

f3d = conform(curl,1,f) ; "f" conforms to the 1-th (second) dimesion of "curl"
curl = curl/(rho * f3d)
delete(f3d) ; not necessary

--Mary

On Jun 21, 2013, at 2:17 PM, Sam McClatchie (NOAA Federal) <sam.mcclatchie@noaa.gov> wrote:

> Colleagues
>
> I am being a bit thick about how to code a matrix multiplication (#),
> and request your help.
>
> I have an array with three coordinate variables: time, latitude, and
> longitude
>
> ncl 14> print(dimsizes(curl))
> (0) 557
> (1) 31
> (2) 26
>
> I want to multiply each of the curl values at each unique latitude by
> 1/(rho * f(i))
> where:
> rho = 1024 ; kg m^-3
> f = 2 * omega * sin(latitude) ; Coriolis parameter
> and omega = 7.27*10^-5 ; units = s^-1
>
> ncl 15> print(dimsizes(f))
> (0) 31
>
> The temptation is to use a do loop and then stack the matrices by time
> steps, but I know there is a better way using vectorization.
>
> Thanks, Sam
>
> --
> Sam McClatchie,
> Supervisory oceanographer, Fisheries oceanography
> Southwest Fisheries Science Center, NOAA,
> 8901 La Jolla Shores Dr.
> La Jolla, CA 92037-1509, U.S.A.
> email <Sam.McClatchie@noaa.gov>
> Office: 858 546 7083, Cellular: 858 752 8495
> Research home page <www.fishocean.info>
>
> /\
> ...>><xX(¡>
> //// \\\\
> <¡)Xx><<
> ///// \\\\\\
>> <(((¡>
>>> <(((¡> ...>><xX(¡>O<¡)Xx><<
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Sun Jun 23 15:29:07 2013

This archive was generated by hypermail 2.1.8 : Mon Jun 24 2013 - 11:46:47 MDT