Message Boards Message Boards

[✓] Use imported data for calculations?

GROUPS:

I am just getting started using Mathematica. I have a code I developed in Matlab, but I realize now that Matlab does not calculate Macdonald functions of imaginary order. So, here I am with Mathematica. I have a *.csv file with numeric data array. I figured out how to read in array, but cannot find anything to instruct me how to extract element-wise values that I can use in computations. The convention of "{{ }}", or "[{ }]", or "[[ ]]" is not explained in any of the documentation, and no combination I try works. I am trying to extract, for instance, element at position [2,3] of the array to perform a calculation. The output I get is taking the entire array and performing the calculation on all elements. How do I get the calculation on the single element I want?

Dwight

POSTED BY: Dwight Swett
Answer
4 months ago

Here is a List:

myList = {{a, b, c}, {d, e, f}, {g, h, i}}

To access the 3rd element of the 2nd row, i.e. [2,3]:

myList[[2,3]]

More details can be found in the doucmentation at http://reference.wolfram.com/language/ref/Part.html

This tutorial on Lists should help as well: http://reference.wolfram.com/language/tutorial/ListsOverview.html

POSTED BY: Abrita Chakravarty
Answer
4 months ago

You should read at least the quick introduction to using Mathematica in the Mathematica Book (Documentation Center, version 11).

I think the Mathematica Book version 4.0 (or 5.x) are easier to sit down and read the introduction of than Documentation Center.

You can find a free mathematica book pdf at:

http://reference.wolfram.com/legacy/v5_2/

POSTED BY: John Hendrickson
Answer
4 months ago

Thanks for all the good help. I was able to get started using the following simple: ae = Table[0, {Nd}]; Zae = Table[0, {Nd}]; Zbe = Table[0, {Nd}]; For[Nd = 1, Nd < Necc + 1, Nd++, g = gap[[Nd]]; Da = 2 ra 1000; Db = 2 rb 1000; ae[[Nd]] = (g (Db - g) (Db - Da - g) (Da + g))^0.5 /(Db - Da - 2 g); Zae[[Nd]] = ArcSinh[2 ae[[Nd]] /Da]; Zbe[[Nd]] = ArcSinh[2 ae[[Nd]] /Db]; a = ae[[Nd]] /1000; Za = Zae[[Nd]]; Zb = Zbe[[Nd]]; ];

and this works. But then I try using the same here: frq1 = 50 10^6; frq2 = 1000 10^6; Nfrq = 95; frq = Table[0, {Nfrq}]; for [Nf = 1, Nf < Nfrq + 1, Nf++, frq[[Nf]] = frq1 + (Nf - 1) (frq2 - frq1)/Nfrq; ];

and it does not work. Any idea why this does not work?

POSTED BY: Dwight Swett
Answer
4 months ago

I had a couple typo's in my response. But my question remains: Why does this script not work? frq1 = 50.0 10^6; frq2 = 1000.0 10^6; Nfrq = 10; frq = Table[0, {Nfrq}]; for[nf = 1, nf <= Nfrq + 1, nf++, frq[[nf]] = frq1 + (nf - 1) (frq2 - frq1)/Nfrq; ];

The output keeps all zeroes for frq, except frq[2] which gives the correct calculation: {0, 1.45*10^8, 0, 0, 0, 0, 0, 0, 0, 0}

Dwight

POSTED BY: Dwight Swett
Answer
4 months ago

Dwight, the For command must use uppercase F. Secondly, the nf<=Nfrq+1 yields a value of 11 but frg has a maximum of 10 elements. This requires nf<Nfrq + 1 or nf,<=Nfrq. Hope this helps. Regards, -Ed

POSTED BY: Ed Forrester
Answer
4 months ago

Thanks Ed very much. I just caught those too and it works now. I am just recovering from stomach flu so probably missing on several cylinders.

Dwight

POSTED BY: Dwight Swett
Answer
4 months ago

Group Abstract Group Abstract