计算物理作业python代码_如何在简书中用markdown写计算物理作业

这篇文章是专门写给我的学妹——某傻璐

第一步

1.在简书中注册一个账号

2.然后点击红色区块开始写文章

420cba6915ad

(1.1)

3.然后进入左下方的设置选项中,设置编辑器为markdown

420cba6915ad

(1.2)

420cba6915ad

(1.3)

4.回到写文章的地方,在右上角点击新建文集

420cba6915ad

(1.4)

这里我新建了一个名为“曾梓龙”的文集

5.然后点击新建文章

420cba6915ad

(1.5)

6.新建文章之后切换到预览模式,开始写作

420cba6915ad

(1.6)

7.进入预览模式

420cba6915ad

(1.7)

第二步

1.markdown的基本语法

420cba6915ad

(2.1)

420cba6915ad

(2.2)

420cba6915ad

(2.3)

420cba6915ad

(2.4)

至于代码的引用用这个符号:```

两个这样的符号包括代码框,就引用了代码,如下图所示:

420cba6915ad

(2.5)

420cba6915ad

(2.6)

2.latex语法

如果你想输入公式,就得用到latex,但是github不支持,所以我们转移到简书写,简书写挺方便的。latex的教程地址在这,你在那个网站学一下怎么输入方程就行

第三步(代码部分)

1.这次作业你先看一下前面的例题,就是铀原子衰变的那道题,先把方程转化一下,至于方程的转化看这里,这是我自己写的

2.铀原子衰变的python代码

# -*- coding: utf-8 -*- #是为了告诉Python解释器,按照UTF-8编码读取源代码,,否则,你在源代码中写的中文输出可能会有乱码。

import numpy as np

import pylab as pl

Number=[]

t=[]

print("the number of uranium atoms ->")

number_u=input()

Number.append(number_u)

print("the time of decay ->")

t_decay=input()

print("the time step ->")

dt=input()

t_max=dt*100

t.append(0.0)

for i in range(100):

N=Number[i]-(Number[i]/t_decay)*dt

tadd=t[i]+dt

Number.append(N)

t.append(tadd)

pl.plot(t,Number) #将两个列表数据导入

pl.title('the decay of uranium') #图标的名称

pl.xlabel('the time of decaying') #横轴的标签

pl.ylabel('number of atoms') #纵轴标签

pl.xlim(0.0,t_max) #横轴的坐标范围

pl.ylim(0.0,100) #纵轴坐标范围

pl.show() #输出图表

3.作业的代码

# -*- coding: utf-8 -*-

import numpy as np

import matplotlib.pyplot as pl

Number_A=[]

Number_B=[]

t=[]

print("the number of A atoms ->")

number_a=input()

Number_A.append(number_a)

print("the number of B atoms ->")

number_b=input()

Number_B.append(number_b)

print("the time of decay ->")

t_decay=input()

print("the time step ->")

dt=input()

def Bigger(a,b):

if a>b:

return a

else:

return b

def Smaller(a,b):

if a>b:

return b

else:

return a

big=Bigger(Number_A[0],Number_B[0])

small=Smaller(Number_A[0],Number_B[0])

t.append(0.0)

for i in range(100):

NA=Number_A[i]+((Number_B[i]-Number_A[i])/t_decay)*dt

NB=Number_B[i]+((Number_A[i]-Number_B[i])/t_decay)*dt

tadd=t[i]+dt

Number_A.append(NA)

Number_B.append(NB)

t.append(tadd)

t_max=t[-1]

pl.plot(t,Number_A,color="blue",linewidth=2.5,linestyle="-",label="A atom")

pl.plot(t,Number_B,color="red",linewidth=2.5,linestyle="-",label="B atom")

pl.title('the decay between A and B')

pl.xlabel('the time of decaying')

pl.ylabel('number of atoms')

pl.xlim(0.0,t_max)

pl.ylim(small,big)

pl.text(t[len(t)//2],((big-small)//2),r'Number_A[0]=NA,Number_B[0]=NB')

pl.legend(loc='upper right')

pl.show()

第四步:结果

1.铀原子衰变

420cba6915ad

(4.1)

2.作业的图像

420cba6915ad

(4.2)

结束

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值