Message Boards Message Boards

0
|
3880 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

Integrate a function with limits from a set of data?

Posted 5 years ago

Hello, I'm trying to integrate a function:

r(z) = Integral of c/H(z) from 0 to z, where: c = speed of light and H(z) = Sqrt[0.7+0.3(1+z)^3]

My problem is I have a bunch of values of z in an excel spreadsheet but I don't know the syntax for performing a mass integration like that.

So far I have:

s = Import["C:\\Users\\jung\\Desktop\\senior\Raw redshift data.xlsx"];
H[z_] := Sqrt[0.3*((1 + z)^3) + 0.7];
c = 3*10^8;
Integrate[c/H[z], {z, 0, s}]

My end goal is to have a data set of each integrated value that I can export to an excel spreadsheet.

POSTED BY: Jungkyu Kim
Posted 5 years ago

If I read this correctly, you want the integration performed over the dummy variable z, with a limit from 0 to s. The list you import as "s" contains the values for s.

Here is code that would do that:

(* some made-up data *)
data = Range[1, 5]

(* {1,2,3,4,5} *)

(* h can be just an expression *)
h = Sqrt[0.3*((1 + z)^3) + 0.7];

c = 3*10^8;

(* a function that accepts s as an argument -- numerical integration *)
r[s_] := NIntegrate[c/h, {z, 0, s}]

(* applied to a single value *)
r[2]

(* 3.628413612813334`*^8 *)

(* mapped onto a list of values for s *)    
r /@ data

(* {2.31428*10^8, 3.62841*10^8, 4.45206*10^8, 5.02273*10^8, 
 5.44653*10^8} *)
POSTED BY: David Keith
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract