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...
You are given the partial code for a function, with only the body completed. You must...
You are given the partial code for a function, with only the body completed. You must Write a complete function header, including a meaningful name (to indicate your understanding of the code), Include type annotations Use proper indentation. #FUNCTION HEADER (2 points) #DOCSTRING (3 points) #FUNCTION BODY - Do not change the code. You may copy-paste it into the answer-box but it is your choice. No marks for doing so) return x*x
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...
In this problem, you will write an implementation of BubbleSort. Your function should take in a...
In this problem, you will write an implementation of BubbleSort. Your function should take in a single line representing an array of integers, and output a single line containing the list in ascending order. For example, if you receive the following input followed by a newline: 8 7 6 5 4 3 2 1 then you should display the following output followed by a newline: 1 2 3 4 5 6 7 8 Starter code for reading the input and...
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...
You are working for a company that is responsible for determining the winner of a prestigious...
You are working for a company that is responsible for determining the winner of a prestigious international event, Men’s Synchronized Swimming. Scoring is done by eleven (11) international judges. They each submit a score in the range from 0 to 100. The highest and lowest scores are not counted. The remaining nine (9) scores are averaged and the median value is also determined. The participating team with the highest average score wins. In case of a tie, the highest median...
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT