Info

此问题已关闭。 请重新打开它进行编辑或回答。

How do you make a function that returns the Lagrange interpolating polynomial?

1 次查看(过去 30 天)
1. Write a function: function [P] = MyLagrangeInterpolater(nodes_x, nodes_y) that returns the Lagrange interpolating polynomial, P(x), as a Matlab function using sample points (x, f(x)) defined by the values in nodes_x and nodes_fx respectively. The pseudocode on the previous page should give a good start on writing this function. Hint: See Examples 1 and 2 in the examples file for more information on double for-loops and on how to skip iterations in a for-loop.
(a) Consider the function f(x) = cos(x) on the interval [−π, π]. Use your MyLagrangeInterpolater function to generate a degree N = 1, 2, 3, 4, 5, 6 polynomial function PN (x) using equally spaced nodes on the interval. Evaluate both f(xi) and PN (xi) on 1000 equally spaced xi values on the interval and print the max error: EN = max xi |f(xi) − PN (xi)| for these points.

回答(0 个)

此问题已关闭。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by