clc
close all
clear all

format long

disp('  ')
disp('Exercicio 2 IM1')
disp('  ')

AB=129.870;
sigma_AB=0.018; %em m
BC=318.260;
sigma_BC=0.024; %em m
CD=179.841;
sigma_CD=0.018; %em m
DE=217.713;
sigma_DE=0.024; %em m

AE=AB+BC+CD+DE;
fprintf('distancia total = %7.3f m\n', AE)

% calculo da incerteza no calculo da distancia total AE
% definir simbolicamente a funcao area
syms AE1 AB1 BC1 CD1 DE1
AE1=AB1+BC1+CD1+DE1;
% calcular as derivadas parciais da funcao AE em relacao as observacoes
d_AE1_AB1=diff(AE1,AB1);
d_AE1_BC1=diff(AE1,BC1);
d_AE1_CD1=diff(AE1,CD1);
d_AE1_DE1=diff(AE1,DE1);
% matriz jacobiana da transformacao de C e L em A
J(1,1)=double(subs(d_AE1_AB1,[AB1,BC1,CD1,DE1],[AB,BC,CD,DE]));
J(1,2)=double(subs(d_AE1_BC1,[AB1,BC1,CD1,DE1],[AB,BC,CD,DE]));
J(1,3)=double(subs(d_AE1_CD1,[AB1,BC1,CD1,DE1],[AB,BC,CD,DE]));
J(1,4)=double(subs(d_AE1_DE1,[AB1,BC1,CD1,DE1],[AB,BC,CD,DE]));
disp ('matriz Jacobiana da transformacao')
J

%disp ('matriz de variancias-covariancias das observacoes')
Sigma_obs=[sigma_AB^2,0,0,0;0,sigma_BC^2,0,0;0,0,sigma_CD^2,0;0,0,0,sigma_DE^2]

Sigma_AE=J*Sigma_obs*J';

incerteza_AE=sqrt(Sigma_AE);

fprintf('incerteza da distancia total = %6.3f m\n', incerteza_AE)

disp('  ')

