Problem 55970. Interpolated Value Between Two Points
Given two points,
and
, a new location x, and a method "linear" or "cubic", return the value of a linear or cubic interpolant through the two points at the new location x, using the formulas below.
Linear: 
Cubic: 
where
and
.
(This formulation for the cubic interpolant has zero derivative at each interpolation point.)
If
, your function should produce an error with the message "x2 must be greater than x1".
If
, your function should produce a warning with the message "x is outside the interval [x1,x2]" (but still return the value of the interpolant).
If the method is given as anything other than "linear" or "cubic", your function should produce an error with the message "method must be either "linear" or "cubic"".
Solution Stats
Problem Comments
-
4 Comments
Show
1 older comment
Marco Riani
on 15 Mar 2023
This is just to say that I fully agree with what goc3 wrote!
Rarely I have seen warnings and errors tested on Cody.
For example it would be nice to test errors where (as it is good practice and can be set in the MATLAB code Analyzer preferences),
"The first argument of error should be a message identifier".
Nikolaos Nikolaou
on 22 Mar 2023
Is there a problem with testcase 2 ?
Dyuman Joshi
on 24 Mar 2023
Nikolaos, the reference solution is working fine, there seems to be no problem with the test suite.
Solution Comments
Show commentsProblem Recent Solvers82
Suggested Problems
-
Calculate the Levenshtein distance between two strings
1453 Solvers
-
Project Euler: Problem 8, Find largest product in a large string of numbers
1198 Solvers
-
390 Solvers
-
Solve a System of Linear Equations
12671 Solvers
-
135 Solvers
More from this Author12
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!