A pH curve is requested for a reaction between 50 mL of 0.2 M HNO3 and 0.1 M NaOH. This involves a neutralization reaction between the acid and base that will result in the pH changing from acidic to basic as the reaction progresses. The curve will track this pH change as the moles of H+ ions are consumed by the OH- ions added from the NaOH.
This document summarizes a titration of 100 mL of 2M HCl with 1M NaOH. It calculates the volume of NaOH needed at the equivalence point as 50 mL. It then sets up the x-axis values from 0 to 100 mL NaOH added in increments of 2 mL. The y-axis values are calculated as the pH at each point using the titration equations before and after the equivalence point.
This document describes how to generate a titration curve for a strong acid-strong base titration using Python. It involves titrating 100 mL of 2 M HCl with 1 M NaOH and plotting the pH as a function of the amount of titrant added. The Python code provided calculates the pH values at different points of titrant addition, plots the curve in three segments before, at, and after the equivalence point, and displays the final titration curve graph.
This document describes an iterative bisection method to find the root of the function 2 * sin(x) + cos(2x) between an initial range. Over 17 iterations, it narrows down the range of r from [4.712389, 6.283185] to [5.908415, 5.908463] by bisection with an allowed error of 1 x 10-5.
A pH curve is requested for a reaction between 50 mL of 0.2 M HNO3 and 0.1 M NaOH. This involves a neutralization reaction between the acid and base that will result in the pH changing from acidic to basic as the reaction progresses. The curve will track this pH change as the moles of H+ ions are consumed by the OH- ions added from the NaOH.
This document summarizes a titration of 100 mL of 2M HCl with 1M NaOH. It calculates the volume of NaOH needed at the equivalence point as 50 mL. It then sets up the x-axis values from 0 to 100 mL NaOH added in increments of 2 mL. The y-axis values are calculated as the pH at each point using the titration equations before and after the equivalence point.
This document describes how to generate a titration curve for a strong acid-strong base titration using Python. It involves titrating 100 mL of 2 M HCl with 1 M NaOH and plotting the pH as a function of the amount of titrant added. The Python code provided calculates the pH values at different points of titrant addition, plots the curve in three segments before, at, and after the equivalence point, and displays the final titration curve graph.
This document describes an iterative bisection method to find the root of the function 2 * sin(x) + cos(2x) between an initial range. Over 17 iterations, it narrows down the range of r from [4.712389, 6.283185] to [5.908415, 5.908463] by bisection with an allowed error of 1 x 10-5.
2. 6 字串
唐詩在書法中的排列 (二)
撰寫此程式,首先到理清楚雙層迴圈兩個下標與詩句字串下標的關
聯,假設雙層迴圈變數由外而內分別為 i 與 j,字串字元下標為 k,
以下的推導可得到其間的關係:
唐詩的排列是由右向左,可順勢讓橫向
的 j 迴圈配合由右向左隨之遞增,在紙上
填入相關的數字後,即可觀察到詩句的字元
下標 k 與兩迴圈的 i、 j 變數有著以下
簡單關係:
k = j × h + i
以上 h 為詩句的直行字數。
本範例解題的關鍵即在要能推導出以上幾個變數間的公式,沒有此公式
,程式雖簡單,卻也難以於短時間完成程式。由中可看出在撰寫程式前紙筆
推導的重要性,許多程式問題若少了紙筆推導是難以在電腦螢幕前憑空「生
」出程式。
46
3. 6 字串
唐詩在書法中的排列 (三)
47
p = ”春眠不覺曉處處聞啼鳥夜來風雨聲花落知多少”
while True :
# 讀入詩句列數
h = int(input(”> ”))
# 計算詩句行數
w = len(p)//h + ( 1 if len(p)%h else 0 )
for i in range(h) :
for j in range(w-1,-1,-1) :
k = j*h+i
print( p[k] if k < len(p) else ” ” , end=” ”)
print()
print()
5. 6 字串
一至七字詩 (二)
49
詩句 起點 a 字數 n 終點 b 字串
呆 0 1 1 p[0:1]
秀才 1 2 3 p[1:3]
吃長齋 3 3 6 p[3:6]
鬍鬚滿腮 6 4 10 p[6:10]
經書揭不開 10 5 15 p[10:15]
紙筆自己安排 15 6 21 p[15:21]
明年不請我自來 21 7 27 p[21:28]
假設 p 詩字串,若能準確的設定各列詩句起點 a 與終點 b,就可由之取得詩
句 p[a:b]。 觀察上表可知自第二列開始的詩句起點 a 就是上一列詩句的終
點 b,各列終點 b 數值就是 a 加上字數 n,由此得知程式的主要部份就為:
a = 0
for n in range(1,8) :
b = a + n
print( p[a:b] )
a = b
有了此部份後,列印每列的左側空格與根據列數以順
逆向方式列印 p[a:b] 字串就簡單了,整個程式也
僅是十多列而已。
6. 6 字串
一至七字詩 (三)
50
p = ”呆秀才吃長齋鬍鬚滿腮經書揭不開紙筆自己安排明年不請我自來”
k = 0
for n in range(1,8) :
# 輸出每列的空白
print( ’ ’*(2*(7-n)) , end="" )
b = a + n
if n%2 :
# 奇數列:順向列印,並於字與字間加上兩個空格
print( ’ ’.join(p[a:b]) )
else :
# 偶數列:逆向列印,並於字與字間加上兩個空格
print( ’ ’.join(p[a:b][::-1]) )
a = b
13. 6 字串
連環錦纏枝迴文詩 (四)
57
poem = ( ”寒泉漱玉清音好” ”好處深居近翠巒”
”巒秀聳岩飛澗水” ”水邊松竹檜宜寒”
”寒窗淨室親邀客” ”客待閒吟恣取歡”
”歡宴聚陪終席喜” ”喜來歸興酒闌殘” )
# n 列(行)數
# r , c 位置下標
# d 方向
n , r , c , d = 7 , 5 , 1 , 0
# 轉彎方向
dr , dc = [ 0 , -1 , 0 , 1 ] ,
[ -1 , 0 , 1 , 0 ]
# 二維字串串列
p = [ [ " " ] * n for i in range(n) ]
for i , ch in enumerate(poem) :
# 跳過重複字不處理
if i > 0 and i%n == 0 : continue
# 設定 p
p[r][c] = ch
# 更新 r 與 c 位置
r += dr[d]
c += dc[d]
# 檢查是否該轉彎
if ( ( r == c ) or ( r == 5 and c == 0 )
or ( r < c and r+c==n-1 ) or ( r > c
and r+c == n ) ) :
d += 1
if d == 4 : d = 0
# 列印
for i in range(len(p)) :
print( "".join(p[i]) )