基本上是用Fortran写的,主要是为了效率和精确度 如下: 1、史瓦西半径计算

program testingInt
  implicit none
  real(kind=16) :: G !这个宇宙的万有引力常数
  real(kind=16) :: M !天体质量,单位kg
  real(kind=16) :: c !这个宇宙的光速
  real(kind=16) :: R !史瓦西半径
  G = 6.67430e-11_16
  c = 299792458.0_16
  !print *,G 
  print *, "请输入物体质量M(单位:kg)"
  read *, M
  R=(2*G*M)/(c**2)
  print *, "半径为:", R
end program

2、钟慢尺缩效应

program testingInt
    implicit none
    real(kind=16) :: c
    real :: v_input
    real :: begin
    real(kind=16) :: out
    c = 299792458.0_16
    print *, "输入一个速度:"
    read *, v_input
    print *, "输入一个距离(m)/时间(s):"
    read *, begin
    if (v_input <= c) then
        out=begin*sqrt(1-(v_input**2/c**2))
        print *, "计算结果为:", out
    else
        print *, "输入的速度超过了光速,请重新输入一个小于光速的速度。"
    end if
end program

3、奇妙项目

program testingInt
    implicit none
    integer :: i, n
    real :: L0, total_length, s_0, p_estimated
    real :: a
    real, dimension(70) :: x, y, length

    ! 读取L0(假设是某个特征长度)
    print *, "请输入L0的值: "
    read *, L0

    n = 0
    ! 第一个循环:计算离散点
    do i = 1, 21  ! a从0到2,步长0.1,共21个点
        a = 0.0 + (i-1)*0.1
        x(i) = a
        y(i) = -(x(i))**2 + 4.0
        n = n + 1
    end do

    ! 第二个循环:计算相邻点之间的线段长度
    total_length = 0.0
    do i = 1, n-1
        length(i) = sqrt((x(i)-x(i+1))**2 + (y(i)-y(i+1))**2)
        total_length = total_length + length(i)
    end do

    ! 输出总长度
    print *, "曲线总长度 (total_length) = ", total_length
    
    ! 计算物理量
    s_0 = L0 * (total_length*2)
    print *, "计算得到的s_0 = ", s_0
    
    ! 计算估计压强,注意单位转换
    ! 假设100是某个力(N),s_0面积单位是m²,需要从cm²转为m²
    p_estimated = 100.0 / (s_0 * 1.0e-4)  ! 乘以10^(-4)转换为m²
    print *, "估计压强为 (Pa): ", p_estimated
    
end program testingInt