Message Boards Message Boards

0
|
4877 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

MapIndexed & InterpolatingPolynomial code explanation?

Posted 8 years ago

I have an expression of mathematica that I cannot understand it. can anyone break it for me so that I can understand it. I have a vector which looks like :

toc = {{-0.5, 0}, {-0.3, 0}, {-0.1, 0}, {0.1, 0}, {0.3, 0}, {0.5, 0}}

and then the expression

xp = MapIndexed[ 
  InterpolatingPolynomial[ReplacePart[toc, 1, {#, 2}], x] &, 
  Range[2, order]]

I should mention that in the above expression order = 5.

thanks in advance

POSTED BY: Mohsen Rezaee
2 Replies
Posted 8 years ago

thanks that saved my day. But you didn't mention how it generate the polynomials from that expressions.

POSTED BY: Mohsen Rezaee

Hi Mohsen,

Your code is a bit unusual as it does not use the Indexed part of MapIndexed:

order = 5
toc = {{-0.5, 0}, {-0.3, 0}, {-0.1, 0}, {0.1, 0}, {0.3, 0}, {0.5, 0}}
xp = Map[InterpolatingPolynomial[ReplacePart[toc, 1, {#, 2}], x] &, Range[2, order]]

gives the same output. So I will work from there. Map basically 'fills' the # with the values given: Range[2,order] ({2,3,4,5}):

{InterpolatingPolynomial[ReplacePart[toc,1,{2,2}],x], 
InterpolatingPolynomial[ReplacePart[toc,1,{3,2}],x], 
InterpolatingPolynomial[ReplacePart[toc,1,{4,2}],x], 
InterpolatingPolynomial[ReplacePart[toc,1,{5,2}],x]}

which takes toc and replaces the {2,2}, {3,2},{4,2} {5,2} element with a 1:

{
ReplacePart[toc, 1, {2, 2}], 
ReplacePart[toc, 1, {3, 2}], 
 ReplacePart[toc, 1, {4, 2}], 
ReplacePart[toc, 1, {5, 2}]
}

{
{{-0.5,0},{-0.3,1},{-0.1,0},{0.1,0},{0.3,0},{0.5,0}},
{{-0.5,0},{-0.3,0},{-0.1,1},{0.1,0},{0.3,0},{0.5,0}},
{{-0.5,0},{-0.3,0},{-0.1,0},{0.1,1},{0.3,0},{0.5,0}},
{{-0.5,0},{-0.3,0},{-0.1,0},{0.1,0},{0.3,1},{0.5,0}}
}

Now it creates InterpolatingPolynomials with variable x for each....

POSTED BY: Sander Huisman
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