Question

% 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 xp=55 is: '); P_xp=P_x

_______

given function f(x)=cos(x)-x

A. Edit the program in such a way it:

1. Prompts the user to enter a string containing the values of
x (x0, x1,

x2,...xn).

2. Calculates the values of f(x) that should be filled in the
string called f_x. 3. Returns the value of the P3(x1) (Third order
Lagrange InterpolatingPolynomial evaluated at x=x1).

B. Compare the P3(x1) returned by the program to the f(x1)
available inside

the string f_x.

Answer #1

We have modified the the given code in the required form.

*OUTPUT*

-------------------------------------------** MATLAB
code**-------------------------------------------

clc;

clear all

format short;

fprintf('\n\n')

x=input('Enter the values of x as a vector: ');

f_x=cos(x)-x;

n=numel(x)-1;

% xp=input('Enter a value xp between 0 and 100: ');

xp=x(2);

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

fprintf('\n\n')

disp (['The polynomial P_xp at x1=',num2str(x(2)), ' is: ',
num2str(P_x)]);

fprintf('\n\n')

disp (['Absolute error at x1=',num2str(x(2)), ' is: ',
num2str(abs(P_x-f_x(2)))]);

fprintf('\n\n')

Design a program that calculates the amount of money a person
would earn over a period of time if his or her salary is one penny
the first day, two pennies the second day, and continues to double
each day. The program should ask the user for the number of days.
Display a table showing what salary was for each day, and then show
the total pay at the end of the period. The output should be
displayed in a...

Problem 3 you can use Matlab and also i give u the Problem 1
code its on Matlab
Using the same initial code fragment as in Problem 1, add code
that calculates and plays y (n)=h(n)?x (n) where h(n) is the
impulse response of an IIR bandpass filter with band edge
frequencies 750 Hz and 850 Hz and based on a 4th order Butterworth
prototype. Name your program p3.sce
this is the Problem 1 code and the solutin
clear; clc;...

Problem 1 ...... you can use Matlan i got one so all
what i need is 2, 3 and 4 one of them or all of them ..
thanks
The following Scilab code generates a 10-second “chirp” with
discrete frequencies ranging from 0 to 0.2 with a sampling
frequency of 8 kHz.
clear; Fs = 8000;
Nbits = 16;
tMax = 10;
N = Fs*tMax+1;
f = linspace(0.0,0.2,N);
x = zeros(f);
phi = 0;
for n=0:N-1 x(n+1) = 0.8*sin(phi);
phi...

The following algorithm finds the initial substring of y
that can be reversed and found in y. For example,
longestInitialReverseSubstringLength(“aabaa”) = 5, because “aabaa”
is the same string forwards and backwards, so the longest initial
substring that can be reversed and found in the string is “aabaa”.
Also, longestInitialReverseSubstringLength(“bbbbababbabbbbb”) is 6,
because “babbbb” can be found in the string (see color-highlighted
portions of the string), but no longer initial string exists
reversed in any part of the string.
longestInitialReverseSubstringLength(String
y)...

Modify your Free Fall program below to plot the energy vs. time
for a baseball dropped from a height of 1000 feet until it hits the
ground. Now add in the effects of air resistance into your program.
This time, on the energy plot, you will plot four quantities: KE
(Red line), PE (Green line), Energy lost due to air resistance
(purple line), and total Energy (blue circles). Note, you must
calculate the energy lost by using the definition of...

My assignment:
Triplet Template Class Directions:
Define a template class for a generic triplet. The private data
member for the triplet is a generic array with three elements. The
triplet ADT has the following functions:
default constructor
explicit constructor: initialize the data member using
parameters
three accessors (three get functions) which will return the
value of each individual element of the array data member
one mutator (set function) which will assign values to the
data member...

The C++ program steps through the array x[]. For each i, if x[i]
< x[i+1], i is saved in the array ascend[], in order. Compile
and run the program; it should print 0 4 5.
In this exercise, you’ll try to translate the C++ program to
MIPS. Some of the more tedious parts are already given in
Assignment3.F19.s. You won’t have to write the data allocation
sections, some of the initializations, and the output loop at the
end.
So the...

Write a method that returns the sum of all the elements in a
specified column in a 3 x 4 matrix using the following header:
public static double sumColumn(double[][] m, int
columnIndex)
The program should be broken down into methods, menu-driven, and
check for proper input, etc.
The problem I'm having is I'm trying to get my menu to execute
the runProgram method. I'm not sure what should be in the
parentheses to direct choice "1" to the method. I'm...

/*
This program should check if the given integer number is
prime.
Reminder, an integer number greater than 1 is prime if
it divisible only by itself and by 1.
In other words a prime number divided by any other natural
number
(besides 1 and itself) will have a non-zero remainder.
Your task:
Write a method called checkPrime(n) that will
take
an integer greater than 1 as an input, and return true
if that integer is prime; otherwise, it should...

Write a program of wordSearch puzzle that use
the following text file as an input. The output should be like
this: PIXEL found (left) at (0,9). ( Use
JAVA Array ) .Please do not use
arrylist and the likes!
Hints
• The puzzle can be represented as a right-sized two-dimensional
array of characters (char).
• A String can be converted into a right-sized array of characters
via the String method toCharArray.
. A word can occur in any of 8...

ADVERTISEMENT

Get Answers For Free

Most questions answered within 1 hours.

ADVERTISEMENT

asked 13 minutes ago

asked 13 minutes ago

asked 14 minutes ago

asked 14 minutes ago

asked 14 minutes ago

asked 16 minutes ago

asked 20 minutes ago

asked 24 minutes ago

asked 26 minutes ago

asked 30 minutes ago

asked 31 minutes ago

asked 45 minutes ago