Question
In matlab Obtain a piecewise linear interpolation of the function f(x) = ex/a sin(x2 +b) where a is the rst digit of your SUID and
In matlab
Obtain a piecewise linear interpolation of the function f(x) = ex/a sin(x2 +b) where a is the rst digit of your SUID and b is its last digit. Interpolation should take place on the interval [0,7]. Try equally spaced nodes with distance h = 1, h = 0.5, until you nd one that works reasonably well. Report the spacing h you found suitable in a comment.
Method: To begin with, dene a function f (function handle would work). Calculate the nodes, the values of f at nodes, and the slopes of interpolating segments (the vector slope below; you may refer to the function pwL). Then evaluate the interpolant.
One approach is this: t = linspace (0 ,7 ,100);
pl = zeros ( size ( t ));
for i = 1: length ( t ) i f t ( i ) == x(1) pl ( i ) = y(1) + slope (1) ( t ( i ) x(1) );
else id = sum(x pl ( i ) = y( id ) + slope ( id ) ( t ( i ) x( id ) ); end end Finally, plot both f and the interpolant together for comparison, using dierent colors.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started