Solving a function by interpolation
9 views (last 30 days)
Show older comments
I'm trying to find the solution x of f(a, b, c, d, x) = 0 where f is a function I implemented. I managed to create an array X = xmin:xstep:xmax; Then I tried to interpolate in order to find x such that f = 0: x = interp1(f(a,b,c,d,X),X,0);
But I sometimes get an error by using interp1 (which I don't get by using a home made slower interpolation function) :
Error using griddedInterpolant The grid vectors must contain unique points.
Error in interp1 (line 151) F = griddedInterpolant(X,V,method);
Any idea how to solve this? If you have any suggestion to get the value x to solve f(a,b,c,d,x) =0 I'm listening too.
Thanks in advance
3 Comments
Sargondjani
on 30 Jun 2020
Well the error says it: "The grid vectors must contain unique points." If a particular value of x has two 'y' values, then you can not use interp1 in that way. If x is a function of y, then swap your x and y variables in interp1 and it should work.
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!