Question

In: Advanced Math

Write a Matlab m-script to compute the backward difference approximation A = f(a)−f(a−h) h of the...

Write a Matlab m-script to compute the backward difference approximation A = f(a)−f(a−h) h of the derivative T = f0(a) for f(x) = sin(x) and a = π/3 using each value of h in the sequence 2−n (n = 1,2,3,···,52).

Solutions

Expert Solution

MATLAB Code:

close all
clear
clc

f = @(x) sin(x);
a = pi/3;

fprintf('%-20s%-20s\n--------------------------------------------\n', 'h', 'Backward Diff., A')
for n = 1:52
h = 2^(-n);
back_diff = (f(a) - f(a - h)) / h;
fprintf('%-20.8e%-20.16f\n', h, back_diff)
end

Output:


Related Solutions

1. Compute forward, centered and backward difference approximation for the first ??? derivativeof?=????at?=4 usingavalueof h=12 ,?h??h=24...
1. Compute forward, centered and backward difference approximation for the first ??? derivativeof?=????at?=4 usingavalueof h=12 ,?h??h=24 . Then estimate the true percent relative error for each approximation. ??′ = −0.79106 ??? = 11.8738% ??′ = −0.60702 ??? = 14.1535% ??′ = −0.69904 ??? = 1.1398%
Write a MATLAB script file that will give the value of f(x) using method of least...
Write a MATLAB script file that will give the value of f(x) using method of least squares and asks the user to enter values of x, y, n (curve fit), and x for f(x).
Write a MATLAB script file that will give the value of f(x) using method of least...
Write a MATLAB script file that will give the value of f(x) using method of least squares and asks the user to enter values of x, y, n (linear, quadratic, or cubic), and x for f(x).
Write and upload a MATLAB script to do the following. Compute the sequence S(n+1) = (2...
Write and upload a MATLAB script to do the following. Compute the sequence S(n+1) = (2 – K) S(n) – S(n-1) ;   Assume S(1) = 0, S(2) = 1; (a)    Case 1, Assume K = 1 (b)    Case 2, Assume K = 2 (c)     Case 3, Assume K = 4 Plot all of these on the same plot, for N = 1 to 20
Write a Matlab script-file probl1.m to execute the requested commands (as much as possible) in the...
Write a Matlab script-file probl1.m to execute the requested commands (as much as possible) in the exercises below. Increase N a number of times according to N = 4, 8, 16, 32, 64, 128, . . . (1) Determine for each N the (exact) error. (2) Determine for N ≥ 16 also the convergence ratio q(h/2). This script should be based on a function-file trap.m (trapezoidal integration) as follows: function [totarea] = trap(N) format long; a = 0; b =...
Assuming that the variables a, b, c, d, and f are scalars, write MATLAB statements to compute and display
Assuming that the variables a, b, c, d, and f are scalars, write MATLAB statements to compute and display the following expressions. Test your statements for the values a = 1.12, b = 2.34, c = 0.72, d = 0.81, and f = 19.83.
write a matlab script for double mass spring system with animation.
write a matlab script for double mass spring system with animation.
Part A: Write a MATLAB script to find the volume of the cylinder in gallons, as...
Part A: Write a MATLAB script to find the volume of the cylinder in gallons, as well as the tank dimensions in feet. Assume that the initial measurements are 7 meters in diameter and 11 meters tall. Display your final answers to the screen using disp and a statement without a semicolon, e.g. write the following into your script disp(‘The capacity in U.S. gallons is:’), capacity, where capacity is a variable that you defined in preceding calculations. Part B: In...
(MATLAB) Write a script that would create a 3x5 matrix of random integers and write this...
(MATLAB) Write a script that would create a 3x5 matrix of random integers and write this new matrix to a file called “Assignment3_Question5.dat”.
MATLAB Function: (Backward substitution) Write a function that takes an upper triangular matrix U, and a...
MATLAB Function: (Backward substitution) Write a function that takes an upper triangular matrix U, and a vector b as input and returns the solution of the linear system U x = b. Use this function in the case when U is made of the numbers [(3,2,1),(0,5,4),(0,0,6)], and b = [1,1,−6]^T.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT