Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

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

1 Ansicht (letzte 30 Tage)
Seungryul Lee
Seungryul Lee am 24 Feb. 2022
Geschlossen: John D'Errico am 24 Feb. 2022
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.

Antworten (0)

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by