How to substitute values from a list into a function?How to substitute variables in interpolated function?How...
Don't know what I’m looking for regarding removable HDDs?
Real life puzzle: Unknown alphabet or shorthand
The need of reserving one's ability in job interviews
Citing contemporaneous (interlaced?) preprints
Analog Mute Circuit - Simplest Solution
Skis versus snow shoes - when to choose which for travelling the backcountry?
Borrowing Characters
Heating basement floor with water heater
It took me a lot of time to make this, pls like. (YouTube Comments #1)
What is better: yes / no radio, or simple checkbox?
What is this waxed root vegetable?
Levi-Civita symbol: 3D matrix
How to lift/raise/repair a segment of concrete slab?
Why do phishing e-mails use faked e-mail addresses instead of the real one?
Why do members of Congress in committee hearings ask witnesses the same question multiple times?
Reason why dimensional travelling would be restricted
Detect if page is on experience editor Sitecore 9 via Javascript?
What is a term for a function that when called repeatedly, has the same effect as calling once?
In Adventurer's League, is it possible to keep the Ring of Winter if you manage to acquire it in the Tomb of Annihilation adventure?
In iTunes 12 on macOS, how can I reset the skip count of a song?
Is divide-by-zero a security vulnerability?
If a set is open, does that imply that it has no boundary points?
If nine coins are tossed, what is the probability that the number of heads is even?
What type of investment is best suited for a 1-year investment on a down payment?
How to substitute values from a list into a function?
How to substitute variables in interpolated function?How to construct pairs in a list?Insert all elements from one matrix into anotherCommand to insert item into listWay to generate all multisetsHow delete a pair from a list of pairs if the last element of the pair is complex?Filter a nested list based on conditions on its elementslabeling data in a listManipulating listsMapping doesn't substitute in the values
$begingroup$
I was hoping to take pairs of numbers from a list and substitute them into a function. So if my list was
list = {{1,2}, {3,4}, {5,6}}
and my function was
function = a x^b
The output I'm hoping to get is
result =1x^2 + 3x^4 + 5x^6
How would I best do this?
list-manipulation functions
New contributor
Pineapple is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
add a comment |
$begingroup$
I was hoping to take pairs of numbers from a list and substitute them into a function. So if my list was
list = {{1,2}, {3,4}, {5,6}}
and my function was
function = a x^b
The output I'm hoping to get is
result =1x^2 + 3x^4 + 5x^6
How would I best do this?
list-manipulation functions
New contributor
Pineapple is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
add a comment |
$begingroup$
I was hoping to take pairs of numbers from a list and substitute them into a function. So if my list was
list = {{1,2}, {3,4}, {5,6}}
and my function was
function = a x^b
The output I'm hoping to get is
result =1x^2 + 3x^4 + 5x^6
How would I best do this?
list-manipulation functions
New contributor
Pineapple is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
I was hoping to take pairs of numbers from a list and substitute them into a function. So if my list was
list = {{1,2}, {3,4}, {5,6}}
and my function was
function = a x^b
The output I'm hoping to get is
result =1x^2 + 3x^4 + 5x^6
How would I best do this?
list-manipulation functions
list-manipulation functions
New contributor
Pineapple is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Pineapple is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Pineapple is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 39 mins ago
PineapplePineapple
111
111
New contributor
Pineapple is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Pineapple is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Pineapple is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
$begingroup$
This is not a Function:
function = a x^b
But this is:
function = {a,b} [Function] a x^b
You can Apply it to each element of
list = {{1,2}, {3,4}, {5,6}}
with
function @@@ list
{x^3, 3 x^5, 5 x^7}
and sum it up with Total:
Total[ function @@@ list ]
x^3 + 3 x^5 + 5 x^7
$endgroup$
$begingroup$
Why would you do 'function = {a,b} [Function] a x^b' instead of function[a_, b_, x_] = a*x^b?
$endgroup$
– Pineapple
28 mins ago
$begingroup$
Because[Function]is easily entered with the escape sequence esc f n esc . AlsoFunctiondefines a pure function whilefunction[a_, b_, x_] = a*x^bdefines a replacement rule. However, they act the same way - most of the time. So it is a matter of taste.
$endgroup$
– Henrik Schumacher
24 mins ago
$begingroup$
@Pineapple Take a look at this tutorial on Defining Functions. Another good resource is the tutorial on Immediate and Delayed Definitions for the difference betweenSet(=) andSetDelayed(:=).
$endgroup$
– MarcoB
10 mins ago
add a comment |
$begingroup$
Total[#*x^#2&@@@list]
x^2 + 3 x^4 + 5 x^6
$endgroup$
add a comment |
$begingroup$
Total[(#[[1]] x^#[[2]]) & /@ list]
$endgroup$
$begingroup$
Amazing, thank you! Sorry - I'm very new to Mathematica.
$endgroup$
– Pineapple
29 mins ago
add a comment |
$begingroup$
FromCoefficientRules[Thread[list[[All, {2}]] -> list[[All, 1]]], x]
x^2 + 3 x^4 + 5 x^6
Internal`FromCoefficientList[Normal@SparseArray[1 + list[[All, {2}]] -> list[[All, 1]]], x]
x^2 + 3 x^4 + 5 x^6
$endgroup$
add a comment |
$begingroup$
Inner[#1 x^#2 &, Sequence @@ Transpose@list, Plus]
(* Out: x^2 + 3 x^4 + 5 x^6 *)
$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
});
}
});
Pineapple is a new contributor. Be nice, and check out our Code of Conduct.
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%2f192691%2fhow-to-substitute-values-from-a-list-into-a-function%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
This is not a Function:
function = a x^b
But this is:
function = {a,b} [Function] a x^b
You can Apply it to each element of
list = {{1,2}, {3,4}, {5,6}}
with
function @@@ list
{x^3, 3 x^5, 5 x^7}
and sum it up with Total:
Total[ function @@@ list ]
x^3 + 3 x^5 + 5 x^7
$endgroup$
$begingroup$
Why would you do 'function = {a,b} [Function] a x^b' instead of function[a_, b_, x_] = a*x^b?
$endgroup$
– Pineapple
28 mins ago
$begingroup$
Because[Function]is easily entered with the escape sequence esc f n esc . AlsoFunctiondefines a pure function whilefunction[a_, b_, x_] = a*x^bdefines a replacement rule. However, they act the same way - most of the time. So it is a matter of taste.
$endgroup$
– Henrik Schumacher
24 mins ago
$begingroup$
@Pineapple Take a look at this tutorial on Defining Functions. Another good resource is the tutorial on Immediate and Delayed Definitions for the difference betweenSet(=) andSetDelayed(:=).
$endgroup$
– MarcoB
10 mins ago
add a comment |
$begingroup$
This is not a Function:
function = a x^b
But this is:
function = {a,b} [Function] a x^b
You can Apply it to each element of
list = {{1,2}, {3,4}, {5,6}}
with
function @@@ list
{x^3, 3 x^5, 5 x^7}
and sum it up with Total:
Total[ function @@@ list ]
x^3 + 3 x^5 + 5 x^7
$endgroup$
$begingroup$
Why would you do 'function = {a,b} [Function] a x^b' instead of function[a_, b_, x_] = a*x^b?
$endgroup$
– Pineapple
28 mins ago
$begingroup$
Because[Function]is easily entered with the escape sequence esc f n esc . AlsoFunctiondefines a pure function whilefunction[a_, b_, x_] = a*x^bdefines a replacement rule. However, they act the same way - most of the time. So it is a matter of taste.
$endgroup$
– Henrik Schumacher
24 mins ago
$begingroup$
@Pineapple Take a look at this tutorial on Defining Functions. Another good resource is the tutorial on Immediate and Delayed Definitions for the difference betweenSet(=) andSetDelayed(:=).
$endgroup$
– MarcoB
10 mins ago
add a comment |
$begingroup$
This is not a Function:
function = a x^b
But this is:
function = {a,b} [Function] a x^b
You can Apply it to each element of
list = {{1,2}, {3,4}, {5,6}}
with
function @@@ list
{x^3, 3 x^5, 5 x^7}
and sum it up with Total:
Total[ function @@@ list ]
x^3 + 3 x^5 + 5 x^7
$endgroup$
This is not a Function:
function = a x^b
But this is:
function = {a,b} [Function] a x^b
You can Apply it to each element of
list = {{1,2}, {3,4}, {5,6}}
with
function @@@ list
{x^3, 3 x^5, 5 x^7}
and sum it up with Total:
Total[ function @@@ list ]
x^3 + 3 x^5 + 5 x^7
answered 33 mins ago
Henrik SchumacherHenrik Schumacher
55.4k576154
55.4k576154
$begingroup$
Why would you do 'function = {a,b} [Function] a x^b' instead of function[a_, b_, x_] = a*x^b?
$endgroup$
– Pineapple
28 mins ago
$begingroup$
Because[Function]is easily entered with the escape sequence esc f n esc . AlsoFunctiondefines a pure function whilefunction[a_, b_, x_] = a*x^bdefines a replacement rule. However, they act the same way - most of the time. So it is a matter of taste.
$endgroup$
– Henrik Schumacher
24 mins ago
$begingroup$
@Pineapple Take a look at this tutorial on Defining Functions. Another good resource is the tutorial on Immediate and Delayed Definitions for the difference betweenSet(=) andSetDelayed(:=).
$endgroup$
– MarcoB
10 mins ago
add a comment |
$begingroup$
Why would you do 'function = {a,b} [Function] a x^b' instead of function[a_, b_, x_] = a*x^b?
$endgroup$
– Pineapple
28 mins ago
$begingroup$
Because[Function]is easily entered with the escape sequence esc f n esc . AlsoFunctiondefines a pure function whilefunction[a_, b_, x_] = a*x^bdefines a replacement rule. However, they act the same way - most of the time. So it is a matter of taste.
$endgroup$
– Henrik Schumacher
24 mins ago
$begingroup$
@Pineapple Take a look at this tutorial on Defining Functions. Another good resource is the tutorial on Immediate and Delayed Definitions for the difference betweenSet(=) andSetDelayed(:=).
$endgroup$
– MarcoB
10 mins ago
$begingroup$
Why would you do 'function = {a,b} [Function] a x^b' instead of function[a_, b_, x_] = a*x^b?
$endgroup$
– Pineapple
28 mins ago
$begingroup$
Why would you do 'function = {a,b} [Function] a x^b' instead of function[a_, b_, x_] = a*x^b?
$endgroup$
– Pineapple
28 mins ago
$begingroup$
Because
[Function] is easily entered with the escape sequence esc f n esc . Also Function defines a pure function while function[a_, b_, x_] = a*x^b defines a replacement rule. However, they act the same way - most of the time. So it is a matter of taste.$endgroup$
– Henrik Schumacher
24 mins ago
$begingroup$
Because
[Function] is easily entered with the escape sequence esc f n esc . Also Function defines a pure function while function[a_, b_, x_] = a*x^b defines a replacement rule. However, they act the same way - most of the time. So it is a matter of taste.$endgroup$
– Henrik Schumacher
24 mins ago
$begingroup$
@Pineapple Take a look at this tutorial on Defining Functions. Another good resource is the tutorial on Immediate and Delayed Definitions for the difference between
Set (=) and SetDelayed (:=).$endgroup$
– MarcoB
10 mins ago
$begingroup$
@Pineapple Take a look at this tutorial on Defining Functions. Another good resource is the tutorial on Immediate and Delayed Definitions for the difference between
Set (=) and SetDelayed (:=).$endgroup$
– MarcoB
10 mins ago
add a comment |
$begingroup$
Total[#*x^#2&@@@list]
x^2 + 3 x^4 + 5 x^6
$endgroup$
add a comment |
$begingroup$
Total[#*x^#2&@@@list]
x^2 + 3 x^4 + 5 x^6
$endgroup$
add a comment |
$begingroup$
Total[#*x^#2&@@@list]
x^2 + 3 x^4 + 5 x^6
$endgroup$
Total[#*x^#2&@@@list]
x^2 + 3 x^4 + 5 x^6
answered 29 mins ago
J42161217J42161217
3,935322
3,935322
add a comment |
add a comment |
$begingroup$
Total[(#[[1]] x^#[[2]]) & /@ list]
$endgroup$
$begingroup$
Amazing, thank you! Sorry - I'm very new to Mathematica.
$endgroup$
– Pineapple
29 mins ago
add a comment |
$begingroup$
Total[(#[[1]] x^#[[2]]) & /@ list]
$endgroup$
$begingroup$
Amazing, thank you! Sorry - I'm very new to Mathematica.
$endgroup$
– Pineapple
29 mins ago
add a comment |
$begingroup$
Total[(#[[1]] x^#[[2]]) & /@ list]
$endgroup$
Total[(#[[1]] x^#[[2]]) & /@ list]
answered 33 mins ago
David G. StorkDavid G. Stork
24.5k22153
24.5k22153
$begingroup$
Amazing, thank you! Sorry - I'm very new to Mathematica.
$endgroup$
– Pineapple
29 mins ago
add a comment |
$begingroup$
Amazing, thank you! Sorry - I'm very new to Mathematica.
$endgroup$
– Pineapple
29 mins ago
$begingroup$
Amazing, thank you! Sorry - I'm very new to Mathematica.
$endgroup$
– Pineapple
29 mins ago
$begingroup$
Amazing, thank you! Sorry - I'm very new to Mathematica.
$endgroup$
– Pineapple
29 mins ago
add a comment |
$begingroup$
FromCoefficientRules[Thread[list[[All, {2}]] -> list[[All, 1]]], x]
x^2 + 3 x^4 + 5 x^6
Internal`FromCoefficientList[Normal@SparseArray[1 + list[[All, {2}]] -> list[[All, 1]]], x]
x^2 + 3 x^4 + 5 x^6
$endgroup$
add a comment |
$begingroup$
FromCoefficientRules[Thread[list[[All, {2}]] -> list[[All, 1]]], x]
x^2 + 3 x^4 + 5 x^6
Internal`FromCoefficientList[Normal@SparseArray[1 + list[[All, {2}]] -> list[[All, 1]]], x]
x^2 + 3 x^4 + 5 x^6
$endgroup$
add a comment |
$begingroup$
FromCoefficientRules[Thread[list[[All, {2}]] -> list[[All, 1]]], x]
x^2 + 3 x^4 + 5 x^6
Internal`FromCoefficientList[Normal@SparseArray[1 + list[[All, {2}]] -> list[[All, 1]]], x]
x^2 + 3 x^4 + 5 x^6
$endgroup$
FromCoefficientRules[Thread[list[[All, {2}]] -> list[[All, 1]]], x]
x^2 + 3 x^4 + 5 x^6
Internal`FromCoefficientList[Normal@SparseArray[1 + list[[All, {2}]] -> list[[All, 1]]], x]
x^2 + 3 x^4 + 5 x^6
answered 1 min ago
kglrkglr
187k10203422
187k10203422
add a comment |
add a comment |
$begingroup$
Inner[#1 x^#2 &, Sequence @@ Transpose@list, Plus]
(* Out: x^2 + 3 x^4 + 5 x^6 *)
$endgroup$
add a comment |
$begingroup$
Inner[#1 x^#2 &, Sequence @@ Transpose@list, Plus]
(* Out: x^2 + 3 x^4 + 5 x^6 *)
$endgroup$
add a comment |
$begingroup$
Inner[#1 x^#2 &, Sequence @@ Transpose@list, Plus]
(* Out: x^2 + 3 x^4 + 5 x^6 *)
$endgroup$
Inner[#1 x^#2 &, Sequence @@ Transpose@list, Plus]
(* Out: x^2 + 3 x^4 + 5 x^6 *)
answered just now
MarcoBMarcoB
36.7k556113
36.7k556113
add a comment |
add a comment |
Pineapple is a new contributor. Be nice, and check out our Code of Conduct.
Pineapple is a new contributor. Be nice, and check out our Code of Conduct.
Pineapple is a new contributor. Be nice, and check out our Code of Conduct.
Pineapple is a new contributor. Be nice, and check out our Code of Conduct.
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%2f192691%2fhow-to-substitute-values-from-a-list-into-a-function%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