Question

1. Write a function to evaluate a Lagrange interpolating polynomial at a given value z. Given...

1. Write a function to evaluate a Lagrange interpolating polynomial at a given value z. Given you have n arbitrary points (xi ; yi) to start with to build the polynomial. Use the algorithm provided for this assignment. To receive full marks you must: • Name of your function must be Lpoly5 • Use the variables in the order they are described in the Algorithm handout for this lab. • Submit the .m file for your function with the correct name. To receive full marks, your function, Lpoly5, but evaluate a polynomial of created from an arbitrary number of starting points (xi ; yi) (n points). This will be tested with data not provided to students. As a test case, you can use the points from the lab handout. Do not submit your results of this case. It is for your assistance only.

Homework Answers

Answer #1

function Lpoly5

clear all;

clc;

%n=input('Enter the value of n: ');

%disp('Enter value of x: ')

%for i=1:n

% x(i)=input('x: ');

%end

%disp('Enter value of x: ')

%for i=1:n

% y(i)=input('y: ');

%end

x= [1,2,0,3]

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

syms z

sum=0;

d=1;

%z=input('Enter value of z: ')

z=8

fprintf('Coefficients of polynomial by Langrange method:\n');

for i=1:4

for j=1:4

if i~=j

d=d*((z-x(j))/(x(i)-x(j)));

end

sum=sum+d*y(i);

end

fprintf('L%d',i-1);

d

end

disp('Lagrange interpolating polynomial at a given value z is: ')

sum

Know the answer?
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
Similar Questions
% This program calculates the Lagrange interpolating polynomial of a given % xp and returns the...
% This program calculates the Lagrange interpolating polynomial of a given % xp and returns the value clc, clear all; format short; x=[0 20 40 60 80 100];% This string can be filled by Matlab f_x=[26.0 48.6 61.6 71.2 74.8 75.2]; % You can create a separate function to fill f_x automatically n=length(x)-1; xp=input('Enter a value xp between 0 and 100: '); P_x=0; for i=1:n+1 L_k=1; for j=1:n+1 if j~=i L_k=L_k*(xp-x(j))/(x(i)-x(j)); end end P_x=P_x+f_x(i)*L_k; end disp ('The polynomial P_xp at...
1 Approximation of functions by polynomials Let the function f(x) be given by the following: f(x)...
1 Approximation of functions by polynomials Let the function f(x) be given by the following: f(x) = 1/ 1 + x^2 Use polyfit to approximate f(x) by polynomials of degree k = 2, 4, and 6. Plot the approximating polynomials and f(x) on the same plot over an appropriate domain. Also, plot the approximation error for each case. Note that you also will need polyval to evaluate the approximating polynomial. Submit your code and both plots. Make sure each of...
A therapist would like to evaluate an intervention for treating depression. A sample of n =...
A therapist would like to evaluate an intervention for treating depression. A sample of n = 20 depressed clients is obtained, and each person’s level of depression is measured using a standardized questionnaire before they begin the therapy program. Two weeks after therapy, each client’s level of depression is measured again. The average level of depression dropped by 4.0 points following therapy. The difference scores had a variance of 64. a. State the null hypothesis. b.            Identify the appropriate statistical...
A therapist would like to evaluate an intervention for treating depression. A sample of n =...
A therapist would like to evaluate an intervention for treating depression. A sample of n = 20 depressed clients is obtained, and each person’s level of depression is measured using a standardized questionnaire before they begin the therapy program. Two weeks after therapy, each client’s level of depression is measured again. The average level of depression dropped by 4.0 points following therapy. The difference scores had a variance of 64. a. State the null hypothesis. b. Identify the appropriate statistical...
1. Write 3n + 1 Sequence String Generator function (1 point) In lab5.py complete the function...
1. Write 3n + 1 Sequence String Generator function (1 point) In lab5.py complete the function sequence that takes one parameter: n, which is the initial value of a sequence of integers. The 3n + 1 sequence starts with an integer, n in this case, wherein each successive integer of the sequence is calculated based on these rules: 1. If the current value of n is odd, then the next number in the sequence is three times the current number...
You must write a function that works like a small editor. It should open an existing...
You must write a function that works like a small editor. It should open an existing file (let us say this is File1.txt. This file must exist before the function is run), read it line by line. Then write it to another file (let us say this is File2.txt. This file need not exist since Python will create it). However, if a certain line exists in the first file, it should be replaced by another line supplied by you. You...
Use a few sentences to describe the problem given below . Also, Identify the nouns and...
Use a few sentences to describe the problem given below . Also, Identify the nouns and verbs used in the below project descriptions.  Identified nouns, list the ones that are necessary to define variables in your program. For each variable, specify its name, data type, and what information it is used to store. Write the pseudo code algorithm (i.e. algorithm steps) to solve this problem. (For the base salaries and commission rates use constants instead to keep these values. Use the...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
**please write code with function definition taking in input and use given variable names** for e.g....
**please write code with function definition taking in input and use given variable names** for e.g. List matchNames(List inputNames, List secRecords) Java or Python Please Note:    * The function is expected to return a STRING_ARRAY.      * The function accepts following parameters:      *  1. STRING_ARRAY inputNames      *  2. STRING_ARRAY secRecords      */ Problem Statement Introduction Imagine you are helping the Security Exchange Commission (SEC) respond to anonymous tips. One of the biggest problems the team faces is handling the transcription of the companies reported...
Programming Exercise 2: implement the member function moveToNth(...) that removes the item marked by the cursor...
Programming Exercise 2: implement the member function moveToNth(...) that removes the item marked by the cursor and inserts it as the nth element of the list; test your implementation by turning the flag LAB3_TEST2 from 0 to 1 in config.h; - Programming Exercise 3: implement the ListArray member function find(...) that searches for the element given as a parameter; the search starts at the cursor and stops when it finds the element or at the end of the list; the...