發新話題
打印

用Maxima解題

設\( \displaystyle f(z)=\frac{z+a}{z+b} \)且\( g(z)=f(f(z)) \),其中a及b為複數。若\( |a|=1 \)且對所有使得\( g(g(z)) \)有定義的z都滿足\( g(g(z))=z \),則最大可能的\( |b| \)值與最小可能的\( |b| \)值之差是多少?(A) 0  (B) \( \sqrt{2}-1 \)  (C) \( \sqrt{3}-1 \)  (D) 1  (E) 2
(2011AMC12 https://math.pro/db/thread-1080-1-1.html)



定義f(z)函數
(%i1) f(z):=(z+a)/(z+b);
(%o1) \( \displaystyle f(z):=\frac{z+a}{z+b} \)

定義g(z)函數
(%i2) g(z):=f(f(z));
(%o2) g(z):=f(f(z))

(%i3) g(g(z));
(%o3) 

計算g(g(z))=z化簡後的結果
(%i4) ratsimp(%)=z;
(%o4) \( \displaystyle \frac{(ab^2+2ab+a^2+3a+1)z+ab^3+ab^2+(2a^2+a)b+2a^2+a}{(b^3+b^2+(2a+1)b+2a+1)z+b^4+3ab^2+2ab+a^2+a}=z \)

(%i5) num(lhs(%o4))=rat(denom(lhs(%o4))*rhs(%o4));
(%o5) \( (ab^2+2ab+a^2+3a+1)z+ab^3+ab^2+(2a^2+a)b+2a^2+a=(b^3+b^2+(2a+1)b+2a+1)z^2+(b^4+3ab^2+2ab+a^2+a)z \)

(%i6) rhs(%)-lhs(%);
(%o6) \( (b^3+b^2+(2a+1)b+2a+1)z^2+(b^4+2ab^2-2a-1)z-ab^3-ab^2+(-2a^2-a)b-2a^2-a \)

(...)z^2+(...)z+(...)=0
不管複數z是多少代入的結果都是0
可知原式是恆等式,各項係數為0

(%i7) 
factor(coeff(%o6,z,2))=0;
factor(coeff(%o6,z,1))=0;
factor(coeff(%o6,z,0))=0;

(%o7) \( (b+1)(b^2+2a+1)=0 \)
(%o8) \( (b-1)(b+1)(b^2+2a+1)=0 \)
(%o9) \( -a(b+1)(b^2+2a+1)=0 \)

從三個式子解出b
(%i10) solve([%o7,%o8,%o9],b);
(%o10) \( [ [b=\sqrt{-2a-1}],[b=-\sqrt{-2a-1}],[b=-1] ] \)

因為|a|=1,令a=cos(t)+i*sin(t)代入,求b的範圍
(%i11) ev(%o10[1][1],a=cos(t)+%i*sin(t));
(%o11) \( b=\sqrt{-2(\%i  sin(t)+cos(t))-1} \)

計算複數b的絕對值
(%i12) trigsimp(cabs(%));
(%o12) \( |b|=(4 cos(t)+5)^{1/4} \)

當t=0時|b|有最大值√3
(%i13) ev(%o12,t=0);
(%o13) \( |b|=\sqrt{3} \)

當t=π時|b|有最小值1
(%i14) ev(%o12,t=%pi);
(%o14) \( |b|=1 \)



[ 本帖最後由 bugmens 於 2011-3-19 08:21 PM 編輯 ]

TOP

尤拉在1742年時,將白努力所舉的四次多項式\( f(x) \)分解為二次多項式
\( \displaystyle x^2-\Bigg(\; 2+\sqrt{4+2 \sqrt{7}} \Bigg)\; x+\Bigg(\; 1+\sqrt{4+2 \sqrt{7}}+\sqrt{7} \Bigg)\; \)
與二次多項式
\( \displaystyle x^2-\Bigg(\; 2-\sqrt{4+2 \sqrt{7}} \Bigg)\; x+\Bigg(\; 1-\sqrt{4+2 \sqrt{7}}+\sqrt{7} \Bigg)\; \)
的乘積。白努利所舉的多項式\( f(x) \)=(以降次排列表示)
(100華江高中二招,https://math.pro/db/thread-1177-1-1.html)



用公式解得方程式的兩根
(%i1) 
x^2-(2+sqrt(4+2*sqrt(7)))*x+(1+sqrt(4+2*sqrt(7))+sqrt(7))=0;
solve(%,x);

(%o1) \( x^2-(\sqrt{2 \sqrt{7}+4}+2)x+\sqrt{2 \sqrt{7}+4}+\sqrt{7}+1=0 \)
(%o2)
[ \( \displaystyle x=\frac{-\sqrt{2}\sqrt{\sqrt{7}-2}%i+\sqrt{2\sqrt{7}+4}+2}{2} \),
\( \displaystyle x=\frac{\sqrt{2}\sqrt{\sqrt{7}-2}%i+\sqrt{2\sqrt{7}+4}+2}{2} \) ]

取第一個根來計算
(%i3) %[1]
(%o3) \( \displaystyle x=\frac{-\sqrt{2}\sqrt{\sqrt{7}-2}%i+\sqrt{2\sqrt{7}+4}+2}{2} \)

兩邊都減1
(%i4) ratsimp(%-1);
(%o4) \( \displaystyle x-1=\frac{\sqrt{2 \sqrt{7}+4}-\sqrt{2}\sqrt{\sqrt{7}-2}%i}{2} \)

兩邊平方
(%i5) ratsimp(%^2);
(%o5) \( \displaystyle x^2-2x+1=-\frac{\sqrt{2}\sqrt{\sqrt{7}-2}\sqrt{2 \sqrt{7}+4}%i-4}{2} \)

rootscontract指令可以將獨立的根號乘在一起
√(x-1)*√(x+1)=√(x^2-1)

(%i6) rootscontract(%);
(%o6) \( \displaystyle x^2-2x+1=-\frac{2 \sqrt{-3}-4}{2} \)

兩邊都減2
(%i7) ratsimp(%-2);
(%o7) \( x^2-2x-1=-\sqrt{3}%i \)

兩邊平方去掉i
(%i8) %^2;
(%o8) \( (x^2-2x-1)^2=-3 \)

得到答案i
(%i9) expand(%+3);
(%o9) \( x^4-4x^3+2x^2+4x+4=0 \)









101.2.10補充一題
\( \displaystyle f(x)=\Bigg[\; x^2-\frac{\sqrt{10+2 \sqrt{5}}+\sqrt{10-2 \sqrt{5}}}{2}x+\sqrt{5} \Bigg]\; \Bigg[\; x^2+\frac{\sqrt{10+2 \sqrt{5}}+\sqrt{10-2 \sqrt{5}}}{2}x+\sqrt{5} \Bigg]\; \)
求乘開後的\( f(x) \)


(%i1) x^2+(sqrt(10+2*sqrt(5))+sqrt(10-2*sqrt(5)))/2*x+sqrt(5);
(%o1) \( x^2+\frac{(\sqrt{2 \sqrt{5}+10}+\sqrt{10-2 \sqrt{5}})x}{2}+\sqrt{5} \)

(%i2) x^2-(sqrt(10+2*sqrt(5))+sqrt(10-2*sqrt(5)))/2*x+sqrt(5);
(%o2) \( x^2-\frac{(\sqrt{2 \sqrt{5}+10}+\sqrt{10-2 \sqrt{5}})x}{2}+\sqrt{5} \)

(%i3) %o1*%o2;
(%o3) \( \displaystyle \Bigg(\; x^2-\frac{(\sqrt{2 \sqrt{5}+10}+\sqrt{10-2 \sqrt{5}})x}{2}+\sqrt{5} \Bigg)\; \Bigg(\; x^2+\frac{(\sqrt{2 \sqrt{5}+10}+\sqrt{10-2 \sqrt{5}})x}{2}+\sqrt{5} \Bigg)\; \)

(%i4) expand(%);
(%o4) \( \displaystyle x^4-\frac{\sqrt{10-2 \sqrt{5}} \sqrt{2 \sqrt{5}+10}x^2}{2}+2 \sqrt{5}x^2-5x^2+5 \)

(%i5) rootscontract(%);
(%o5) \( x^4-5x^2+5 \)



[ 本帖最後由 bugmens 於 2012-2-10 09:49 PM 編輯 ]

TOP

設\( \displaystyle A=\Bigg[\; \matrix{1 & 4 \cr 3 & 2} \Bigg]\;  \),且X、Y均為二階方陣,滿足\( X+Y=\Bigg[\; \matrix{1 & 0 \cr 0 & 1}\Bigg]\;  \),\( XY=\Bigg[\; \matrix{0 & 0 \cr 0 & 0}\Bigg]\; \),\( aX+bY=A \),其中\( a>b \),a、b為常數,則\( X^n= \)?
(101臺南二中,https://math.pro/db/thread-1335-1-1.html)



(%i1) 
a*X+b*Y=matrix([1,4],[3,2]);
X+Y=matrix([1,0],[0,1]);

(%o1) \( \displaystyle bY+aX=\Bigg[\; \matrix{1 & 4 \cr 3 & 2} \Bigg]\; \)
(%o2) \( \displaystyle Y+X=\Bigg[\; \matrix{1 & 0 \cr 0 & 1} \Bigg]\; \)

solve指令無法解矩陣方程式,只好用加減消去法解出X,Y
(%i3) 
ratsimp((%o1-%o2*a)/(b-a));
ratsimp((-%o1+%o2*b)/(b-a));

(%o3) \( \displaystyle Y=\Bigg[\; \matrix{-\frac{a-1}{b-a} & \frac{4}{b-a} \cr \frac{3}{b-a} & -\frac{a-2}{b-a}} \Bigg]\; \)
(%o4) \( \displaystyle X=\Bigg[\; \matrix{\frac{b-1}{b-a} & -\frac{4}{b-a} \cr -\frac{3}{b-a} & \frac{b-2}{b-a}} \Bigg]\; \)

X.Y相乘為0矩陣
(%i5) rhs(%o4).rhs(%o3)=matrix([0,0],[0,0]);
(%o5) \( \displaystyle \Bigg[\; \matrix{-\frac{(a-1)(b-1)}{(b-a)^2}-\frac{12}{(b-a)^2} & \frac{4(b-1)}{(b-a)^2}+\frac{4(a-2)}{(b-a)^2} \cr \frac{3(b-2)}{(b-a)^2}+\frac{3(a-1)}{(b-a)^2} & -\frac{(a-2)(b-2)}{(b-a)^2}-\frac{12}{(b-a)^2}} \Bigg]\;=\Bigg[\; \matrix{0 & 0 \cr 0 & 0} \Bigg]\; \)

相乘後各元素為0
(%i6) 
lhs(%o5)[1][1]=rhs(%o5)[1][1];
lhs(%o5)[2][1]=rhs(%o5)[2][1];

(%o6) \( \displaystyle -\frac{(a-1)(b-1)}{(b-a)^2}-\frac{12}{(b-a)^2}=0 \)
(%o7) \( \displaystyle \frac{3(b-2)}{(b-a)^2}+\frac{3(a-1)}{(b-a)^2}=0 \)

整理式子
(%i8) 
factor(%o6);
factor(%o7);

(%o8) \( \displaystyle -\frac{ab-b-a+13}{(b-a)^2}=0 \)
(%o9) \( \displaystyle \frac{3(b+a-3)}{(b-a)^2}=0 \)

解出a,b,得到兩解,但第二組不合
(%i10) solve([%o8,%o9],[a,b]);
(%o10) \( [ [a=5,b=-2],[a=-2,b=5] ] \)

將第一組解代回X,Y矩陣
(%i11) 
ev(%o3,%o10[1]);
ev(%o4,%o10[1]);

(%o11) \( \displaystyle Y=\Bigg[\; \matrix{\frac{4}{7} & -\frac{4}{7} \cr -\frac{3}{7} & \frac{3}{7}} \Bigg]\; \)
(%o12) \( \displaystyle X=\Bigg[\; \matrix{\frac{3}{7} & \frac{4}{7} \cr \frac{3}{7} & \frac{4}{7}} \Bigg]\; \)

計算X矩陣的平方會得到自己(X^2=X),所以X的n次方還是自己
(%i13) rhs(%).rhs(%);
(%o13) \( \displaystyle \Bigg[\; \matrix{\frac{3}{7} & \frac{4}{7} \cr \frac{3}{7} & \frac{4}{7}} \Bigg]\; \)



[ 本帖最後由 bugmens 於 2012-5-18 07:54 PM 編輯 ]

TOP

上學期教到數據分析時,想要修改課本的題目數據讓學生練習
但改了一個數字平均數就變成分數或標準差變成根號,改來改去就是湊不出整數的答案
讓我想到能否用maxima幫忙檢查,於是就花了一些時間寫成程式
回頭想想相關係數、回歸直線應該也能寫成程式,將來要命題時就有很多現成的題目可以用



makelist和random:隨機產生list
mean:從list資料中計算平均數
std:從list資料中計算標準差
integerp:檢查是否為整數

(%i1) 
StandardDeviation(LowerBound,UpperBound,n):=block(
for i:1 thru 1000 do
  (data:makelist(random(UpperBound-LowerBound+1)+LowerBound,n),
   mean:mean(data),
   std:std(data),
   if integerp(mean)=true and integerp(std)=true then
     print(data,"平均數=",mean,"標準差=",std)
  )
)$


StandardDeviation(下界,上界,個數)
(%i2) StandardDeviation(6,15,5);
[5,10,15,15,15] 平均數=12 標準差=4
[6,8,9,10,12] 平均數=9 標準差=2


指令:StandardDeviation(50,100,5);
說明:從50到100的範圍中任意取5筆資料
範例:甲生第一次月考五科成績分別為82,80,54,68,71,則成績的平均數為 71 ,標準差為 10 
其他範例
58,56,59,70,52平均數59,標準差6
83,65,76,77,79平均數76,標準差6
84,90,93,76,72平均數83,標準差8
74,73,67,85,61平均數72,標準差8
94,86,92,98,75平均數89,標準差8
82,67,87,97,77平均數82,標準差10

指令:StandardDeviation(170,190,5);
說明:從170到190的範圍中任意取5筆資料
範例:籃球隊5位先發球員的身高為178,182,181,180,184公分,試求此5人身高的平均數為 181 ,標準差為 2 
其他範例
172,178,175,184,176平均數177標準差4
186,183,180,174,182平均數181標準差4
176,170,174,178,182平均數176標準差4
172,176,178,175,184平均數177標準差4
182,188,176,184,180平均數182標準差4
177,178,190,174,186平均數181標準差6

指令:StandardDeviation(40,80,6);
說明:從40到80的範圍中任意取6筆資料
範例:某高中一年二班其中6位學生的體重為68,62,70,73,67,74公斤,則此6人的平均數為 69 ,標準差為 4 
其他範例
77,65,67,68,61,64平均數67標準差5
52,50,52,53,61,44平均數52標準差5
67,65,73,59,55,59平均數63標準差6
73,55,61,57,66,60平均數62標準差6
41,52,53,53,58,43平均數50標準差6
73,80,65,73,55,74平均數70標準差8
64,60,48,55,66,73平均數61標準差8

指令:StandardDeviation(6,15,5);
說明:從6到15的範圍中任意取5筆資料
範例:甲生的五科學測成績分別為9,6,12,10,8級分,則平均數為 9 ,標準差為 2 
其他範例
11,12,9,13,15平均數12標準差2
10,12,8,11,14平均數11標準差2
13,13,13,8,13平均數12標準差2
11,7,13,10,9平均數10標準差2
14,10,12,8,11平均數11標準差2
10,15,15,15,15平均數14標準差2

[ 本帖最後由 bugmens 於 2012-8-23 10:36 PM 編輯 ]

TOP

產生分組的資料,並檢驗平均數和標準差是否為整數


(%i1) 
GroupStandardDeviation(LowerBound,Group,n):=block(
for i:1 thru 1000 do
  (datas:create_list([LowerBound+10*j,random(n)+1],j,0,Group-1),
   list:[],
   for data in datas do
     list:append(create_list(data[1],i,1,data[2]),list),
   mean:mean(list),
   std:std(list),
   if integerp(mean)=true and integerp(std)=true then
     print("分組資料",datas,"平均數=",mean,"標準差=",std)
  )
)$


GroupStandardDeviation(第一組的組中點,組數,個數)
(%i2) GroupStandardDeviation(55,5,10);
分組資料[[55,3],[65,1],[75,2],[85,3],[95,1]]平均數=73標準差=14
分組資料[[55,2],[65,9],[75,1],[85,5],[95,3]]平均數=74標準差=13


指令:GroupStandardDeviation(55,5,10);
說明:從第一組組中點55開始,共取5組,每組個數小於10位
範例:某班月考的數學成績統計如下

成績

50~6060~7070~8080~9090~100

人數

18821
求全班的平均數為 72 ,標準差 9 
其他範例:
分組資料[[55,3],[65,1],[75,2],[85,3],[95,1]]平均數73標準差14
分組資料[[55,2],[65,9],[75,1],[85,5],[95,3]]平均數74標準差13
分組資料[[55,1],[65,2],[75,4],[85,8],[95,5]]平均數82標準差11
分組資料[[55,9],[65,5],[75,3],[85,3],[95,4]]平均數70標準差15

指令:GroupStandardDeviation(155,4,15);
說明:從第一組組中點155開始,共取4組,每組個數小於15位
範例:20名學生的身高統計如下:

身高

150~160160~170170~180180~190

人數

5591
求這20名學生的平均身高為 168 ,標準差 9 
其他範例:
分組資料[[155,11],[165,12],[175,15],[185,2]]平均數167標準差9
分組資料[[155,7],[165,9],[175,12],[185,2]]平均數168標準差9
分組資料[[155,3],[165,11],[175,9],[185,2]]平均數169標準差8
分組資料[[155,3],[165,7],[175,9],[185,1]]平均數169標準差8

指令:GroupStandardDeviation(45,5,10);
說明:從第一組組中點45開始,共取5組,每組個數小於10位
範例:有25位學生的體重統計如下:

體重

40~5050~6060~7070~8080~90

人數

65932
其體重的平均數 61 ,標準差 12 
其他範例:
分組資料[[45,2],[55,8],[65,9],[75,10],[85,1]]平均數65標準差10
分組資料[[45,7],[55,3],[65,9],[75,5],[85,1]]平均數61標準差12
分組資料[[45,6],[55,5],[65,5],[75,3],[85,1]]平均數59標準差12
分組資料[[45,6],[55,10],[65,4],[75,3],[85,2]]平均數59標準差12

TOP

計算相關係數


要先載入descriptive.mac才能使用cov指令
(%i1) load("descriptive.mac");
(%o1) C:/PROGRA~1/MAXIMA~1.0-2/share/maxima/5.28.0-2/share/descriptive/descriptive.mac

(%i2) 
CorrelationCoefficient(XLowerBound,XUpperBound,YLowerBound,YUpperBound,n):=block(
for i:1 thru 10000 do
  (x:create_list(random(XUpperBound-XLowerBound+1)+XLowerBound,i,1,n),
   y:create_list(random(YUpperBound-YLowerBound+1)+YLowerBound,i,1,n),
   data:matrix(x,y),
   cov:cov(transpose(data)),
   denom:sqrt(cov[1,1]*cov[2,2]),
   if cov[1,2]#0 and cov[1,1]#0 and cov[2,2]#0 and
      integerp(cov[1,1])=true and integerp(cov[2,2])=true and
      integerp(denom)=true then
     (print("資料",data),
      print("第一組 平均",mean(x),"標準差",std(x)),
      print("第二組 平均",mean(y),"標準差",std(y)),
      print("共變數",cov[1,2],"相關係數",cov[1,2]/denom)
     )
  )
)$


CorrelationCoefficient(第一組下界,第一組上界,第二組下界,第二組上界,個數)
(%i3) CorrelationCoefficient(160,175,55,75,5);
資料\( \Bigg[\; \matrix{164 & 165 & 161 & 167 & 163 \cr 61 & 64 & 58 & 62 & 70} \Bigg]\; \)
第一組 平均164標準差2
第二組 平均63標準差4
共變數\( \displaystyle \frac{6}{5} \)相關係數\( \displaystyle \frac{3}{20} \)
資料\( \Bigg[\; \matrix{174 & 166 & 163 & 167 & 165 \cr 72 & 60 & 73 & 74 & 56} \Bigg]\; \)
第一組 平均167標準差\( \sqrt{14} \)
第二組 平均67標準差\( 2\sqrt{14} \)
共變數8相關係數\( \displaystyle \frac{2}{7} \)


指令:CorrelationCoefficient(160,175,55,75,5);
說明:第一組範圍為160~175,第二組範圍為55~75,產生5筆資料
範例:高一某班的5位同學身高與體重的資料如下表所示

身高(公分)

164165161167163

體重(公斤)

6164586270

求身高與體重的相關係數為\( \displaystyle \frac{3}{20} \)。
其他範例:
資料\( \Bigg[\; \matrix{174 & 166 & 163 & 167 & 165 \cr 72 & 60 & 73 & 74 & 56} \Bigg]\; \)
第一組 平均167標準差\( \sqrt{14} \)
第二組 平均67標準差\( 2\sqrt{14} \)
共變數8相關係數\( \displaystyle \frac{2}{7} \)

指令:CorrelationCoefficient(50,80,60,90,5);
說明:第一組範圍50~80,第二組範圍60~90,個數5個
範例:五位同學的英文和數學段考成績如下表:

英文

6871647562

數學

8067767973

則英文和數學的相關係數為\( \frac{6}{55} \)
其他範例:
資料\( \Bigg[\; \matrix{59 & 80 & 56 & 53 & 62 \cr 76 & 82 & 78 & 89 & 70} \Bigg]\; \)
第一組 平均62標準差\( 3\sqrt{10} \)
第二組 平均79標準差\( 2\sqrt{10} \)
共變數\( \displaystyle -\frac{21}{5} \)相關係數\( \displaystyle -\frac{7}{100} \)

資料\( \Bigg[\; \matrix{61 & 62 & 68 & 64 & 55 \cr 68 & 77 & 79 & 60 & 76} \Bigg]\; \)
第一組 平均62標準差\( 3\sqrt{2} \)
第二組 平均72標準差\( 5\sqrt{2} \)
共變數\( \displaystyle -\frac{6}{5} \)相關係數\( \displaystyle -\frac{1}{25} \)
資料\( \Bigg[\; \matrix{52 & 50 & 58 & 54 & 56 \cr 68 & 72 & 76 & 80 & 84} \Bigg]\; \)
第一組 平均54標準差\( 2\sqrt{2} \)
第二組 平均76標準差\( 4\sqrt{2} \)
共變數\( \displaystyle \frac{48}{5} \)相關係數\( \displaystyle \frac{3}{5} \)

但數字太大學生計算時容易出錯,平均一錯後面整個答案都是錯的
以下的數字比較簡單,適合用在平時測驗及期中考試
資料\( \Bigg[\; \matrix{3 & 3 & 1 & 5 \cr 5 & 3 & 3 & 1} \Bigg]\; \)
第一組 平均3標準差\( \sqrt{2} \)
第二組 平均3標準差\( \sqrt{2} \)
共變數\( \displaystyle -1 \)相關係數\( \displaystyle -\frac{1}{2} \)
資料\( \Bigg[\; \matrix{5 & 5 & 5 & 1 \cr 5 & 1 & 1 & 1} \Bigg]\; \)
第一組 平均4標準差\( \sqrt{3} \)
第二組 平均2標準差\( \sqrt{3} \)
共變數\( \displaystyle 1 \)相關係數\( \displaystyle \frac{1}{3} \)
資料\( \Bigg[\; \matrix{1 & -3 & -1 & -1 \cr 2 & 0 & 0 & -2} \Bigg]\; \)
第一組 平均-1標準差\( \sqrt{2} \)
第二組 平均0標準差\( \sqrt{2} \)
共變數\( \displaystyle 1 \)相關係數\( \displaystyle \frac{1}{2} \)
資料\( \Bigg[\; \matrix{-1 & -3 & 3 & -3 \cr 3 & -3 & -3 & -1} \Bigg]\; \)
第一組 平均-1標準差\( \sqrt{6} \)
第二組 平均-1標準差\( \sqrt{6} \)
共變數\( \displaystyle -1 \)相關係數\( \displaystyle -\frac{1}{6} \)
資料\( \Bigg[\; \matrix{2 & -2 & 2 & 2 \cr 3 & 3 & -1 & 3} \Bigg]\; \)
第一組 平均1標準差\( \sqrt{3} \)
第二組 平均2標準差\( \sqrt{3} \)
共變數\( \displaystyle -1 \)相關係數\( \displaystyle -\frac{1}{3} \)
資料\( \Bigg[\; \matrix{-3 & 3 & 1 & -1 \cr -1 & -3 & 3 & 1} \Bigg]\; \)
第一組 平均0標準差\( \sqrt{5} \)
第二組 平均0標準差\( \sqrt{5} \)
共變數\( \displaystyle -1 \)相關係數\( \displaystyle -\frac{1}{5} \)

[ 本帖最後由 bugmens 於 2012-10-6 08:01 PM 編輯 ]

TOP

計算迴歸直線方程式


要先載入descriptive.mac才能使用cov指令
(%i1) load("descriptive.mac");
(%o1) C:/PROGRA~1/MAXIMA~1.0-2/share/maxima/5.28.0-2/share/descriptive/descriptive.mac

(%i2) 
LinearRegression(XLowerBound,XUpperBound,YLowerBound,YUpperBound,n):=block(
for i:1 thru 50 do
  (x:create_list(random(XUpperBound-XLowerBound+1)+XLowerBound,i,1,n),
   y:create_list(random(YUpperBound-YLowerBound+1)+YLowerBound,i,1,n),
   data:matrix(x,y),
   cov:cov(transpose(data)),
   m:cov[1,2]/cov[1,1],
   if cov[1,1]#0 and cov[2,2]#0 and integerp(mean(x))=true and integerp(mean(y))=true then
     print("資料",data,"迴歸直線","y-",mean(y),"=",m,"(x-",mean(x),")")
  )
)$


LinearRegression(第一組下界,第一組上界,第二組下界,第二組上界,個數)
(%i3) LinearRegression(1,10,1,10,5);
資料\( \displaystyle \Bigg[\; \matrix{5 & 3 & 6 & 7 & 4 \cr 8 & 3 & 4 & 1 & 4} \Bigg]\; \)迴歸直線 \( \displaystyle y-4=-\frac{2}{5}(x-5) \)
(%o3) done


指令:LinearRegression(1,10,1,10,5);
說明:第一組範圍為1~10,第二組範圍為1~10,產生5筆資料
範例:設有兩組資料如下:

x

53674

y

83414
則y對x的迴歸直線方程式為 \( \displaystyle y-4=-0.4(x-5) \) 
其他範例:
資料\( \displaystyle \Bigg[\; \matrix{6 & 5 & 4 & 8 & 2 \cr 7 & 2 & 6 & 5 & 10} \Bigg]\; \)迴歸直線 \( \displaystyle y-6=-\frac{7}{10}(x-5) \)
資料\( \displaystyle \Bigg[\; \matrix{5 & 5 & 10 & 5 & 5 \cr 10 & 7 & 2 & 9 & 7} \Bigg]\; \)迴歸直線 \( \displaystyle y-7=-\frac{5}{4}(x-6) \)
資料\( \displaystyle \Bigg[\; \matrix{3 & 4 & 9 & 3 & 1 \cr 7 & 7 & 5 & 9 & 7} \Bigg]\; \)迴歸直線 \( \displaystyle y-7=-\frac{1}{3}(x-4) \)
資料\( \displaystyle \Bigg[\; \matrix{8 & 1 & 9 & 5 & 7 \cr 10 & 10 & 7 & 6 & 7} \Bigg]\; \)迴歸直線 \( \displaystyle y-8=-\frac{1}{5}(x-6) \)
資料\( \displaystyle \Bigg[\; \matrix{3 & 4 & 2 & 5 & 1 \cr 4 & 5 & 7 & 4 & 10} \Bigg]\; \)迴歸直線 \( \displaystyle y-6=-\frac{7}{5}(x-3) \)
資料\( \displaystyle \Bigg[\; \matrix{3 & 8 & 2 & 7 & 10 \cr 1 & 2 & 7 & 10 & 10} \Bigg]\; \)迴歸直線 \( \displaystyle y-6=\frac{1}{2}(x-6) \)

範例:在一個化學反應中,某化學物質的反應速率為Y g/min與某種催化劑的量X g有關,現在紀錄了5組數據於下表中,試求Y對X的迴歸直線方程式

X

678910

Y

689913
則Y關於X的迴歸直線為\( \displaystyle y-9=\frac{3}{2}(x-8) \)
其他範例:
資料\( \displaystyle \Bigg[\; \matrix{6 & 7 & 8 & 9 & 10 \cr 8 & 8 & 9 & 11 & 14} \Bigg]\; \)迴歸直線 \( \displaystyle y-10=\frac{3}{2}(x-8) \)
資料\( \displaystyle \Bigg[\; \matrix{6 & 7 & 8 & 9 & 10 \cr 5 & 6 & 9 & 10 & 10} \Bigg]\; \)迴歸直線 \( \displaystyle y-8=\frac{7}{5}(x-8) \)
資料\( \displaystyle \Bigg[\; \matrix{6 & 7 & 8 & 9 & 10 \cr 4 & 4 & 5 & 6 & 11} \Bigg]\; \)迴歸直線 \( \displaystyle y-6=\frac{8}{5}(x-8) \)
資料\( \displaystyle \Bigg[\; \matrix{6 & 7 & 8 & 9 & 10 \cr 5 & 7 & 9 & 10 & 14} \Bigg]\; \)迴歸直線 \( \displaystyle y-9=\frac{21}{10}(x-8) \)


範例:某冰店為了研究溫度與冰品銷售的影響,經過統計後得到下表:

溫度x℃

3031323334

份數y份

59779495100
則y關於x的迴歸直線為 \( y-85=10(x-32) \) 
其他範例:
資料\( \displaystyle \Bigg[\; \matrix{30 & 31 & 32 & 33 & 34 \cr 66 & 70 & 72 & 92 & 100} \Bigg]\; \)迴歸直線 \( \displaystyle y-80=9(x-32) \)
資料\( \displaystyle \Bigg[\; \matrix{30 & 31 & 32 & 33 & 34 \cr 56 & 58 & 70 & 82 & 99} \Bigg]\; \)迴歸直線 \( \displaystyle y-73=11(x-32) \)
資料\( \displaystyle \Bigg[\; \matrix{33 & 34 & 35 & 36 & 37 \cr 82 & 109 & 116 & 123 & 125} \Bigg]\;
\)迴歸直線 \( \displaystyle y-111=10(x-35) \)
資料\( \displaystyle \Bigg[\; \matrix{33 & 34 & 35 & 36 & 37 \cr 83 & 86 & 102 & 106 & 128} \Bigg]\; \)迴歸直線 \( \displaystyle y-101=11(x-35) \)
資料\( \displaystyle \Bigg[\; \matrix{33 & 34 & 35 & 36 & 37 \cr 89 & 103 & 114 & 117 & 127} \Bigg]\; \)迴歸直線 \( \displaystyle y-110=9(x-35) \)




利用lsquares_estimates指令計算迴歸直線方程式


要先載入lsquares.mac才能使用lsquares_estimates指令
(%i1) load("lsquares.mac");
(%o1) "C:/PROGRA~1/MAXIMA~1.0-2/share/maxima/5.28.0-2/share/lsquares/lsquares.mac"

資料
(%i2) data:matrix([1,9],[2,3],[3,4],[4,7],[5,2]);
(%o2) \( \left[\ \matrix{1 & 9 \cr 2 & 3 \cr 3 & 4 \cr 4 & 7 \cr 5 & 2} \right]\ \)

利用最小平方法計算迴歸直線方程式(y=ax+b)
(%i3) lsquares_estimates(data,[x,y],y=a*x+b,[a,b]);
(%o3) [ [a=-1,b=8] ]

TOP

設\( r \ge s \ge t \ge u \ge 0 \)且滿足\( 5r+4s+3t+6u=2012 \)。試求\( r+s+t+u \)的最大值與最小值。
(101高中數學能力競賽 台北市筆試一試題,https://math.pro/db/thread-1503-1-1.html)


要先載入simplex.mac才能使用maximize_lp,minimize_lp指令
(%i1) load("simplex.mac");
(%o1) C:/PROGRA~1/MAXIMA~1.0-2/share/maxima/5.28.0-2/share/contrib/simplex/simplex.mac

按照英文字母順序顯示
(%i2) powerdisp:true;
(%o2) true

假設新的變數x,y,z,w且\( x,y,z,w \ge 0 \)
(%i3)
x=r-s;
y=s-t;
z=t-u;
w=u;

(%o3) \( x=r-s \)
(%o4) \( y=s-t \)
(%o5) \( z=t-u \)
(%o6) \( w=u \)

將舊的變數r,s,t,u改用x,y,z,w表示
(%i7) solve([%o3,%o4,%o5,%o6],[r,s,t,u]);
(%o7) \( [ [r=w+x+y+z,s=w+y+z,t=w+z,u=w] ] \)

將限制式5r+4s+3t+6u=2012改用x,y,z,w表示
(%i8)
5*r+4*s+3*t+6*u=2012;
ev(%,%o7);
cond:ratsimp(%);

(%o8) \( 5r+4s+3t+6u=2012 \)
(%o9) \( 6w+3(w+z)+4(w+y+z)+5(w+x+y+z)=2012 \)
(%o10) \( 18w+5x+9y+12z=2012 \)

將目標函數r+s+t+u改用x,y,z,w表示
(%i11)
r+s+t+u;
obj:ev(%,%o7);

(%o11) \( r+s+t+u \)
(%o12) \( 4w+x+2y+3z \)

使用線性規劃找最大值
obj目標函數,cond限制式,nonegative_lp非負的變數
當\( \displaystyle x=0,y=0,z=\frac{503}{3},w=0 \)時,有最大值503

(%i13) maximize_lp(obj,[cond]),nonegative_lp=true;
(%o13) \( \displaystyle [503,[z=\frac{503}{3},y=0,x=0,w=0]] \)

使用線性規劃找最小值
obj目標函數,cond限制式,nonegative_lp非負的變數
當\( \displaystyle x=\frac{2012}{5},y=0,z=0,w=0 \)時,有最小值\( \displaystyle \frac{2012}{5} \)

(%i14) minimize_lp(obj,[cond]),nonegative_lp=true;
(%o14) \( \displaystyle [\frac{2012}{5},[z=0,y=0,x=\frac{2012}{5},w=0]] \)



[ 本帖最後由 bugmens 於 2012-11-13 06:09 PM 編輯 ]

TOP

All 20 diagonals are drawn in a regular octagon. At how many distinct points in the interior of the octagon (not on the boundary) do two or more diagonals intersect?
(A)49 (B)65 (C)70 (D)96 (E)128
(2013AMC10A,http://www.artofproblemsolving.c ... Problems/Problem_25)
http://www.youtube.com/watch?v=3ovuMRYs--8
解答可以看上面的連結,但我要藉這個主題來分享一篇論文
Poonen, B. and Rubinstein, M. "The Number of Intersection Points Made by the Diagonals of a Regular Polygon." SIAM J. Disc. Math. 11, 135-156, 1998.
http://www.google.com/search?q=t ... chrome&ie=UTF-8
http://mathworld.wolfram.com/Reg ... ionbyDiagonals.html
論文第3頁列出交點數和區域數的公式,第7頁列出2條對角線、3條對角線、…、7條對角線的交點數。公式請參閱論文



定義δ(m,n)函數
(%i1) delta(m,n):=if mod(n,m)=0 then 1 else 0;
(%o1) \( \delta(m,n):=if mod(n,m)=0 then 1 else 0 \)

交點數公式I(n)
(%i2)
I(n):=binomial(n,4)
      +(-5*n^3+45*n^2-70*n+24)/24*delta(2,n)
      -(3*n/2)*delta(4,n)
      +(-45*n^2+262*n)/6*delta(6,n)
      +42*n*delta(12,n)
      +60*n*delta(18,n)
      +35*n*delta(24,n)
      -38*n*delta(30,n)
      -82*n*delta(42,n)
      -330*n*delta(60,n)
      -144*n*delta(84,n)
      -96*n*delta(90,n)
      -144*n*delta(120,n)
      -96*n*delta(210,n);

(%o2)
\( \displaystyle \matrix{I(n):={n \choose 4}+\frac{(-5)n^3+45n^2+(-70)n+24}{24}\delta(2,n) \cr
+(\; -\frac{3n}{2} )\; \delta(4,n) \cr
+\frac{(-45)n^2+262n}{6}\delta(6,n) \cr
+42 n \delta(12,n) \cr
+60 n \delta(18,n) \cr
+35 n \delta(24,n) \cr
+(-38) n \delta(30,n) \cr
+(-82) n \delta(42,n) \cr
+(-330) n \delta(60,n) \cr
+(-144) n \delta(84,n) \cr
+(-96) n \delta(90,n) \cr
+(-144) n \delta(120,n) \cr
+(-96) n \delta(210,n)} \)

區域數公式R(n)
(%i3)
R(n):=(n^4-6*n^3+23*n^2-42*n+24)/24
      +(-5*n^3+42*n^2-40*n-48)/48*delta(2,n)
      -(3*n/4)*delta(4,n)
      +(-53*n^2+310*n)/12*delta(6,n)
      +(49*n/2)*delta(12,n)
      +32*n*delta(18,n)
      +19*n*delta(24,n)
      -36*n*delta(30,n)
      -50*n*delta(42,n)
      -190*n*delta(60,n)
      -78*n*delta(84,n)
      -48*n*delta(90,n)
      -78*n*delta(120,n)
      -48*n*delta(210,n);

(%o3)
\( \displaystyle \matrix{R(n):=\frac{n^4-6n^3+23 n^2+(-42)n+24}{24} \cr
+\frac{(-5)n^3+42n^2+(-40)n-48}{48}\delta(2,n) \cr
+(\; -\frac{3n}{4} )\; \delta(4,n) \cr
+\frac{(-53)n^2+310n}{12}\delta(6,n) \cr
+\frac{49n}{2}\delta(12,n) \cr
+32 n \delta(18,n) \cr
+19 n \delta(24,n) \cr
+(-36) n \delta(30,n) \cr
+(-50) n \delta(42,n) \cr
+(-190) n \delta(60,n) \cr
+(-78) n \delta(84,n) \cr
+(-48) n \delta(90,n) \cr
+(-78) n \delta(120,n) \cr
+(-48) n \delta(210,n)} \)

2條對角線交於一點的個數
(%i4)
a2(n):=n*((n^3-6*n^2+11*n-6)/24
          +(-5*n^2+46*n-72)/16*delta(2,n)
          -9/4*delta(4,n)
          +(-19*n+110)/2*delta(6,n)
          +54*delta(12,n)
          +84*delta(18,n)
          +50*delta(24,n)
          -24*delta(30,n)
          -100*delta(42,n)
          -432*delta(60,n));

(%o4)
\( \displaystyle \matrix{a2(n):=n \Bigg(\; \frac{n^3-6n^2+11n-6}{24} \cr
+\frac{(-5)n^2+46n-72}{16} \delta(2,n) \cr
+\frac{-9}{4}\delta(4,n) \cr
+\frac{(-19)n+110}{2} \delta(6,n) \cr
+54 \delta(12,n) \cr
+84 \delta(18,n) \cr
+50 \delta(24,n) \cr
+(-24) \delta(30,n) \cr
+(-100) \delta(42,n) \cr
+(-432) \delta(60,n) \Bigg)\;} \)

3條對角線交於一點的個數
(%i5)
a3(n):=n*((5*n^2-48*n+76)/48*delta(2,n)
          +3/4*delta(4,n)
          +(7*n-38)/6*delta(6,n)
          -8*delta(12,n)
          -20*delta(18,n)
          -16*delta(24,n)
          -19*delta(30,n)
          +8*delta(42,n)
          +68*delta(60,n)
          +60*delta(84,n)
          +48*delta(90,n)
          +60*delta(120,n)
          +48*delta(210,n));

(%o5)
\( \displaystyle \matrix{a3(n):=n\Bigg(\; \frac{5n^2-48n+76}{48}\delta(2,n) \cr
+\frac{3}{4} \delta(4,n) \cr
+\frac{7n-38}{6}\delta(6,n) \cr
+(-8)\delta(12,n) \cr
+(-20)\delta(18,n) \cr
+(-16)\delta(24,n) \cr
+(-19)\delta(30,n) \cr
+8 \delta(42,n) \cr
+68 \delta(60,n) \cr
+60 \delta(84,n) \cr
+48 \delta(90,n) \cr
+60 \delta(120,n) \cr
+48 \delta(210,n) \Bigg)\;} \)

4條對角線交於一點的個數
(%i6)
a4(n):=n*((7*n-42)/12*delta(6,n)
          -5/2*delta(12,n)
          -4*delta(18,n)
          +3*delta(24,n)
          +6*delta(42,n)
          +34*delta(60,n)
          -6*delta(84,n)
          -6*delta(120,n));

(%o6)
\( \displaystyle \matrix{a4(n):=n\Bigg(\; \frac{7n-42}{12}\delta(6,n) \cr
-\frac{5}{2}\delta(12,n) \cr
+(-4)\delta(18,n) \cr
+3 \delta(24,n) \cr
+6 \delta(42,n) \cr
+34 \delta(60,n) \cr
+(-6) \delta(84,n) \cr
+(-6) \delta(120,n) \Bigg)\;} \)

5條對角線交於一點的個數
(%i7)
a5(n):=n*((n-6)/4*delta(6,n)
          -3/2*delta(12,n)
          -2*delta(24,n)
          +4*delta(42,n)
          +6*delta(84,n)
          +6*delta(120,n));

(%o7)
\( \displaystyle \matrix{a5(n):=n\Bigg(\; \frac{n-6}{4}\delta(6,n) \cr
-\frac{3}{2} \delta(12,n) \cr
+(-2) \delta(24,n) \cr
+4 \delta(42,n) \cr
+6 \delta(84,n) \cr
+6 \delta(120,n) \Bigg)\;} \)

6條對角線交於一點的個數
(%i8) a6(n):=n*(4*delta(30,n)-4*delta(60,n));
(%o8) \( a6(n):=n(4\delta(30,n)-4 \delta(60,n)) \)

7條對角線交於一點
(%i9) a7(n):=n*(delta(30,n)+4*delta(60,n));
(%o9) \( a7(n):=n(\delta(30,n)+4 \delta(60,n)) \)

以論文第2頁的正30邊形為例,有16801個交點,有21480個區域。
2條對角線交於一點有13800個
3條對角線交於一點有2250個
4條對角線交於一點有420個
5條對角線交於一點有180個
6條對角線交於一點有120個
7條對角線交於一點有30個
15條對角線交於一點有1個(中心)

(%i10)
n:30;
I(n);
R(n);
a2(n);
a3(n);
a4(n);
a5(n);
a6(n);
a7(n);

(%o10) 30
(%o11) 16801
(%o12) 21480
(%o13) 13800
(%o14) 2250
(%o15) 420
(%o16) 180
(%o17) 120
(%o18) 30

TOP

由邊長為1的正三角形堆疊n層,試問邊長為6時(即\( a_6 \)),所有大大小小之平行四邊形總數為
(101陽明高中,https://math.pro/db/viewthread.php?tid=1433&page=1#pid6580)
公式:\( \displaystyle 3C_{4}^{n+2} \)

可以再進一步問正三角形個數有多少
M. E. Larsen, The eternal triangle - a history of a counting problem, College Math. J., 20 (1989), 370-392.
http://www.google.com/search?q=T ... chrome&ie=UTF-8
http://oeis.org/A002717
http://www.math.ku.dk/~mel/mel.pdf
正三角形個數\( \displaystyle \Bigg[\; \frac{n(n+2)(2n+1)}{8} \Bigg]\; \)
其中還可以細分兩種正三角形
△正三角形個數:\( \displaystyle C_3^{n+2} \)
▽正三角形個數:\( \displaystyle \frac{n(n+2)(2n-1)}{24}-\frac{\delta(n)}{8} \) , \( \displaystyle \delta(n)=\cases{0 \text{for $n$ even} \cr 1 \text{for $n$ odd}} \)



正三角形個數公式f(n)
(%i1) f(n):=floor((n*(n+2)*(2*n+1))/8);
(%o1) \( \displaystyle f(n) :=floor \Bigg(\;\frac{n(n+2)(2n+1)}{8} \Bigg)\; \)

△正三角形個數
(%i2) Delta(n):=binomial(n+2,3);
(%o2) \( \Delta(n) :=\Bigg(\; \matrix{n+2 \cr 3} \Bigg)\; \)

定義δ(n)函數
(%i3) delta(n):=if evenp(n)=true then 0 else 1;
(%o3) \( \delta(n) \):=if evenp(n)=true then 0 else 1

▽正三角形個數
nabla符號為▽,http://en.wikipedia.org/wiki/Nabla_symbol

(%i4) nabla(n):=n*(n+2)*(2*n-1)/24-delta(n)/8;
(%o4) \( \displaystyle nabla(n) :=\frac{n(n+2)(2n-1)}{24}-\frac{\delta(n)}{8} \)

以論文第1頁的n=6為例
 正三角形78個
△正三角形56個
▽正三角形22個

(%i5)
n:6;
f(n);
Delta(n);
nabla(n);

(%o5) 6
(%o6) 78
(%o7) 56
(%o8) 22

TOP

發新話題