Question

Problem 5 (programming): Create a MATLAB function named lagrange interp.m to perform interpolation using Lagrange polynomials
function y= lagrange interp(X1, y1, X) % LAGRANGE INTERP : use Lagrange polynomials to interpolate value of y at % input x us
0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

clc%clears the screen
clear all %clears the history
format long;
x=input('Enter x vector(depth) from table as mentioned in question: ');
y=input('Enter x vector(temp) from table as mentioned in question: ');
p5a=lagrange_interp(x(3:5),y(3:5),-150)
p5b=lagrange_interp(x(3:6),y(3:6),-150)
p5c=lagrange_interp(x,y,-150)
depth=-330:10:-10;
temp=lagrange_interp(x(3:5),y(3:5),depth)
figure(5);
plot(temp,depth,x,y,'o');
p5d='See figure 5';

function [yhat]=lagrange_interp(x,y,interpx)

X=x;
f=y;
x=interpx;

l=0;
for i=1:length(X)
li=1;
for j=1:length(X)
if i~=j
li=(li).*((x-X(j))/(X(i)-X(j)));
end
end
l=(l)+((li)*f(i));
end
yhat=l;
  
end

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Problem 5 (programming): Create a MATLAB function named lagrange interp.m to perform interpolation using Lagrange polynomials....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT