conditional Product mathematica

痞子三分冷 提交于 2019-12-25 08:21:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!