Solving a function by interpolation

10 visualizaciones (últimos 30 días)
Maxandre Coulon
Maxandre Coulon el 30 de Jun. de 2020
Comentada: Sargondjani el 30 de Jun. de 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 comentarios
Maxandre Coulon
Maxandre Coulon el 30 de Jun. de 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 el 30 de Jun. de 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.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by