Message Boards Message Boards

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

Large sequential list of definite integrals; deternine a list of each val

I have a data list of definite integrals that I need to numerically evaluate. Then print out the data and list plot.

luke

Posted 11 years ago

I have to guess many things, but can you adapt this?

Given a file named integrals.txt containing

NIntegrate[x^2,{x,0,3}]
NIntegrate[3x-4,{x,1,2}]
NIntegrate[Sin[x],{x,0,Pi}]
NIntegrate[Log[x+1],{x,1,2}]
NIntegrate[x*Sin[x],{x,0,3}]
NIntegrate[ArcTan[x],{x,1/2,1}]
NIntegrate[E^x/x,{x,1,5}]
NIntegrate[E^Sin[x],{x,0,3}]

(just plain ASCII text without any color highlighting, fonts, just the text, but I can't get an unformatted list to display here in any other way)

and a notebook containing this

In[1]:= dati =  StringSplit[Import["integrals.txt"], "\n"]

Out[1]= {"NIntegrate[x^2,{x,0,3}]", "NIntegrate[3x-4,{x,1,2}]", "NIntegrate[Sin[x],{x,0,Pi}]", "NIntegrate[Log[x+1],{x,1,2}]",
"NIntegrate[x*Sin[x],{x,0,3}]", "NIntegrate[ArcTan[x],{x,1/2,1}]", "NIntegrate[E^x/x,{x,1,5}]", "NIntegrate[E^Sin[x],{x,0,3}]"}

In[2]:= result = Map[ToExpression, dati]

Out[2]= {9., 0.5, 2., 0.909543, 3.1111, 0.318573, 38.2902, 6.05667}

In[3]:= ListPlot[result, Joined -> True]

Out[3]= ...PlotSnipped...

Where the In[n]:= are the actual lines I typed into the notebook and the Out[n]= lines were produced by Mathematica.

You either have to figure out where to put that file on your system so Mathematica can find it or you have to figure out how to tell Mathematica where you put it.

POSTED BY: Bill Simpson
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