Question

1 Interpolation methods 1.1 The Lagrange polynomial function (y dot,p] = my Lagrange (x, y,x_dot) Type Description Input 1xM

I'm not allowed to use polyfit or polyval functions.

The hint the homework gives is setting up a linear system for the polynomial coefficients and solving it.

The test case x = [1,2,3,4]

y = [5,-2,3,0]

x_dot = [1.5,2.5]

should result in

y_dot = -1.2500 0.2500

p = -3.333 26.0000 -61.6667 44.0000

Thanks to anyone who can answer this within the next day or so!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: If you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

clc%clears screen
clear all%clears history
close all%closes all files
format long
x = [1,2,3,4];
y = [5,-2,3,0];
x_dot = [1.5,2.5];
[y_dot,p]=myLagrange(x,y,x_dot)


function [y_dot,p]=myLagrange(x,y,x_dot)
f=y;
X=x;
Y=f;
N = length(X);
pvals = zeros(N,N);
for i = 1:N
% the polynomial with roots may be values of X other than this one
pp = poly(X( (1:N) ~= i));
pvals(i,:) = pp ./ polyval(pp, X(i));
end
P = Y*pvals;
p=P;
y_dot=polyval(P,x_dot);
end

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
I'm not allowed to use polyfit or polyval functions. The hint the homework gives is setting...
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
  • A wind tunnel test conducted on an airfoil section yielded the following data between the lift...

    A wind tunnel test conducted on an airfoil section yielded the following data between the lift coefficient (CL) and the angle of attack (?): 12 1.40 16 1.71 20 1.38 de CL 0.11 0.55 0.95 You are required to develop a suitable polynomial relationship between ? and CL and fit a curve to the data points by the least-squares method using (a) hand calculations and (b) Matlab programming Hint: A quadratic equation (parabola) y(x)-aa,x +a x' can be used in...

  • P2) Write a MATLAB function myLinReg Username that is defined below. Use the in-built MATLAB func...

    P2) Write a MATLAB function myLinReg Username that is defined below. Use the in-built MATLAB function sum( ) to ease your programming (you are NOT allowed to use polyfit() and polyval()). Test the output of this function with the results obtained by hand for P1. Submit printout of program and a screenshot of the command window showing the results for P1. function [coeffvec, r2]-myLinReg_Username (xi,yi) %Function file: myLinReg-Username .m Purpose : 8 To obtain the parameters of a L.S. linear...

  • LA Variables - TempPress 1 TempPress X # 34x16 table 10 13 16 VarName4 VarName7 VarName8...

    LA Variables - TempPress 1 TempPress X # 34x16 table 10 13 16 VarName4 VarName7 VarName8 11 VarName11 12 VarName 12 VarName 16 1 Energy) VarName3 NaN NaN" Heightm1 NaN NaN Energy)1 NaN NaN Heightm2 NaN NaN Energy)2 NaN NaN 0 0 0" 0- ino 00 Heightm NaN NaN 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 49.0500 98.1000 147.1500 196.2000 - 245.2500" 294.3000 343.3500 392.4000 441.4500 490.5000 539.5500 588.6000 - 637.6500"...

  • please provide full answer with comments this is just begining course of c++ so don't use...

    please provide full answer with comments this is just begining course of c++ so don't use advanced tequenicks I'll put main.cpp, polynomial.h, polynomial.cpp and Cimg.h at the bottom of pictures. If you help me with this will be greatly thankful thank you main.cpp #include "polynomial.h" #include "polynomial.h" #include "polynomial.h" #include "polynomial.h" #include <iostream> using std::cout; using std::endl; int main() { pic10a::polynomial p1; p1.setCoeff(0, 1.2); p1.setCoeff(3, 2.2); p1.setCoeff(7, -9.0); p1.setCoeff(7, 0.0); //degree of polynomial is now 3 cout << p1 <<...

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