Solving a function by interpolation

9 vues (au cours des 30 derniers jours)
Maxandre Coulon
Maxandre Coulon le 30 Juin 2020
Commenté : Sargondjani le 30 Juin 2020
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 commentaires
Maxandre Coulon
Maxandre Coulon le 30 Juin 2020
In my console, I have:
Error using griddedInterpolant
The grid vectors must contain unique points.
Error in interp1 (line 151)
F = griddedInterpolant(X,V,method);
Error in Envelope_30_06 (line 165)
epsilon_teta_0(indexDeltaTau+1,indexDeltaf+1) = interp1(ATAN(epsilon_tau_0_prev(indexDeltaTau+1,indexDeltaf+1), A0, t_centered, corr_vec, A1, DeltaTau(indexDeltaTau+1), 0,
epsilon_teta, epsilon_f_0(indexDeltaTau+1,indexDeltaf+1), Ti, Deltaf(indexDeltaf+1)),epsilon_teta,0);
my ATAN function is :
function ATAN = ATAN(epsilon_tau, A0, t_centered, corr_vec, A1, delta_tau, delta_teta, epsilon_teta, epsilon_f, Ti, Delta_f)
corr_LOS_P = interp1(t_centered,corr_vec,epsilon_tau);
corr_NLOS_P = interp1(t_centered,corr_vec,epsilon_tau + delta_tau);
%IP = A0 / 2 .* sinc(pi .* epsilon_f .* Ti) .* corr_LOS_P .* cos(epsilon_teta + pi .* Ti .* epsilon_f) + A1 / 2 .* sinc(pi .* (epsilon_f + Delta_f) .* Ti) .* corr_NLOS_P .* cos(epsilon_teta + delta_teta + pi .* (epsilon_f + Delta_f) .* Ti);
%QP = A0 / 2 .* sinc(pi .* epsilon_f .* Ti) .* corr_LOS_P .* sin(epsilon_teta + pi .* Ti .* epsilon_f) + A1 / 2 .* sinc(pi .* (epsilon_f + Delta_f) .* Ti) .* corr_NLOS_P .* sin(epsilon_teta + delta_teta + pi .* (epsilon_f + Delta_f) .* Ti);
IP = A0 / 2 .* corr_LOS_P .* cos(epsilon_teta + pi .* Ti .* epsilon_f) + A1 / 2 .* corr_NLOS_P .* cos(epsilon_teta + delta_teta + pi .* (epsilon_f + Delta_f) .* Ti);
QP = A0 / 2 .* corr_LOS_P .* sin(epsilon_teta + pi .* Ti .* epsilon_f) + A1 / 2 .* corr_NLOS_P .* sin(epsilon_teta + delta_teta + pi .* (epsilon_f + Delta_f) .* Ti);
ATAN = atan(QP ./ IP);
end
in interp1, the problem is in
Xqcol = Xq(:);
num_vals = size(V,2);
% some lines
else % can use ND
if (num_vals > 1)
Xext = {cast(X,'double'),(1:num_vals)'};
F = griddedInterpolant(Xext,V,method);
VqLite = F({cast(Xqcol,class(Xext{1})),Xext{2:end}});
else
F = griddedInterpolant(X,V,method);
VqLite = F(Xqcol);
end
end
Sargondjani
Sargondjani le 30 Juin 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.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by