Question

In: Mechanical Engineering

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

Solutions

Expert Solution

hi first write the xi and yi in given format -

#ans.m

xi=[-0.5 -0.4 ...... 0.8];

yi=[0.04 0.1 ........ 0.04];

xii=linspace(-0.5 0.8 20);

yii=spline(xi,yi,xii); %%cubic spline command interpolate to xii points..

then use unmkpp command to get the coefficients..

these coeeficient will be in matrix shown below function.put syntax as per your own..

%%now for solving using tridiagonal matrix algorithm -

function y = tridiag( a, b, c, f )

%  Solve the  n x n  tridiagonal system for y:
%
%  [ a(1)  c(1)                                  ] [  y(1)  ]   [  f(1)  ]
%  [ b(2)  a(2)  c(2)                            ] [  y(2)  ]   [  f(2)  ]
%  [       b(3)  a(3)  c(3)                      ] [        ]   [        ]
%  [            ...   ...   ...                  ] [  ...   ] = [  ...   ]
%  [                    ...    ...    ...        ] [        ]   [        ]
%  [                        b(n-1) a(n-1) c(n-1) ] [ y(n-1) ]   [ f(n-1) ]
%  [                                 b(n)  a(n)  ] [  y(n)  ]   [  f(n)  ]
%
%  f must be a vector (row or column) of length n
%  a, b, c must be vectors of length n (note that b(1) and c(n) are not used)

% some additional information is at the end of the file

n = length(f);
v = zeros(n,1);   
y = v;
w = a(1);
y(1) = f(1)/w;
for i=2:n
    v(i-1) = c(i-1)/w;
    w = a(i) - b(i)*v(i-1);
    y(i) = ( f(i) - b(i)*y(i-1) )/w;
end
for j=n-1:-1:1
   y(j) = y(j) - v(j)*y(j+1);
end

ref: Mathworks/help/matlab


Related Solutions

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)?
IN MATLAB, Create a 8x8 magic matrix. Then use MATLAB built in function, sum, to calculate...
IN MATLAB, Create a 8x8 magic matrix. Then use MATLAB built in function, sum, to calculate the sum of each column. Use subscript notation to find the 6th element and the last element of each magic square. Find the maximum of all the elements in each magic square.
solve in MATLAB and screenshot code ?′′ −??′ +??= ???(????−?????)
solve in MATLAB and screenshot code ?′′ −??′ +??= ???(????−?????)
Write a Matlab function for a matrix that takes in a matrix in echelon form and...
Write a Matlab function for a matrix that takes in a matrix in echelon form and will return the row canonical form. The function cannot use rref, or any other matlab built in functions.
Solve using matlab code!! Use the graphical method to solve 4x1 − 8x2 = −24 x1...
Solve using matlab code!! Use the graphical method to solve 4x1 − 8x2 = −24 x1 + 6x2 = 34 Check your results by substituting them back into the equations.(include this on the code)
use matlab to create a function that finds inverse of 2x2 matrix and returns result. Should...
use matlab to create a function that finds inverse of 2x2 matrix and returns result. Should be a error check to make sure matrix is 2x2, and nonsingular.
construct A*star algorithm for solving the 8-puzzle problem . Use MATLAB or Python .Your code should...
construct A*star algorithm for solving the 8-puzzle problem . Use MATLAB or Python .Your code should include two heuristic functions -misplaced tiles and calculation of manhattan distance. The code should work for all cases of puzzle.
Use MATLAB to write a function subroutine horner_yourlastname(a, x0, d) that uses Horner’s algorithm to evaluate...
Use MATLAB to write a function subroutine horner_yourlastname(a, x0, d) that uses Horner’s algorithm to evaluate a polynomial at a given point x0. This code should have three inputs in the order specified above: a: a vector of coefficients of the polynomial of interest. The first element of the vector should be the leading coefficient, and the last element should be the trailing coefficient. i. e. The polynomial p(x) = anx n + an−1x n−1 . . . a1x +...
what is the code to solve and graph the following function in matlab dv/dt=80.5(1-e^(.4t))
what is the code to solve and graph the following function in matlab dv/dt=80.5(1-e^(.4t))
Need to write a code using c# Strassen’s Algorithm for matrix multiplication.
Need to write a code using c# Strassen’s Algorithm for matrix multiplication.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT