2008-04-12

C++ Array and Reference Test

這幾天在學C++,對arrayreference的用法做個測試。

#include <iostream> #include <string> void test(std::string (&str)[2]){ std::cout << sizeof(str) << " " << sizeof(std::string); } int main(){ size_t n; std::cin >> n; size_t m = 2; const size_t o = 3; std::string *testStrArr1 = new std::string[n];// correct std::string testStrArr2[n]; // wrong in VC++, correct in gcc, wrong in ISO C++ std::string testStrArr3[2] = {"hello","hi"}; // correct std::string testStrArr4[m]; // wrong in VC++, correct in gcc, wrong in ISO C++ std::string testStrArr5[o]; // correct test(testStrArr1); // wrong test(testStrArr2); // wrong test(testStrArr3); // correct test(testStrArr4); // wrong test(testStrArr5); // wrong [3]->[2] }

正確的那行會印出: 8 4

2008-04-08

stack<book> books;

現在桌上堆了一疊:

  • Head First Design Pattern
  • C++ Primer 4th edition(中文版...)
  • C++ Pocket Reference
  • 剛拿出來要寫作業的數通課本(Ziemer/Tranter)
  • 英漢辭典一本...

筆電裡還有一 trunk 的 ebooks... 目前想要看的有:

  • Head First SQL
  • Head First OOA&D
  • C++ GUI Programming with Qt 4
  • etc...(這算是推薦書單嗎? Head First系列都很好入門~)

看完是無可能的...? = =a

都是為了要完成我心中的小軟體orz

希望這學期能把該看的看完...

--

ps. 久違了...blogger 新開張! 網址是 http://jienew.twbbs.org/

2007-01-01

週末賞花去了

星期六,梅嶺看梅花:

星期日,白河看油菜花田:

晚上還去了情人碼頭逛逛:

花比較美~

2006-12-29

Scilab: Root Locus, Transfer Function Analysis

昨天考完控工...結論是...又爆了一次...
最後一題 Root Locus還畫錯= =|

所以,今天就來說一下怎麼用 Scilab畫 Root Locus,題目就是昨天寫錯的那一題。

Problem

Transfer Function
題目沒給,也不需要
Characteristic Equation
1 + KL(s) = 0
L(s)=(s+5)^2 / s^3

Solve in Scilab

要建立"s"的多項式,一個好方法是:先產生一個只有一個根在0的多項式,也就是 s。
s = poly(0, "s"); //s 是以"s"為變數名稱,只有一個根在 0 的多項式
然後再用 s來產生更複雜的多項式。

以本題來說,就是:
L = (s+5)^2 / s^3

如何?簡單吧= =
接下來需要將多項式轉換成線性系統(Linear System),我還沒研究好這是什麼...
sysL = syslin('c',L)
'c' 是連續的意思(continuous system)

接下來就可以畫圖了,只要一個指令:
evans(sysL, 50)
50是指畫到 K=50,可以任意更改。

如果你覺得圖怪怪的,那你有認真唸書。怪在實數軸跟虛數軸的單位長度不同,要打開圖形選項中 Aspect標籤裡的 isoview選項即可。

And...

我們也可以畫 Bode, Nyquist, Nichols 等圖形,方法如下:

Bode Plot
Assume that L(s) is a transfer function.
bode(sysL)
Nyquist
nyquist(sysL)
Nichols
black(L)
//誰能告訴我為何叫 black?
//還有 Nichols Plot 是什麼我也不知道XD

2006-12-20

Scilab 複數運算

因為今天把工程計算機借給了某評審,導致我回家沒計算機用,事前沒想到會這樣...所以就打開Scilab來算啦!試了好久,做一下筆記。

表示虛數的 i, j,在 Scilab中用%i表示,首先要知道這個。

舉個例,我們要算某 Transfer Function T= R/[R + 1/(sC)]

令 R= 4.7KΩ, C= 0.01μF,並令 s= jω求 f= 1kHz的 Frenquency Response,這樣在Scilab中的算式就是:
T=4700./(4700+1./(%i.*2.*%pi.*1e3.*0.01e-6))

接著算Transfer Function的相移(複數平面的角度),用atan()函數來算:
atan(imag(T),real(T))

換算成度數:
atan(imag(T),real(T)).*360./%pi

atan()的第一個參數是虛數部份,第二個才是實數,要注意。real()跟imag()就是取實部跟虛部的意思。

好亂...

為了做電子套件,把一年級的東西都找出來,我房間就變這樣了...

2006-12-17

How to Compile wxWidgets in Windows Using MinGW

Download

wxWidgets
wxWdigets 2.8.0 is used in this post. Enter the "Download" page of this site, then download wxMSW source archieve.
MinGW
Enter the "Download" page, then download MinGW-5.0.2.exe or newer version in the "Proposed" section.

Inatall

Execute files you just downloaded. Inatall step by step. Be sure that make tool and C/C++ compilers selected when installing MinGW.

Add path [MinGW Directory]\bin to Path variable.

Change directory to [wxWidgets Directory]\build\msw

Enter mingw32-make -f makefile.gcc UNICODE=1 SHARED=0 BUILD=release MONOLITHIC=0

Now we can compile sample programs using the same command. The output binary file will be in the gcc_mswu subdirectory.

Reference

This post is just a note for myself

2006-12-13

OpenOffice.org 2.1 Is Released!

From http://www.openoffice.org/

OpenOffice.org 2.1 is recommend for all users, as it represents a significant improvement over all previous versions. Among other things:
  • Multiple monitor support for Impress
  • Improved Calc HTML export
  • Enhanced Access support for Base
  • Even more languages
  • Automatic notification of updates

We also have more extensions. Developers everywhere are invited to write extensions. To learn more, visit our Extensions Project.

OpenOffice.org 一直是我的愛用軟體。我也有裝 MS Office XP,比較起來OpenOffice.org真的比較好用,對Unicode的支援也好很多。新版的MS Office我沒用過無法比較。

相容性的問題,OpenOffice.org 輸出成 MS Office的格式後用MS Office開啟,格式不會跑掉。然而用OpenOffice.org開啟MS Office製作的檔案時還是會走樣。這是不是代表同一種格式有不同的寫法?= =

所以如果要開別人用MS Office製作的檔案,就用微軟免費的viewer吧。

PowerPoint Viewer 2007
http://www.microsoft.com/downloads/details.aspx?FamilyID=048dc840-14e1-467d-8dca-19d2a8fd7485&DisplayLang=en
Word Viewer 2003
http://www.microsoft.com/downloads/details.aspx?FamilyID=048dc840-14e1-467d-8dca-19d2a8fd7485&DisplayLang=en
Excel Viewer 2003
http://www.microsoft.com/downloads/details.aspx?FamilyID=c8378bf4-996c-4569-b547-75edbd03aaf0&DisplayLang=en
Visio Viewer 2007
http://www.microsoft.com/downloads/details.aspx?FamilyID=d88e4542-b174-4198-ae31-6884e9edd524&DisplayLang=en

2006-12-12

Google Bookmarks' Down

就在剛剛,台北時間早上6點多,我的 Google書籤莫名被清空了,只剩一個連結。並且那個連結還是我今天要考試的科目...機率統計的網頁。= =