how can i run iterations?

2 views (last 30 days)
Postit123
Postit123 on 3 Oct 2020
Edited: KALYAN ACHARJYA on 3 Oct 2020
Hi
I'd like to replace "ep" matrix with "new" matrix for next iteration until the difference between new and ep gets lower than 0.01.
I think all I need is a simple equation that can relate "ep" and "new", but I have no idea how to do that.
function [H,y,true] = guess_new(sat,psr,ep,er,c)
% sat [nX4] * n = the number of satellites
% ep [1X3] : estimated position
% c : light of speed
% psr : pseudorange [nX1]
% er : user clock error
%%
n = size(sat,1);
new = ones(4,1);
while abs(new(1:3)- ep) > 0.01
for i = 1 : n
x(i) = (ep(1) - sat(i,1));
y(i) = (ep(2) - sat(i,2));
z(i) = (ep(3) - sat(i,3));
rho(i) = sqrt(x(i)^2+y(i)^2+z(i)^2);
G(i) = rho(i) + c*er;
end
% Partial Matrix H
H = [x(:) y(:) z(:) c*ones(n,1)]./rho(:);
% Measurement residual vector y
y = [psr(:) - G(:)];
% delta x,y,z,time error
del = inv(H.'*H)*H.'*y;
% update the initial guess
new = [ep'; er] + del;
end
true = new;

Answers (1)

KALYAN ACHARJYA
KALYAN ACHARJYA on 3 Oct 2020
Edited: KALYAN ACHARJYA on 3 Oct 2020
......
while abs(new(1:3)- ep)>0.01
for i = 1 : n
x(i) = (ep(1) - sat(i,1));
y(i) = (ep(2) - sat(i,2));
z(i) = (ep(3) - sat(i,3));
rho(i) = sqrt(x(i)^2+y(i)^2+z(i)^2);
G(i) = rho(i) + c*er;
end
ep=new; % Replace ep with new
end
......
Note: Please note on generation of new "new" after execution of for loop.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!