-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPhysChemLab.R
More file actions
54 lines (50 loc) · 1.7 KB
/
Copy pathPhysChemLab.R
File metadata and controls
54 lines (50 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#虽然大概除了我以外没人同时用R LaTeX还要写物化实验报告==
#本文件包括三个R函数,可以自动生成计算标准差、合成不确定度以及平均值的LaTeX公式代码。
#示例:
# PhysChemLab_sigma(y="y",x="x",xs=c(1,2,3,4),xmean=2.5)
# PhysChemLab_sigma2(y = "y",
# expression = "x_1+x_2",
# x = c("x_1","x_2")
# )
# PhysChemLab_ave(y="y",x="x",xs=c(1,2,3,4))
PhysChemLab_sigma <- function(y,x,xs,xmean){
output <- paste("$$","\\sigma_{",y,"}",
"=\\sqrt{\\frac{\\Sigma (",x,"_i-\\bar{",x,"})^2}{n-1}}",
"=\\sqrt{\\frac{"
)
for(i in xs[1:(length(xs)-1)]){
output <- paste(output,"(",i,"-",xmean,")^2","+")
}
output <- paste(output,"(",xs[length(xs)],"-",xmean,")^2}{",length(xs),"-1}} $$")
cat(output)
}
PhysChemLab_sigma2 <- function(y,expression,x){
output <- paste("$$","\\sigma_{",y,"}=",
"\\sqrt{"
)
for(i in x[1:(length(x)-1)]){
output <- paste(output,"[",
"\\frac{\\partial (",expression,")}{\\partial",i,"}",
"\\sigma_{",i,"}",
"]^2",
"+")
}
output <- paste(output,"[",
"\\frac{\\partial (",expression,")}{\\partial",x[length(x)],"}",
"\\sigma_{",x[length(x)],"}",
"]^2"
)
output <- paste(output,"}","$$")
cat(output)
}
PhysChemLab_ave <- function(y,x,xs){
output <- paste("$$","\\bar{",y,"}",
"=\\frac{\\Sigma (",x,"_i)}{n}",
"=\\frac{"
)
for(i in xs[1:(length(xs)-1)]){
output <- paste(output,i,"+")
}
output <- paste(output,xs[length(xs)],"}{",length(xs),"} $$")
cat(output)
}