Option 1: Polynomial Interpolation Your task is to create a function animateInte
ID: 3733424 • Letter: O
Question
Option 1: Polynomial Interpolation Your task is to create a function animateInterpolation(fs, x81, x82) that produces an animation showing how an interpolating polynomial changes as the interpolation nodes change. The function should take the following inputs: . fs (, f', f'". .: a cell array containing f and its derivatives. . xs1: the interpolation nodes at the start of the animation. e xs2: the interpolation nodes at the end of the animation. Your program should have the following properties: 1. The program should include a function generalInterpolation(fs,xs) that finds the interpolating polynomial including in cases where there are repeated points (inlcud- ing Hermite interpolation, where the points are doubled, and Taylor series, where all nodes are in the same location). It should do this by constructing a divided differ- ence table, then returning the polynomial defined by the table and the interpolating nodes xs. If you find this part too difficult, you may write your program assuming all points in xs1,xs2 are distinct, and use Matlab's polyfit,polyval instead of a divided difference table. 2. The interpolating nodes should change "smoothly" over time from the points in xs1 to the corresponding points in xs2. One way to do this is to define xpts t+xs1 + (1-t) xs2 as t changes from 0 to 1, but you might consider other functions as well. 3. The limits of the x-axis and y-axis for the animation should remain fixed 4. Optionally, allow the user to save the animation as a GIFExplanation / Answer
Interpolating with Animated can allow us to bind to our Animated.Values that we create and change the output. So for example, maybe as a user scrolls or drags a card around you can interpolate from that Animated.Value and change things like the background color and or rotation.
Not only can you do colors and rotation but you can scale down or scale up values. Setting an inputRange and subsequent outputRange can allow you to adjust the values.
For example maybe you want the opacity to also be bound to the dragging of a card.
You could accomplish that like so
The this._opacityAnimation can be used just like an Animated.Value and can be passed into any Animated.View and or Animated component. What the interpolation in this case is doing is as the x value in our _animtedValue increases from 0to 150 it is determine the step and subsequent outputRange between 1 and .2.
So when our x value is 0, our interpolated opacity value will be 1, at 150 it will be .2, and when it's at 75 it'll be .4opacity.
You may be thinking to yourself, well what if the user moves the card more than 150? Well some users may think it will automatically stop and our _opacityAnimation will stay at .2. That isn't the case be default.
You must specify how the interpolation should be extrapolated. If you want it to stop at .2 no matter how far the x goes than you must specify extrapolate:'clamp' like so.
Clamp is VERY IMPORTANT to remember as you may have unintended side effects, especially when dealing with colors and rotation.
Additionally you must pass in the same amount of values in inputRange and outputRange. This can be weird as you may find yourself duplicating some values in outputRange occasionally. I've mostly run into this sort of thing when dealing with colors.
Extrapolate
Alright we just talked about extrapolate however we have a few other options.
The 3 options we have are clamp, identity, and extend. Extend is the default which may seem obvious, but as stated it will continue the interpolation past the end value at whatever the current step is.
We also have more than just extrapolate. We have access to what the interpolation does when animating left => rightand additionally when animating from right => left.
That may seem confusing so let me explain. Take this as an example
Clamp/Extend
So assume a user is dragging a square, and if the square is moved from the 0 postion to 100 then it will quickly scale the square from .1 to 2 ( double its full size) and stop.
However if we go in the reverse direction and drag it back from 100 down to 0 position and then beyond it will continue to scale down and to a negative value eventually.
This will cause it to flip! This is showing that when we hit our top level (moving to the right) it will clamp and then moving downwards (towars the left) it will just extend and grow.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.