1
$\begingroup$

I have imported an excel file Data=Import["data.xlsx"] which gives the output like this:

{{{"Q", "R0", "m"}, {3, 1, 3.83171}, {4, 1.05, 7.01559}, {7, 1.1,10.1735}, {10, 1.15,13.3237}}}

I wish to evaluate the integrals u and w for each Q, R0 and m, and export the obtained results:

u[R0_, m_]:= Integrate[BesselJ[0, (m/R0)*R]*(Cosh[4*z]/Cosh[2] - Cos[4*z]/Cos[2]), {z, -(1/2), 1/2},{R, 0, R0}]
w[Q_, R0_, m_]:= Q*u[R0, m]

enter image description here

What I have done so far is to evaluate them one-by-one. How can I do this more efficiently? Any help would be really appreciated.

$\endgroup$

1 Answer 1

1
$\begingroup$
Clear["Global`*"]
data = First@{{{"Q", "R0", "m"}, {3, 1, 3.83171}, {4, 1.05, 
     7.01559}, {7, 1.1, 10.1735}, {10, 1.15, 13.3237}}}
u[R0_, m_] := 
 Integrate[
  BesselJ[0, (m/R0)*R]*(Cosh[4*z]/Cosh[2] - 
     Cos[4*z]/Cos[2]), {z, -(1/2), 1/2}, {R, 0, R0}]
w[Q_, R0_, m_] := Q*u[R0, m]

out = Prepend[{#1, #2, #3, u[#2, #3], w[#1, #2, #3]} & @@@ (Rest@data)
  , (data[[1]]~Join~{w, u})
  ]

Export["C:/results.out", out, "List"]

Or to an Excel file as:

Export["C:/table.xlsx", out, "XLSX"]
$\endgroup$
1
  • $\begingroup$ Thank you so much, this is exactly what I wanted ! $\endgroup$ Commented Jun 15, 2023 at 10:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.