Question

In: Computer Science

x = [0,1,2,3,4,5,6,7,8]; y = [0,10,23,28,25,13,6,2,-5]; Spline interpolation, Use Matlab code Write your own spline method...

x = [0,1,2,3,4,5,6,7,8];
y = [0,10,23,28,25,13,6,2,-5];

Spline interpolation, Use Matlab code
Write your own spline method to estimate the value of the function on x ∈ [0,8],Δx = 0.1. For your 2 degrees of freedom, set the first and second
derivatives at the left boundary to 0. Save your result, the interpolated y values.(do not use Matlab's built-in spline method

Solutions

Expert Solution

others take much longer). Since the second approach contains N additions, N multiplications and N − 1 powers (with our assumption) it takes as much as 4N − 2 floating point operations. The third approach takes only N multiplications and N additions for a total of 2N floating point operations. This is the fastest and best approach, specially if N is large, and if the polynomial evaluation is a significant portion of your code (performed possibly millions of times). This approach is called Horner’s rule or nested multiplication. I compared the timings for an example polynomial of degree 20 and found that MATLAB uses about the same amount of time for the second and third approach, probably due to internal optimization when it generates machine code. 2.1.4 Counting operations: evaluating series Let’s implement the function ApproxExp function y=ApproxExp(x,n); % Output parameter: y (nth order Taylor approximation of $e^x$) % Input parameters: x (scalar) % n (integer) sumo = 1; for k=1:n sumo = sumo + x^k/factorial(k); end y = sumo; in a more efficient way using less floating point operations, as follows: function y=ApproxExp2(x,n); % Output parameter: y (nth order Taylor approximation of $e^x$) % Input parameters: x (scalar) % n (integer) temp = 1; 22 sumo = temp; for k=1:n temp = temp*x/k; sumo = sumo + temp; end y = sumo; Note that the second code replaced a power and a factorial by a multiplication and a division, which should be more efficient. The script n=100; x=1; tic ApproxExp(x,n); t1=toc tic ApproxExp2(x,n); t2=toc t1/t2 shows that the second approach is 80 times faster than the first, depending on the values of n and on the machine. 2.2 Machine Representation of real numbers, Roundoff errors 2.2.1 Decimal and binary representation of reals Reals can be represented in base 10 (decimal representation) using digits 0,. . . ,9, or base 2 (binary representation), using digits 0,1, or any other base. Examples next. Example: What number is (1534.4141)10? Example: Find the base 10 representation of (1011.01101)2 Example: Find the first 10 digits of the base 2 representation of 53.710. (Use common sense, no need to learn an algorithm here.)


Related Solutions

Write your own MATLAB code to solve the system 10 − x + sin(x + y)...
Write your own MATLAB code to solve the system 10 − x + sin(x + y) − 1 = 0 8y − cos2 (z − y) − 1 = 0 12z + sin(z) − 1 = 0 using a residual tolerance of 10^−6 and the initial guess, ~x 0 = [0.1, 0.25, 0.08]^T . Print out the values for x, y and z for each iteration in a table similar to the one you created for the problems of the...
The question is to use Matlab to find the clamped cubic spline v(x) that interpolates a...
The question is to use Matlab to find the clamped cubic spline v(x) that interpolates a function f(x) that satisfies: f(0)=0, f(1)=0.5, f(2)=2, f(3)=1.5, f'(0)=0.2, f'(3)=-1 and then plot v(x). This is my code so far: x = [0 1 2 3]; y = [0 0.5 2 1.5]; cs = spline(x,[0 y 0]); xx = linspace(0,3,101); figure() plot(x,y,'o',xx,ppval(cs,xx),'-'); IS THIS RIGHT? HOW CAN I GET MATLAB TO GIVE ME THE EQUATION OF v(x)?
assume that the data are stored in variable names x and y. write a matlab code...
assume that the data are stored in variable names x and y. write a matlab code to plot the quadratic spline and along with the data points x= 1 2 3 4 5 6 y= 40 78 125 256 348 425
Practice for Matlab. You can create own f(x). a. Write code to find and plot a...
Practice for Matlab. You can create own f(x). a. Write code to find and plot a root using the modified secant method b. Find the roots using the roots command - identify and plot root of interest c. Use polyder and roots to find and plot the minimum value d. use fminbnd to find and plot minimum value Thank you!
Use a python code to solve Use Newton interpolation to find the unique polynomial p2(x) of...
Use a python code to solve Use Newton interpolation to find the unique polynomial p2(x) of degree 2 or less, that agrees with the following data: p2(0) = 1, p2(2) = 5, p2(4) = 17.
MATLAB CODE: Making cubic spline iterpolation function. Then, To solve use Tridiagonal matrix algorithm(TDMA) xi -0.5...
MATLAB CODE: Making cubic spline iterpolation function. Then, To solve use Tridiagonal matrix algorithm(TDMA) xi -0.5 -0.4 -0.2 0 0.2 0.4 0.6 0.8 yi 0.04 0.1 0.4 1 0.35 0.2 0.3 0.04
Write a matlab code for given task Use your ‘sin’ or ‘cos’ function to generate a...
Write a matlab code for given task Use your ‘sin’ or ‘cos’ function to generate a sinusoid wave having two components as f1 = 3kHz and f2 = 5kHz and then sample it with fs = 10kHz. Calculate its fft with zero frequency component in the middle. Plot it on a properly scaled w-axis. Specify if there is aliasing or not? If there is aliasing specify which component is casing the aliasing
This code is to be written in Matlab. Write a function that will plot cos(x) for...
This code is to be written in Matlab. Write a function that will plot cos(x) for x values ranging from -pi to pi in steps of 0.1, using black *'s. It will do this three times across in one Figure Window, with varying line widths. If no arguments are passed to the function, the line widths will be 1, 2, and 3. If on the other hand, an argument is passed to the function, it is multiplier for these values....
Write a MATLAB code for the conjugate gradient method and apply it to solve the system...
Write a MATLAB code for the conjugate gradient method and apply it to solve the system Hx = b, where H is the n×n Hilbert matrix, and b is A times the vector of all ones, for (a) n = 4; (b) n = 8. Compare your numerical solutions with the exact solution (which is the vector of all ones), and report your numerical errors.
Use matlab code for bisection method and regula falsi. Thank you!
Use matlab code for bisection method and regula falsi. Thank you!
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT