问题
I am trying to replicate Lagrange Interpolating Polynomials in Mathematica. The wiki for an explanattion of them can be seen here. This is my code (sorry I don't know how to place mathematica code in SO so I have an image):
My problem is that I want a conditional product. if j = m I just want to skip over that product and evaluate the next one. That's why I put the false evaluation as 1. Any suggestions?回答1:
All built-in functions start with a capital letter. So the conditional is If[...]
not if[...]
. Fix that and everything works fine!
With[{k = 5}, Sum[Product[
If[j != m, (x - x[m])/(x[j] - x[m]), 1], {m, 0, k}], {j, 0, k}]]
来源:https://stackoverflow.com/questions/8410379/conditional-product-mathematica