Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.34 KB | None | 0 0
  1. SKO = 0.4;
  2. thSKO = 3 * 0.4;
  3. exval = 50;
  4. inimeas = normrnd(exval, SKO, [1000,1]);
  5. measurment_redux = count_error(inimeas);
  6. meas1 = count_error(inimeas);
  7. meas2 = count_error(inimeas);
  8. meas3 = count_error(inimeas);
  9. make_struct(inimeas)
  10. make_struct(measurment_redux)
  11. make_struct(meas1)
  12. make_struct(meas2)
  13. make_struct(meas3)
  14. draw_graph(inimeas, 'Resistors resistance graph (source), Ohm', 1);
  15. draw_graph(measurment_redux, 'Resistors resistance graph with defective resistors removed (source), Ohm', 2);
  16. draw_graph(meas1, 'Measuring the resistance of resistors 1, Ohm', 3);
  17. draw_graph(meas2, 'Measuring the resistance of resistors 1, Ohm', 4);
  18. draw_graph(meas3, 'Measuring the resistance of resistors 1, Ohm', 5);
  19. function result = count_error(arr)
  20. len = length(arr);
  21. exval = 50;
  22. result = zeros([len, 1]);
  23. for i = 1:len
  24. random_factor = rand() * 0.005;
  25. result(i) = arr(i) + random_factor * arr(i);
  26. if(result(i) > exval * 1.01 || result(i) < exval * 0.99)
  27. result(i) = exval;
  28. continue;
  29. end
  30. end
  31. end
  32. function draw_graph(arr, subgraph_title, number_in_graph)
  33. thSKO = 3 * 0.4;
  34. exval = 50;
  35. title(subgraph_title);
  36. subplot(5, 1, number_in_graph);
  37. histogram(arr);
  38. axis([exval - thSKO exval + thSKO 0 110]);
  39. end
  40. function result = make_struct(arr)
  41. result.distr = arr;
  42. result.std = std(arr);
  43. result.var = var(arr);
  44. result.mean = mean(arr);
  45. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement