Error propagation results error in coding

3 views (last 30 days)
Gregory Cook
Gregory Cook on 7 Oct 2020
Commented: Gregory Cook on 7 Oct 2020
Part 1: Density of Brass Mass
Objective:
We her to get the mass of the brass, volume the column, intensity of the density.
Definitions:
Standard error of mass scale (g)
Height of cylinder (cm)
Inner radius of cylinder (cm)
Outter radius of cylinder (cm
water volume (mL) after adding cylinder
Initial water volume (mL)
Mass of cylinder (g)
Conventions:
m = mass = M
vi = volume of water before cylinder is added = Vi
vf = volume of water after cylinder is added = Vf
vc = actual volume of cylinder = Vc
r1 = radius to outter edge of cylinder = R1
r2 = radius of inner edge of cylinder = R2
h = height of cylinder = H
= density = Q1
Mathematical Relationships:
The mass density was calculated from the mass m and volume of the cylinder as follows:
Method 2: We ........
v1 = 2pi r1 h v2 = 2pi r2 h
= vi-vfMeasured Data (Method 1):
% code example
% You can directly enter numerical results into a code section here....
% Make sure to include units in the code comments
vi =225; % Volume of water before immersion in ml
dvi=2; % uncertainty in vi in ml
vf=240; % Volume of water after immersion in ml
dvf=2; % uncertainty in vf in ml
m=100.6; % Mass in grams
dm=.1; % Uncertainty in mass2
h= 1.5; % height in cm
di= .15; %inside diameter in cm
do= 3.1; %outside diameter in cm
ddi= .1;
ddo= .1;
dh= .1;
%list variable
syms M Vi Vf Di Do H
syms dM dVi dVf dDi dDo dH
%method 1
Vc=Vf-Vi;
Rho1=M/Vc;
%method 2
Ri=Di/2;
Ro=Do/2;
Vinn=H*pi*Ri^2;
Vout=H*pi*Ro^2;
Rho2=M/(Vout-Vinn)
Rho2 =
%partial deriv for method 1
dRho1dM=diff(Rho1,M);
dRho1dVi=diff(Rho1,Vi);
dRho1dVf=diff(Rho1,Vf);
dRho1=sqrt((dRho1dM*dM)^2+(dRho1dVi*dVi)^2+(dRho1dVf*dVf)^2);
vars1=[M,Vi,Vf,dM,dVi,dVf];
nums1=[m,vi,vf,dm,dvi,dvf];
Rho1
Rho1 =
Results
double( subs(Rho1,vars1,nums1))%results method 1
ans = 6.7067
double(subs(dRho1,vars1,nums1))% error results method 1
double( subs(Rho2,vars1,nums1))%results methods 2
Error using symengine
Unable to convert expression into double array.
Error in sym/double (line 707)
Xstr = mupadmex('symobj::double', S.s, 0);
double(subs(dRho2,vars2,nums2))% error results method 2
Mothod 1 proved to easure the density showed to have more standard error deviation, because there was more uncertainty in the value of measurments.
Method 2 (two sig figs)
The uncertainty in vi and vf was primarily due to the larger graduated cylinder used to measure, does not show small and prescise units.
The uncertainty in mass was primarily due to the scale has a standard deviation of 0.1 grams.
Measured Data (Method 2):
In this section present your measured values (including uncertainties).
similar to above.
%partials for method 2
dRho2dM =diff(Rho2,M);
dRho2dDi=diff(Rho2,Di);
dRho2dDo=diff(Rho2,Do);
dRho2dH =diff(Rho2,H);
dRho2=sqrt((dRho2dM*dM)^2+(dRho2dDi*dDi)^2+(dRho2dDo*dDo)^2+(dRho2dH*dH)^2);
vars2=[M,Di,Do,H,dM,dDi,dDo,dH];
nums2=[m,di,do,h,dm,ddi,ddo,dh];
Rho2
Data Processing (Method 1):
In this section perform calculations of density and perform the error propagation.
% Code section for density calculation and error propagation.
% General Procedure (3 Steps)
% Step 1: Declare symbolic variables needed
% Step 2: Do symbolic calculations of density and uncertainty in
% density first.
% Step 3: Substitute the numeric values from the
% "Measured Data" section in the symbolic expressions to
% get a numeric result.
% Step 1
syms Vi Vf M dVi dVf dM % declare symbolic variables
% Step 2
Rho1 = M/(Vf-Vi) % define a function for density
% Calculating the partial derivatives (in symbolic form)
dRho1dM = diff(Rho1,M);
dRho1dVi = diff(Rho1,Vi);
dRho1dVf = diff(Rho1,Vf);
% Calculating the uncertainty in the density (in symbolic form using error propagation equation)
dRho1 = sqrt((dRho1dM*dM)^2+(dRho1dVi*dVi)^2+(dRho1dVf*dVf)^2)
% Step 3
% Create arrays of symbols and numerical values to replace them with.
sym = [M,Vi,Vf,dM,dVi,dVf];
num = [m,vi,vf,dm,dvi,dvf];
% Substitute symbolic variables with numeric values
rho1 = double(subs(Rho1,sym,num)) % in g/cm^3
drho1 = double(subs(dRho1,sym,num)) % in g/cm^3
Final Numerical Result (Method 1):
Write a sentence and state the final result with proper significant figures and uncertainty.
Data Processing (Method 2):
In this section perform calculations of density and perform the error propagation.
% code section for density calculation and error propagation
% Step 1
syms H D_o D_i dH ....... % declare symbolic variables
% Step 2
V2 = .......
Rho2 = ..... % define a function for density
% Calculating the partial derivatives (in symbolic form)
dRho2dM = diff(Rho2,M);
dRho2dH = diff(Rho2,...);
dRho2dD_o = ....;
dRho2........;
% Calculating the uncertainty in the density (in symbolic form using error propagation equation)
dRho2 = sqrt((dRho2dM*dM)^2+..............)
% Step 3
% Create arrays of symbols and numerical values to replace them with.
sym2 = [M H D_o ...................];
num2 = [m .........................];
% Substitute symbolic variables with numeric values
rho2 = double(subs(...........)) % in ......
drho2 =....................... % in .....
Final Numerical Result (Method 2):
Write a sentence and state the final result with proper significant figures and uncertainty.
Discussion/Summary for Density Measurement:
Compare the results of the two density measurements and draw a conclusion regarding which of the two measurements appears to be more accurate etc.. Compare your measured density to known values of densities of brass (not all brass has the same density, it depends on the composition of the steel, but this will give a range of acceptable values).
Part 2: Statistical Uncertainty
Dice Rolls - Manual
clear
dice_sum = [Dice_Throw_Simulation]; % enter the values of your summed dice throws seperated by spaces
nmax=length(dice_sum); % automatically calculates the length of the array "dice_sum"
Statistics and Histogram
r_ave=mean(dice_sum) % Calculate the mean of the dice sums
r_std=std(dice_sum) % Calculate the standard deviation of the dice sums
r_std_mean=r_std/sqrt(nmax) % Calculate the standard error of the mean of the dice sums
histogram(dice_sum)
% hold on
histfit(dice_sum)
Dice Rolls - Simulation
clear;
dmax=4; % number of dice thrown simultaneously
nmax=10000; % number of dice throws
Dice_Throw_Simulation=randi(6,[dmax nmax]) % has dmax rows and nmax columns
result_sum =sum(Dice_Throw_Simulation) % Adds up the sum for each dice throw (column)
Statistics and Histogram
r_ave=mean(result_sum) % Calculate the mean of the dice sums
r_std=std(result_sum) % Calculate the standard deviation of the dice sums
r_std_mean=r_std/sqrt(nmax) % Calculate the standard error of the mean of the dice sums
histogram(result_sum)
% hold on
histfit(result_sum,dmax*5+1,'normal')
Discussion/Summary for Dice Rolls:
With a large enough population, we will see that the standard deviation will stay the same no matter how many times you keep roling the dice. The standard error of the mean will become more precise as the population increases, and the bell curve showing the 95% confidence interval will become more narrow, as the standard error of mean decreases.
I am havving irrues finding out what ther error means under the results section for part 1. I had it all coded out and all data and results, then i rearraned some of the code, and now there are errors.
Also, with part 2, I had all the data calculated, and once i rearranged part 1, it messed up the data result for 2.
Please help
Thank you!
  7 Comments
Gregory Cook
Gregory Cook on 7 Oct 2020
Can you tell me whats wrong with part 2? I had the code running earlier, but now theres some sort of issue.
Gregory Cook
Gregory Cook on 7 Oct 2020
Nevermind! i got this one too!
Thanks for your help though

Sign in to comment.

Answers (0)

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!