cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

Implementation of Lagrange Interpolation

JA_9803374
5-Regular Member

Implementation of Lagrange Interpolation

Hello, I am trying to implement a program where I can find out the "y" value for a given "x" value using Lagrange Interpolation with data points (x,y) like the ones shown below:

JA_9803374_1-1614219290768.png

JA_9803374_2-1614219299785.pngJA_9803374_3-1614219316454.png

The program should use these expressions:

JA_9803374_5-1614219459897.png

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

It doesn't look like you've put too much thought and effort into this.

 

However, as promised!

View solution in original post

9 REPLIES 9
JXBWk
13-Aquamarine
(To:JA_9803374)

While interesting what have you got so far? Couldn't see any attached mcad sheet!

Where are the stumbling blocks?

Fred_Kohlhepp
23-Emerald I
(To:JXBWk)

Assuming Werner's right, and this IS homework, you need to show an honest effort (AKA, post your worksheet!)

 

That said, these were developed (as LaGrange polynomial interpolation functions) using Prime 4.0 Express.  Worksheet will be posted upon demonstration of honest effort.

Fred_Kohlhepp_0-1614260239477.png

 


@Fred_Kohlhepp wrote:

Assuming Werner's right, and this IS homework,

 


The poster himself labelled his question with "Math Homework" 🙂

Thereby demonstrating (once again) that you are much more observant than I!  😉

 

But I still enjoyed the challenge.

JA_9803374
5-Regular Member
(To:Fred_Kohlhepp)

This was my original attempt at it. However I realized two things, Mathcad won't simplify the polynomial basis expressions. Secondly, this method is really inefficient as the Lagrange polynomial degree increases. So I stopped trying this method. I figured I could use two loops and the actual expression. However I'm having trouble implementing that.

It doesn't look like you've put too much thought and effort into this.

 

However, as promised!

I agree with you and your version looks so familiar compared to what I had prepared 🙂

Werner_E_0-1614271302046.png

Splitting may make it better readable

Werner_E_0-1614271646642.png

 

@JA_9803374 

Keep in mind that Freds sheet assumes the default setting for ORIGIN (which is 0). In your sheet you changed ORIGIN to be 1 so you have to slightly modify Freds approach to take that into account.

JA_9803374
5-Regular Member
(To:Werner_E)

Thank you guys! I just needed this because I am new to Mathcad programming and I was just unsure how some of the syntax works for the product function and got completely stuck! thanks for helping me get started!

As this is obviously homework you should show your attempts for a solution. This also would help us to see where you have problems with the handling of Prime so we can help.

If you already derived a solution you may check your function by creating a plot and also check against the built-in "polyfit" function:

Werner_E_1-1614251899670.png

 

Top Tags