[英]Why am I getting "NA" values after running the curvefit function in R?
[英]I am not getting the expected output in R for the Firas spectrum after running this code
我正在嘗試運行下面的代碼,可以從https://lambda.gsfc.nasa.gov/data/cobe/firas/monopole_spec/firas_monopole_spec_v1.txt訪問數據
#loading the data
cobe <- read.table("~/Downloads/cobe.txt", quote="\"")
frequency <- (cobe$V1)*29.979
spectrum <- cobe$V2
B_f <- function(frequency, t){
h <- 6.62607015e-34
c <- 299792458
k <- 1.380649e-23
spectrum <- ((2*h*frequency^3)/c^2)/exp((h*frequency)/k*t)-1
return(spectrum * 1e-9)
}
t <- 2.725
spectrum <- B_f(frequency,t)
library(ggplot2)
ggplot(data = data.frame(frequency, spectrum)) +
geom_line(aes(x = frequency, y = spectrum)) +
ggtitle("Blackbody spectrum at T = 2.725K \n with data from the COBE satellite") +
xlab("Frequency (GHz)") + ylab("Spectral Radiance (MJy/sr)") +
theme_classic()+
geom_point(aes(x = frequency, y = spectrum), color = 'red', size = 5)
我不斷得到第一張圖片(直線水平圖),但我期待第二張圖(BB 曲線) output plot [2]預期 plot 。
根據您提供的來源,我認為您進行了不必要的轉換:
#loading the data
cobe <- read.table("~/Downloads/cobe.txt", quote="\"")
library(ggplot2)
ggplot(data = cobe, aes(x = V1, y = V2)) +
geom_line(colour = "blue") +
ggtitle("Blackbody spectrum at T = 2.725K \n with data from the COBE satellite") +
xlab("Frequency (cycles/cm)") + ylab("Spectral Radiance (MJy/sr)") +
theme_classic()+
geom_point(aes(x = frequency, y = spectrum), color = 'red', size = 5)
產生一個 plot 來匹配我認為的預期圖像?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.