Integrating a list of valuesList operation on specific elementsEfficient way to obtain values of a function defined by an IntegralNumerical integration of modified bessel functionIntegrating an interpolating functionNumerical Integral with Boolean as part of argumentHow to set a line coordinate for a symbolic line integral over a curve?Integrating curve peaksStrange results by integrating Abs[Sin[a - t]]Integrating over colorsIntegrating only over positive values of an oscillating function
How can I determine if the org that I'm currently connected to is a scratch org?
Can I run a new neutral wire to repair a broken circuit?
Do UK voters know if their MP will be the Speaker of the House?
Would Slavery Reparations be considered Bills of Attainder and hence Illegal?
How can saying a song's name be a copyright violation?
Mathematica command that allows it to read my intentions
Alternative to sending password over mail?
How to compactly explain secondary and tertiary characters without resorting to stereotypes?
What is the most common color to indicate the input-field is disabled?
Are there any examples of a variable being normally distributed that is *not* due to the Central Limit Theorem?
How to Recreate this in LaTeX? (Unsure What the Notation is Called)
Cursor Replacement for Newbies
Size of subfigure fitting its content (tikzpicture)
Why no variance term in Bayesian logistic regression?
Short story with a alien planet, government officials must wear exploding medallions
Could the museum Saturn V's be refitted for one more flight?
Arrow those variables!
How seriously should I take size and weight limits of hand luggage?
Why didn't Boeing produce its own regional jet?
Im going to France and my passport expires June 19th
Why do bosons tend to occupy the same state?
Is it possible to create a QR code using text?
Should I tell management that I intend to leave due to bad software development practices?
Avoiding the "not like other girls" trope?
Integrating a list of values
List operation on specific elementsEfficient way to obtain values of a function defined by an IntegralNumerical integration of modified bessel functionIntegrating an interpolating functionNumerical Integral with Boolean as part of argumentHow to set a line coordinate for a symbolic line integral over a curve?Integrating curve peaksStrange results by integrating Abs[Sin[a - t]]Integrating over colorsIntegrating only over positive values of an oscillating function
$begingroup$
The data given here
data = Table[Clip[Sin[x], 0, 1], x, 0, 2 [Pi], 0.1]
generates the following curve
ListPlot[data]
I want to know, how to compute the integral of this curve using only the data given above.
list-manipulation calculus-and-analysis numerical-integration
$endgroup$
add a comment |
$begingroup$
The data given here
data = Table[Clip[Sin[x], 0, 1], x, 0, 2 [Pi], 0.1]
generates the following curve
ListPlot[data]
I want to know, how to compute the integral of this curve using only the data given above.
list-manipulation calculus-and-analysis numerical-integration
$endgroup$
3
$begingroup$
If you only have a list of function values, you need to give the step size as well.
$endgroup$
– J. M. is slightly pensive♦
2 days ago
add a comment |
$begingroup$
The data given here
data = Table[Clip[Sin[x], 0, 1], x, 0, 2 [Pi], 0.1]
generates the following curve
ListPlot[data]
I want to know, how to compute the integral of this curve using only the data given above.
list-manipulation calculus-and-analysis numerical-integration
$endgroup$
The data given here
data = Table[Clip[Sin[x], 0, 1], x, 0, 2 [Pi], 0.1]
generates the following curve
ListPlot[data]
I want to know, how to compute the integral of this curve using only the data given above.
list-manipulation calculus-and-analysis numerical-integration
list-manipulation calculus-and-analysis numerical-integration
edited 2 days ago
J. M. is slightly pensive♦
99k10311467
99k10311467
asked 2 days ago
Tobias FritznTobias Fritzn
1945
1945
3
$begingroup$
If you only have a list of function values, you need to give the step size as well.
$endgroup$
– J. M. is slightly pensive♦
2 days ago
add a comment |
3
$begingroup$
If you only have a list of function values, you need to give the step size as well.
$endgroup$
– J. M. is slightly pensive♦
2 days ago
3
3
$begingroup$
If you only have a list of function values, you need to give the step size as well.
$endgroup$
– J. M. is slightly pensive♦
2 days ago
$begingroup$
If you only have a list of function values, you need to give the step size as well.
$endgroup$
– J. M. is slightly pensive♦
2 days ago
add a comment |
4 Answers
4
active
oldest
votes
$begingroup$
Using Tai's method:
ω = ConstantArray[0.1, Length[data]];
ω[[1]] *= 0.5;
ω[[-1]] *= 0.5;
ω.data
Alternatively
a = Table[x, Clip[Sin[x], 0., 1.], x, 0, 2 π, 0.1];
Integrate[Interpolation[a][x], x, a[[1, 1]], a[[-1, 1]]]
2.00038
$endgroup$
$begingroup$
ForInterpolation
you can also play with theInterpolationOrder
option to increase the accuracy (sometimes). In this case it doesn't do much though.
$endgroup$
– Roman
2 days ago
$begingroup$
Jepp. The reseason is the kink in the middle of the integral. This way, one cannot profit from higher order quadrature rules. Trapezoidal rule is almost optimal.
$endgroup$
– Henrik Schumacher
2 days ago
$begingroup$
I want the integral as a plot, a curve. Any way of doing that?
$endgroup$
– Tobias Fritzn
2 days ago
add a comment |
$begingroup$
Assuming the stepsize is 0.1 as suggested by the construction of the Table, you can calculate:
0.1*Total[data]
to get the numerical integral. To visualize the integral and plot it you can ListPlot:
0.1*Accumulate[data]
Hence:
data = Table[Clip[Sin[x], 0, 1], x, 0, 2 [Pi], 0.1];
ListPlot[data, 0.1*Accumulate[data]]
$endgroup$
$begingroup$
How is the function Accumulate related to Integration?
$endgroup$
– Tobias Fritzn
2 days ago
1
$begingroup$
As you are accumulating the data, you are integrating the function up to that point. So this is the answer to your statement that you "want the integral as a plot."
$endgroup$
– bill s
2 days ago
$begingroup$
Thanks, @bill, it works nice. But looking at the definition of Accumulate[], it is not immediately clear how it should give an integral when multiplied by the stepsize. I mean given the definition Accumulate[i,j,k]=i,i+j,i+j+k, how does this lead to integration?
$endgroup$
– Tobias Fritzn
yesterday
$begingroup$
This is called the Rieman approximation to the integral.
$endgroup$
– bill s
yesterday
$begingroup$
Correct me if I am wrong. In a Rieman sum, nth term is not the sum of all (n-1) terms, which seems to be the case with Accumulate[]. en.wikipedia.org/wiki/Riemann_sum
$endgroup$
– Tobias Fritzn
yesterday
|
show 1 more comment
$begingroup$
You mention that you want the integral as a plot in a comment; I wonder if the following is what you had in mind. Here I am using your definition of data, and assuming a $0.1$ step size, as hinted at by your Table
expression.
tuples = Transpose@Range[0, 2 Pi, 0.1], data;
Show[
Plot[
NIntegrate[Interpolation[tuples][x], x, 0, xmax, Method -> "Trapezoidal"],
xmax, 0, 2 Pi, PlotLegends -> "integral"
],
ListPlot[
Style[tuples, Thick, ColorData[97][2]],
Mesh -> All, MeshStyle -> Directive[Black, PointSize[0.01]],
PlotLegends -> "data", Joined -> True
]
]
$endgroup$
add a comment |
$begingroup$
It seems that Simpson's rule has not been mentioned yet, which is the result from a 2nd-order interpolation and will have a smaller error than that from a 1st-order one. So according to the formula, the inputs are the List
of samples of the function data
and the step size h
:
simpsoncoefficients[n_] := SparseArray[1 -> 1, -1 -> 1, i_?EvenQ -> 4, n, 2]
integral[data_, h_] := (h/3) simpsoncoefficients[Length[#]].# &[data]
Then integral[data, 0.1]
gives 2.00024
.
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f194373%2fintegrating-a-list-of-values%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Using Tai's method:
ω = ConstantArray[0.1, Length[data]];
ω[[1]] *= 0.5;
ω[[-1]] *= 0.5;
ω.data
Alternatively
a = Table[x, Clip[Sin[x], 0., 1.], x, 0, 2 π, 0.1];
Integrate[Interpolation[a][x], x, a[[1, 1]], a[[-1, 1]]]
2.00038
$endgroup$
$begingroup$
ForInterpolation
you can also play with theInterpolationOrder
option to increase the accuracy (sometimes). In this case it doesn't do much though.
$endgroup$
– Roman
2 days ago
$begingroup$
Jepp. The reseason is the kink in the middle of the integral. This way, one cannot profit from higher order quadrature rules. Trapezoidal rule is almost optimal.
$endgroup$
– Henrik Schumacher
2 days ago
$begingroup$
I want the integral as a plot, a curve. Any way of doing that?
$endgroup$
– Tobias Fritzn
2 days ago
add a comment |
$begingroup$
Using Tai's method:
ω = ConstantArray[0.1, Length[data]];
ω[[1]] *= 0.5;
ω[[-1]] *= 0.5;
ω.data
Alternatively
a = Table[x, Clip[Sin[x], 0., 1.], x, 0, 2 π, 0.1];
Integrate[Interpolation[a][x], x, a[[1, 1]], a[[-1, 1]]]
2.00038
$endgroup$
$begingroup$
ForInterpolation
you can also play with theInterpolationOrder
option to increase the accuracy (sometimes). In this case it doesn't do much though.
$endgroup$
– Roman
2 days ago
$begingroup$
Jepp. The reseason is the kink in the middle of the integral. This way, one cannot profit from higher order quadrature rules. Trapezoidal rule is almost optimal.
$endgroup$
– Henrik Schumacher
2 days ago
$begingroup$
I want the integral as a plot, a curve. Any way of doing that?
$endgroup$
– Tobias Fritzn
2 days ago
add a comment |
$begingroup$
Using Tai's method:
ω = ConstantArray[0.1, Length[data]];
ω[[1]] *= 0.5;
ω[[-1]] *= 0.5;
ω.data
Alternatively
a = Table[x, Clip[Sin[x], 0., 1.], x, 0, 2 π, 0.1];
Integrate[Interpolation[a][x], x, a[[1, 1]], a[[-1, 1]]]
2.00038
$endgroup$
Using Tai's method:
ω = ConstantArray[0.1, Length[data]];
ω[[1]] *= 0.5;
ω[[-1]] *= 0.5;
ω.data
Alternatively
a = Table[x, Clip[Sin[x], 0., 1.], x, 0, 2 π, 0.1];
Integrate[Interpolation[a][x], x, a[[1, 1]], a[[-1, 1]]]
2.00038
answered 2 days ago
Henrik SchumacherHenrik Schumacher
59.1k582164
59.1k582164
$begingroup$
ForInterpolation
you can also play with theInterpolationOrder
option to increase the accuracy (sometimes). In this case it doesn't do much though.
$endgroup$
– Roman
2 days ago
$begingroup$
Jepp. The reseason is the kink in the middle of the integral. This way, one cannot profit from higher order quadrature rules. Trapezoidal rule is almost optimal.
$endgroup$
– Henrik Schumacher
2 days ago
$begingroup$
I want the integral as a plot, a curve. Any way of doing that?
$endgroup$
– Tobias Fritzn
2 days ago
add a comment |
$begingroup$
ForInterpolation
you can also play with theInterpolationOrder
option to increase the accuracy (sometimes). In this case it doesn't do much though.
$endgroup$
– Roman
2 days ago
$begingroup$
Jepp. The reseason is the kink in the middle of the integral. This way, one cannot profit from higher order quadrature rules. Trapezoidal rule is almost optimal.
$endgroup$
– Henrik Schumacher
2 days ago
$begingroup$
I want the integral as a plot, a curve. Any way of doing that?
$endgroup$
– Tobias Fritzn
2 days ago
$begingroup$
For
Interpolation
you can also play with the InterpolationOrder
option to increase the accuracy (sometimes). In this case it doesn't do much though.$endgroup$
– Roman
2 days ago
$begingroup$
For
Interpolation
you can also play with the InterpolationOrder
option to increase the accuracy (sometimes). In this case it doesn't do much though.$endgroup$
– Roman
2 days ago
$begingroup$
Jepp. The reseason is the kink in the middle of the integral. This way, one cannot profit from higher order quadrature rules. Trapezoidal rule is almost optimal.
$endgroup$
– Henrik Schumacher
2 days ago
$begingroup$
Jepp. The reseason is the kink in the middle of the integral. This way, one cannot profit from higher order quadrature rules. Trapezoidal rule is almost optimal.
$endgroup$
– Henrik Schumacher
2 days ago
$begingroup$
I want the integral as a plot, a curve. Any way of doing that?
$endgroup$
– Tobias Fritzn
2 days ago
$begingroup$
I want the integral as a plot, a curve. Any way of doing that?
$endgroup$
– Tobias Fritzn
2 days ago
add a comment |
$begingroup$
Assuming the stepsize is 0.1 as suggested by the construction of the Table, you can calculate:
0.1*Total[data]
to get the numerical integral. To visualize the integral and plot it you can ListPlot:
0.1*Accumulate[data]
Hence:
data = Table[Clip[Sin[x], 0, 1], x, 0, 2 [Pi], 0.1];
ListPlot[data, 0.1*Accumulate[data]]
$endgroup$
$begingroup$
How is the function Accumulate related to Integration?
$endgroup$
– Tobias Fritzn
2 days ago
1
$begingroup$
As you are accumulating the data, you are integrating the function up to that point. So this is the answer to your statement that you "want the integral as a plot."
$endgroup$
– bill s
2 days ago
$begingroup$
Thanks, @bill, it works nice. But looking at the definition of Accumulate[], it is not immediately clear how it should give an integral when multiplied by the stepsize. I mean given the definition Accumulate[i,j,k]=i,i+j,i+j+k, how does this lead to integration?
$endgroup$
– Tobias Fritzn
yesterday
$begingroup$
This is called the Rieman approximation to the integral.
$endgroup$
– bill s
yesterday
$begingroup$
Correct me if I am wrong. In a Rieman sum, nth term is not the sum of all (n-1) terms, which seems to be the case with Accumulate[]. en.wikipedia.org/wiki/Riemann_sum
$endgroup$
– Tobias Fritzn
yesterday
|
show 1 more comment
$begingroup$
Assuming the stepsize is 0.1 as suggested by the construction of the Table, you can calculate:
0.1*Total[data]
to get the numerical integral. To visualize the integral and plot it you can ListPlot:
0.1*Accumulate[data]
Hence:
data = Table[Clip[Sin[x], 0, 1], x, 0, 2 [Pi], 0.1];
ListPlot[data, 0.1*Accumulate[data]]
$endgroup$
$begingroup$
How is the function Accumulate related to Integration?
$endgroup$
– Tobias Fritzn
2 days ago
1
$begingroup$
As you are accumulating the data, you are integrating the function up to that point. So this is the answer to your statement that you "want the integral as a plot."
$endgroup$
– bill s
2 days ago
$begingroup$
Thanks, @bill, it works nice. But looking at the definition of Accumulate[], it is not immediately clear how it should give an integral when multiplied by the stepsize. I mean given the definition Accumulate[i,j,k]=i,i+j,i+j+k, how does this lead to integration?
$endgroup$
– Tobias Fritzn
yesterday
$begingroup$
This is called the Rieman approximation to the integral.
$endgroup$
– bill s
yesterday
$begingroup$
Correct me if I am wrong. In a Rieman sum, nth term is not the sum of all (n-1) terms, which seems to be the case with Accumulate[]. en.wikipedia.org/wiki/Riemann_sum
$endgroup$
– Tobias Fritzn
yesterday
|
show 1 more comment
$begingroup$
Assuming the stepsize is 0.1 as suggested by the construction of the Table, you can calculate:
0.1*Total[data]
to get the numerical integral. To visualize the integral and plot it you can ListPlot:
0.1*Accumulate[data]
Hence:
data = Table[Clip[Sin[x], 0, 1], x, 0, 2 [Pi], 0.1];
ListPlot[data, 0.1*Accumulate[data]]
$endgroup$
Assuming the stepsize is 0.1 as suggested by the construction of the Table, you can calculate:
0.1*Total[data]
to get the numerical integral. To visualize the integral and plot it you can ListPlot:
0.1*Accumulate[data]
Hence:
data = Table[Clip[Sin[x], 0, 1], x, 0, 2 [Pi], 0.1];
ListPlot[data, 0.1*Accumulate[data]]
edited 2 days ago
answered 2 days ago
bill sbill s
54.9k377158
54.9k377158
$begingroup$
How is the function Accumulate related to Integration?
$endgroup$
– Tobias Fritzn
2 days ago
1
$begingroup$
As you are accumulating the data, you are integrating the function up to that point. So this is the answer to your statement that you "want the integral as a plot."
$endgroup$
– bill s
2 days ago
$begingroup$
Thanks, @bill, it works nice. But looking at the definition of Accumulate[], it is not immediately clear how it should give an integral when multiplied by the stepsize. I mean given the definition Accumulate[i,j,k]=i,i+j,i+j+k, how does this lead to integration?
$endgroup$
– Tobias Fritzn
yesterday
$begingroup$
This is called the Rieman approximation to the integral.
$endgroup$
– bill s
yesterday
$begingroup$
Correct me if I am wrong. In a Rieman sum, nth term is not the sum of all (n-1) terms, which seems to be the case with Accumulate[]. en.wikipedia.org/wiki/Riemann_sum
$endgroup$
– Tobias Fritzn
yesterday
|
show 1 more comment
$begingroup$
How is the function Accumulate related to Integration?
$endgroup$
– Tobias Fritzn
2 days ago
1
$begingroup$
As you are accumulating the data, you are integrating the function up to that point. So this is the answer to your statement that you "want the integral as a plot."
$endgroup$
– bill s
2 days ago
$begingroup$
Thanks, @bill, it works nice. But looking at the definition of Accumulate[], it is not immediately clear how it should give an integral when multiplied by the stepsize. I mean given the definition Accumulate[i,j,k]=i,i+j,i+j+k, how does this lead to integration?
$endgroup$
– Tobias Fritzn
yesterday
$begingroup$
This is called the Rieman approximation to the integral.
$endgroup$
– bill s
yesterday
$begingroup$
Correct me if I am wrong. In a Rieman sum, nth term is not the sum of all (n-1) terms, which seems to be the case with Accumulate[]. en.wikipedia.org/wiki/Riemann_sum
$endgroup$
– Tobias Fritzn
yesterday
$begingroup$
How is the function Accumulate related to Integration?
$endgroup$
– Tobias Fritzn
2 days ago
$begingroup$
How is the function Accumulate related to Integration?
$endgroup$
– Tobias Fritzn
2 days ago
1
1
$begingroup$
As you are accumulating the data, you are integrating the function up to that point. So this is the answer to your statement that you "want the integral as a plot."
$endgroup$
– bill s
2 days ago
$begingroup$
As you are accumulating the data, you are integrating the function up to that point. So this is the answer to your statement that you "want the integral as a plot."
$endgroup$
– bill s
2 days ago
$begingroup$
Thanks, @bill, it works nice. But looking at the definition of Accumulate[], it is not immediately clear how it should give an integral when multiplied by the stepsize. I mean given the definition Accumulate[i,j,k]=i,i+j,i+j+k, how does this lead to integration?
$endgroup$
– Tobias Fritzn
yesterday
$begingroup$
Thanks, @bill, it works nice. But looking at the definition of Accumulate[], it is not immediately clear how it should give an integral when multiplied by the stepsize. I mean given the definition Accumulate[i,j,k]=i,i+j,i+j+k, how does this lead to integration?
$endgroup$
– Tobias Fritzn
yesterday
$begingroup$
This is called the Rieman approximation to the integral.
$endgroup$
– bill s
yesterday
$begingroup$
This is called the Rieman approximation to the integral.
$endgroup$
– bill s
yesterday
$begingroup$
Correct me if I am wrong. In a Rieman sum, nth term is not the sum of all (n-1) terms, which seems to be the case with Accumulate[]. en.wikipedia.org/wiki/Riemann_sum
$endgroup$
– Tobias Fritzn
yesterday
$begingroup$
Correct me if I am wrong. In a Rieman sum, nth term is not the sum of all (n-1) terms, which seems to be the case with Accumulate[]. en.wikipedia.org/wiki/Riemann_sum
$endgroup$
– Tobias Fritzn
yesterday
|
show 1 more comment
$begingroup$
You mention that you want the integral as a plot in a comment; I wonder if the following is what you had in mind. Here I am using your definition of data, and assuming a $0.1$ step size, as hinted at by your Table
expression.
tuples = Transpose@Range[0, 2 Pi, 0.1], data;
Show[
Plot[
NIntegrate[Interpolation[tuples][x], x, 0, xmax, Method -> "Trapezoidal"],
xmax, 0, 2 Pi, PlotLegends -> "integral"
],
ListPlot[
Style[tuples, Thick, ColorData[97][2]],
Mesh -> All, MeshStyle -> Directive[Black, PointSize[0.01]],
PlotLegends -> "data", Joined -> True
]
]
$endgroup$
add a comment |
$begingroup$
You mention that you want the integral as a plot in a comment; I wonder if the following is what you had in mind. Here I am using your definition of data, and assuming a $0.1$ step size, as hinted at by your Table
expression.
tuples = Transpose@Range[0, 2 Pi, 0.1], data;
Show[
Plot[
NIntegrate[Interpolation[tuples][x], x, 0, xmax, Method -> "Trapezoidal"],
xmax, 0, 2 Pi, PlotLegends -> "integral"
],
ListPlot[
Style[tuples, Thick, ColorData[97][2]],
Mesh -> All, MeshStyle -> Directive[Black, PointSize[0.01]],
PlotLegends -> "data", Joined -> True
]
]
$endgroup$
add a comment |
$begingroup$
You mention that you want the integral as a plot in a comment; I wonder if the following is what you had in mind. Here I am using your definition of data, and assuming a $0.1$ step size, as hinted at by your Table
expression.
tuples = Transpose@Range[0, 2 Pi, 0.1], data;
Show[
Plot[
NIntegrate[Interpolation[tuples][x], x, 0, xmax, Method -> "Trapezoidal"],
xmax, 0, 2 Pi, PlotLegends -> "integral"
],
ListPlot[
Style[tuples, Thick, ColorData[97][2]],
Mesh -> All, MeshStyle -> Directive[Black, PointSize[0.01]],
PlotLegends -> "data", Joined -> True
]
]
$endgroup$
You mention that you want the integral as a plot in a comment; I wonder if the following is what you had in mind. Here I am using your definition of data, and assuming a $0.1$ step size, as hinted at by your Table
expression.
tuples = Transpose@Range[0, 2 Pi, 0.1], data;
Show[
Plot[
NIntegrate[Interpolation[tuples][x], x, 0, xmax, Method -> "Trapezoidal"],
xmax, 0, 2 Pi, PlotLegends -> "integral"
],
ListPlot[
Style[tuples, Thick, ColorData[97][2]],
Mesh -> All, MeshStyle -> Directive[Black, PointSize[0.01]],
PlotLegends -> "data", Joined -> True
]
]
answered 2 days ago
MarcoBMarcoB
38.5k557115
38.5k557115
add a comment |
add a comment |
$begingroup$
It seems that Simpson's rule has not been mentioned yet, which is the result from a 2nd-order interpolation and will have a smaller error than that from a 1st-order one. So according to the formula, the inputs are the List
of samples of the function data
and the step size h
:
simpsoncoefficients[n_] := SparseArray[1 -> 1, -1 -> 1, i_?EvenQ -> 4, n, 2]
integral[data_, h_] := (h/3) simpsoncoefficients[Length[#]].# &[data]
Then integral[data, 0.1]
gives 2.00024
.
$endgroup$
add a comment |
$begingroup$
It seems that Simpson's rule has not been mentioned yet, which is the result from a 2nd-order interpolation and will have a smaller error than that from a 1st-order one. So according to the formula, the inputs are the List
of samples of the function data
and the step size h
:
simpsoncoefficients[n_] := SparseArray[1 -> 1, -1 -> 1, i_?EvenQ -> 4, n, 2]
integral[data_, h_] := (h/3) simpsoncoefficients[Length[#]].# &[data]
Then integral[data, 0.1]
gives 2.00024
.
$endgroup$
add a comment |
$begingroup$
It seems that Simpson's rule has not been mentioned yet, which is the result from a 2nd-order interpolation and will have a smaller error than that from a 1st-order one. So according to the formula, the inputs are the List
of samples of the function data
and the step size h
:
simpsoncoefficients[n_] := SparseArray[1 -> 1, -1 -> 1, i_?EvenQ -> 4, n, 2]
integral[data_, h_] := (h/3) simpsoncoefficients[Length[#]].# &[data]
Then integral[data, 0.1]
gives 2.00024
.
$endgroup$
It seems that Simpson's rule has not been mentioned yet, which is the result from a 2nd-order interpolation and will have a smaller error than that from a 1st-order one. So according to the formula, the inputs are the List
of samples of the function data
and the step size h
:
simpsoncoefficients[n_] := SparseArray[1 -> 1, -1 -> 1, i_?EvenQ -> 4, n, 2]
integral[data_, h_] := (h/3) simpsoncoefficients[Length[#]].# &[data]
Then integral[data, 0.1]
gives 2.00024
.
edited yesterday
answered 2 days ago
Αλέξανδρος ΖεγγΑλέξανδρος Ζεγγ
4,49011029
4,49011029
add a comment |
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f194373%2fintegrating-a-list-of-values%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
$begingroup$
If you only have a list of function values, you need to give the step size as well.
$endgroup$
– J. M. is slightly pensive♦
2 days ago