Question

In: Computer Science

For a function, only the numerical values are available as shown in the table bellow, Write...

For a function, only the numerical values are available as shown in the table bellow, Write a MATLAB script file to calculate the derivative of y, use a ‘for loop’ to apply the centered method to the middle 8 points. Hint: Define x and y as arrays, so you can easily call them in formula and the for loop

xi = 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0

yi = 1.815 2.16 2.535 2.94 3.375 3.84 4.335 4.86 5.415 6

Solutions

Expert Solution

Answer:----

Given,

xi = 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0

yi = 1.815 2.16 2.535 2.94 3.375 3.84 4.335 4.86 5.415 6

MATLAB script file to calculate the derivative of y, use a ‘for loop’ to apply the centered method to the middle 8 points

Here the code is

%Define function

function ff= forward(yi,xi,p)

%Find value

ff= (yi(p + 1) - yi(p)) / (xi(p + 1) - xi(p));

%End

end

%Define function

function bb= backward(yi,xi,p)

%Find value

bb = (yi(p) - yi(p - 1)) / (xi(p) - xi(p - 1));

%End

end

%Define function

function cc= central(yi, xi, p)

%Find value

cc = (yi(p + 1) - yi(p - 1)) / (xi(p + 1) - xi(p - 1));

%End

end

%Define xi

xi=[1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0];

%Define yi

yi=[1.815 2.16 2.535 2.94 3.375 3.84 4.335 4.86 5.415 6];

%Define value

size =10;

%Define value

di=zeros(size,1);

%Call Function

di(1) = forward(yi, xi, 1);

%Loop

for n = 2:size-1

%Call Function

di(n) = central(yi, xi, n);

end

%Call Function

di(size) = backward(yi, xi, size);

%Display message

fprintf('\n %s   %s %s','xi', 'yi', 'Derivative');

%For loop

for n=1:10

%Display message

fprintf('\n %.2f %.3f %.3f',xi(n), yi(n), di(n));

%End

end

The sample output :---


Related Solutions

VIII. a. Fill in the appropriate numerical values in the table below for the surplus or...
VIII. a. Fill in the appropriate numerical values in the table below for the surplus or shortage of baseball caps in the fourth column and the effect on price in the fifth column. Market Demand and Supply Schedules for Baseball Caps Price ($ per cap) Quantity demand-ed (caps per week) Quantity supplied (caps per week) Surplus (+) or Shortage (-) Effect on Price (up or down) $25 8000 14000 $20 9000 12000 $15 10000 10000 $10 11000 8000 $5 12000...
The values of y and their corresponding values of y are shown in the table below...
The values of y and their corresponding values of y are shown in the table below x 2 3 4 4 6 y 2 3 5 4 6 A) Calculate the coefficient of correlation; B) Calculate the coefficient of determination; C) Obtain the regression coefficients and write the regression expression; D) Provide your prediction of the dependent variable if the value of the independent variable is 4.
(C++ only please) Write a function called maximum that takes an array of double values as...
(C++ only please) Write a function called maximum that takes an array of double values as a parameter and returns the largest value in the array. The length of the array will also be passed as a parameter. (Note that the contents of the array should NOT be modified.) Write a function called printReverse that takes an array of characters and the length of the array as parameters. It should print the elements of the array in reverse order. The...
Derive an equation for the available NPSH for a pump is bellow the water in the...
Derive an equation for the available NPSH for a pump is bellow the water in the suction reservoir. Support your derivation by drawing.
Two investments with varying cash flows (in thousands of dollars) are available, as shown in Table....
Two investments with varying cash flows (in thousands of dollars) are available, as shown in Table. At time 0, $10,000 is available for investment, and at time 1, $7,000 is available. Investment 0 1 2 3 A -6 -5 7 9 B -8 -3 9 7 Assuming that r = 0.40 (4%), set up an LP whose solution maximizes the NPV obtained from these investments. Graphically find the optimal solution to the LP.
After Reading the real life scenario bellow.... What options are available for an employer who is...
After Reading the real life scenario bellow.... What options are available for an employer who is looking at a way to provide good benefits without increased costs to either the employees or to the practice. Assume that your current health insurance is a traditional plan in which there is an annual $200 deductible and 20% coinsurance regardless of which doctor you go to?? "Sunshine Medical Group, a group of 25 employees located in a metropolitan area, has elected to purchase...
Consider a world that only consists of the three stocks shown in the following​ table: LOADING.......
Consider a world that only consists of the three stocks shown in the following​ table: LOADING.... a. Calculate the total value of all shares outstanding currently. b. What fraction of the total value outstanding does each stock make​ up? c. You hold the market​ portfolio, that​ is, you have picked portfolio weights equal to the answer to part b with each​ stock's weight is equal to its contribution to the fraction of the total value of all stocks. What is...
Consider a world that only consists of the three stocks shown in the following​ table: LOADING......
Consider a world that only consists of the three stocks shown in the following​ table: LOADING... . a. Calculate the total value of all shares outstanding currently. b. What fraction of the total value outstanding does each stock make​ up? c. You hold the market​ portfolio, that​ is, you have picked portfolio weights equal to the answer to part b with each​ stock's weight is equal to its contribution to the fraction of the total value of all stocks. What...
Find a possible formula for the trigonometric function whose values are in the following table. x...
Find a possible formula for the trigonometric function whose values are in the following table. x 0 2 4 6 8 10 12 y 8 2 -4 2 8 2 -4 y =
1. Find a possible formula for the trigonometric function whose values are in the following table....
1. Find a possible formula for the trigonometric function whose values are in the following table. X 0 2 4 6 8 10 12 Y 5 1 -3 1 5 1 -3 y=? 2. A population of rabbits oscillates 15 above and below an average of 128 during the year, hitting the lowest value in January (t = 0). Find an equation for the population, P, in terms of the months since January, t. P(t) =    What if the lowest...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT