如何用增加波长绘制波浪?

发布于 2025-01-21 06:39:43 字数 957 浏览 0 评论 0原文

我正在看一堆电磁频谱图,并意识到它们显示的波实际上从未与图中给定的波长相对应。例如,红外波长的波长(lambda = 800 nm)应比X射线时的波长长800倍(lambda = 1 nm)。

如何绘制R中的波,以使波长与指定波长成正比增加?即f(x)= lambda和f(n * x)= n * lambda

简单示例,只是在电磁频谱的一小部分上:

library(ggplot2)

# Make a simple dataset
max.x <- 800 # Maximum wavelength in nanometers (nm) to show
steps <- 10000 # More steps make plotting smooter

waveforms <- as.data.frame(matrix(data=NA, nrow=steps+1, ncol=2, dimnames=list(NULL, c("x", "y"))))
waveforms$x <- seq(0,max.x, by=max.x/steps)


# We can make a wave with periods that increase easily
waveforms$y <- sin(sqrt(waveforms$x))

ggplot()+
  geom_line(data=waveforms, aes(x=x, y=y), color="red")+
  scale_x_continuous("Wavelength in nanometers (nm)")

“增加波长的图”

频谱的低端不比上端的波长短800倍。什么是将波长成比例的实际公式?

I was looking at a bunch of electromagnetic spectrum diagrams and realized that the wave they show never actually corresponds with the given wavelengths in the diagram. For example, the wavelength of the wave at infrared (lambda = 800 nm) should appear 800 times longer than the wavelength at X-ray (lambda = 1 nm).

How can I plot a wave in r such that the wavelength increases proportional to the specified wavelength? i.e. f(x) = lambda and f(n * x) = n * lambda

Simple example just over a small part of the electromagnetic spectrum:

library(ggplot2)

# Make a simple dataset
max.x <- 800 # Maximum wavelength in nanometers (nm) to show
steps <- 10000 # More steps make plotting smooter

waveforms <- as.data.frame(matrix(data=NA, nrow=steps+1, ncol=2, dimnames=list(NULL, c("x", "y"))))
waveforms$x <- seq(0,max.x, by=max.x/steps)


# We can make a wave with periods that increase easily
waveforms$y <- sin(sqrt(waveforms$x))

ggplot()+
  geom_line(data=waveforms, aes(x=x, y=y), color="red")+
  scale_x_continuous("Wavelength in nanometers (nm)")

Plot of increasing wavelength

...but just eyeballing the graph, a wavelength at the low end of the spectrum isn't 800 times shorter than a wavelength at the upper end. What is the actual formula that would make the wavelengths proportional?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岛徒 2025-01-28 06:39:43

我认为您需要波长的倒数累积总和(显然您必须跳过0,因为否则您的累积总和将是无限的):

waveforms$y <- c(0, sin(cumsum(1 / waveforms$x[-1])))


ggplot()+
  geom_line(data=waveforms, aes(x=x, y=y), color="red")+
  scale_x_continuous("Wavelength in nanometers (nm)")

“

I think you need the cumulative sum of the reciprocal of wavelength (obviously you have to skip 0 because otherwise your cumulative sum would be infinite):

waveforms$y <- c(0, sin(cumsum(1 / waveforms$x[-1])))


ggplot()+
  geom_line(data=waveforms, aes(x=x, y=y), color="red")+
  scale_x_continuous("Wavelength in nanometers (nm)")

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文