0
$\begingroup$

I have imported an excel file, and I want to evaluate an expression on each point:

Data = Import["data.xlsx"] which gives output like this:

{{f,t},{2,12},{3,200},{20,2500},{38,100},{40,2000}}

I want to evaluate following expression for each point:

Rate=EXP[(a-f)]*f*t

where, a is some type constant. So far I am trying to use Evaluate function in mathemtica:

Evaluate[Rate, Data[[All, {1, 2}]]]
Evaluate[Rate, Data[[All, {3, 4}]]]

But couldn't figure out how to obtained values for expression (Rate) for each value. Any help will be appreciated.

$\endgroup$

1 Answer 1

2
$\begingroup$

You want to do the same thing to each item in a list. In Mathematica that almost always means use Map. I'm guessing you probably don't want to do that to the first item in your list, so Rest will discard that. Each item in your Data list is a list of two numbers so we define a function which accepts a list of two numbers and calculates the result you are looking for. Perhaps this will do what you are looking for

Data={{f,t},{2,12},{3,200},{20,2500},{38,100},{40,2000}};
a=5;
fun[{f_,t_}]:=Exp[(a-f)]*f*t;
Map[fun,Rest[Data]]

which instantly returns

{24*E^3, 600*E^2, 50000/E^15, 3800/E^33, 80000/E^35}

If you need that result in a different form and can't figure out how to accomplish that then leave a comment describing how it needs to be changed and perhaps we can get what you are looking for.

Look up Map in the documentation and see if you can understand how this works. And check these results to make certain that they are correct.

Experienced users will often use the shorthand /@ instead of writing Map[...] but for a new user having those [...] may help you figure out how this is working.

$\endgroup$
1
  • $\begingroup$ Thank you very much, This is what I am looking for. $\endgroup$ Commented Jul 23, 2019 at 23:05

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.