Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % double A_d = 0.32345;
- % double B_d = 0.78743;
- % double C_d = 0.56532;
- %
- % float A_f = 0.32345;
- % float B_f= 0.78743;
- % float C_d = 0.56532;
- close all;
- A=0.32345;
- B=-0.78743;
- C=0.56532;
- % A_bin=zeros(20);
- prec_f=18;
- for i = 1:prec_f
- A_fix=fixed(A,1,1,i);
- B_fix=fixed(B,1,1,i);
- C_fix=fixed(C,1,1,i);
- if i==7
- A_bin=bin(A_fix);
- B_bin=bin(B_fix);
- C_bin=bin(C_fix);
- end
- A_fix=double(A_fix);
- B_fix=double(B_fix);
- C_fix=double(C_fix);
- Y=(A+B)*C;
- Y_fix=(A_fix+B_fix)*C_fix;
- error_res_y(i)=abs(Y-Y_fix);
- error_res_a(i)=abs(A-A_fix);
- error_res_b(i)=abs(B-B_fix);
- error_res_c(i)=abs(C-C_fix);
- end
- Y_fix=fixed(Y_fix,1,1,i);
- Y_bin=bin(Y_fix);
- X=linspace(1,prec_f,prec_f);
- figure
- plot(X,error_res_y);
- grid on;
- xlabel('Ilośc bitów czesci ułamkowej');
- ylabel('Błąd bezwzględny');
- figure
- grid on;
- plot(X,error_res_a);
- xlabel('Ilośc bitów czesci ułamkowej');
- ylabel('Błąd bezwzględny');
- hold on;
- grid on;
- plot(X,error_res_b);
- plot(X,error_res_c);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement