善用過期英語教學雜誌,是可以增進英文功力又不讓荷包失血的良策。您可選擇常春藤或空中英語教室出版社,前者分兩級 (生活英語、解析英語),後者分三級 (大家說英語、空中英語教室、Advanced),可線上購買自己有興趣的雜誌搭配 MP3 學習。
Welcome Message
「流行起於高分子,變化盡藏微宇宙」! 歡迎光臨「流變學好簡單 | The RheoMaster」部落格,成立於 2019/2/22,旨在提供簡單的中文流變學知識,包括高分子流變學、輸送現象、高分子加工、流變量測等。您可至右方進行關鍵字搜尋,若有任何建議,請至文章留言或來信 yuhowen@gmail.com。
Welcome to "The RheoMaster" Blog. This website was established in Feb 2019. In view of the lack of Chinese literature on rheology, here we offer basic knowledge relevant to polymer rheology, transport phenomena, polymer processing, rheometry, etc. If you have any suggestion, please leave a message on the post you are reading or email us at yuhowen@gmail.com.
2019年12月25日
2019年12月24日
基本 C++ 程式碼整理 (Basic C++ Notes)
Revised: 2023/4/11
Reference: I Horton, Ivor Horton's Beginning Visual C++ 2013 (Wiley 2014).
Main Function
. #include <cstring> // For strlen() ans strcpy()
. #include <iostream> // Basic input and output library
. #include <utility> // Define a set of templates for operator functions; For operator overload templates
. using namespace std::rel_ops; // The templates are defined in the std::rel_ops namespace
. #include "CandyBox.h" // For class CBox and class CCandyBox
. using namespace std; // Any name in std namespace
Header File
. #pragma once // Prevent the file contents from being included in the source code more than once
. #include "Box.h" // In inherited class CCandyBox
. #include "CandyBox.h" // For CBox and CCandyBox
. class CCandyBox : public CBox // In inherited class CCandyBox; private CBox or CBox
. explicit CBox(double side) : m_Length {side}, m_Width {side}, m_Height {side} {} // Specific constructor
Main Function
. #include <cstring> // For strlen() ans strcpy()
. #include <iostream> // Basic input and output library
. #include <utility> // Define a set of templates for operator functions; For operator overload templates
. using namespace std::rel_ops; // The templates are defined in the std::rel_ops namespace
. #include "CandyBox.h" // For class CBox and class CCandyBox
. using namespace std; // Any name in std namespace
Header File
. #pragma once // Prevent the file contents from being included in the source code more than once
. #include "Box.h" // In inherited class CCandyBox
. #include "CandyBox.h" // For CBox and CCandyBox
. class CCandyBox : public CBox // In inherited class CCandyBox; private CBox or CBox
. explicit CBox(double side) : m_Length {side}, m_Width {side}, m_Height {side} {} // Specific constructor
. #include <fstream>
ofstream myfile; // Write myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile.close()
. #include <fstream>
#include <string>
string line;
ifstream myfile("example.txt"); // Read
while (getline(myfile, line))
{
cout << line << '\n';
}
myfile.close();
#include <iostream>
int number; // Or int number = int();
cout << "Enter a number: ";
cin >> number;
cout << "The number is: " << number << endl;
#include <fstream> // Output with file (file stream 的縮寫)
ofstream myfile;
ofstream myfile1;
myfile.open("data.txt");
myfile1.open("rate.txt");
myfile << x << endl;
myfile1 << y << endl;
Basic Commands
. log(x) // Natural logarithm of x
. log10(x) // Logarithm of x
. exp(5.0) // = 148.413159
else // j is odd
K3 = K3 + Q;
if (i == 0 || i == n)
J1 = J1 + L;
else if (i % 2 == 0)
J2 = J2 + L;
else
J3 = J3 + L;
. for
for (int i{0}; i <= n - 1; i++) // or int i{}
. switch
switch(dice)
{
case 1: cout << pstr << pstr1;
a = 1.0;
break;
case 2: cout << pstr << pstr2;
break;
case 3: cout << pstr << pstr3;
break;
case 4: cout << pstr << pstr4;
break;
case 5: cout << pstr << pstr5;
break;
case 6: cout << pstr << pstr6;
break;
default: cout << "Sorry, you haven't got a lucky star.";
}
. return
(1) ok
if (FP == 0.0 || ((b - a) / 2.0) < tol)
return p; // Output p; procedure completed successfully
(2) ok
if (FP == 0.0 || ((b - a) / 2.0) < tol)
{
return p; // Output p; procedure completed successfully
}
(3) ok
if (FP == 0.0 || ((b - a) / 2.0) < tol)
{
cout << "Root: " << p << endl;
return p; // Output p; procedure completed successfully
}
(4) failed
if (FP == 0.0 || ((b - a) / 2.0) < tol)
{}
return p; // Output p; procedure completed successfully
(5) failed
if (FP == 0.0 || ((b - a) / 2.0) < tol)
cout << "Root: " << p << endl;
return p; // Output p; procedure completed successfully
. to comment-out (multi-line comments)
/*
cout << "The message is disabled" << endl;
*/
. log(x) // Natural logarithm of x
. log10(x) // Logarithm of x
. exp(5.0) // = 148.413159
. abs(-1.0) // = 1
fabs(-1.0) // = 1
. acos(-1.0) // = pi
. acos(-1.0) // = pi
. sqrt(143.0) // = 11.9583
. pow(5.0, 3) // = 125
. \ // Backslash as a line continuation character
a = 1.0 + 2.0;
or
a = 1.0 + \
2.0;
. \ // Backslash as a line continuation character
a = 1.0 + 2.0;
or
a = 1.0 + \
2.0;
. logical operators: &&, ||, !
. system("pause") // Pause
. if
for ()
. system("pause") // Pause
. if
for ()
{
if ()
{
statement 1;
statement 2;
}
}
if (i > 7) x = 6;
// 大於等於2行時, 需加大括號{}
if (j % 2 == 0) // j is even
{ K2 = K2 + Q;
// 大於等於2行時, 需加大括號{}
if (j % 2 == 0) // j is even
{ K2 = K2 + Q;
K3 = K3 + P;
}
}
else // j is odd
{ K3 = K3 + Q;
K4 = K3;
}
// 1行時, 毋需加大括號{}
if (j % 2 == 0) // j is even
K2 = K2 + Q;else // j is odd
K3 = K3 + Q;
if (i == 0 || i == n)
J1 = J1 + L;
else if (i % 2 == 0)
J2 = J2 + L;
else
J3 = J3 + L;
. for
for (int i{0}; i <= n - 1; i++) // or int i{}
. switch
switch(dice)
{
case 1: cout << pstr << pstr1;
a = 1.0;
break;
case 2: cout << pstr << pstr2;
break;
case 3: cout << pstr << pstr3;
break;
case 4: cout << pstr << pstr4;
break;
case 5: cout << pstr << pstr5;
break;
case 6: cout << pstr << pstr6;
break;
default: cout << "Sorry, you haven't got a lucky star.";
}
. return
(1) ok
if (FP == 0.0 || ((b - a) / 2.0) < tol)
return p; // Output p; procedure completed successfully
(2) ok
if (FP == 0.0 || ((b - a) / 2.0) < tol)
{
return p; // Output p; procedure completed successfully
}
(3) ok
if (FP == 0.0 || ((b - a) / 2.0) < tol)
{
cout << "Root: " << p << endl;
return p; // Output p; procedure completed successfully
}
(4) failed
if (FP == 0.0 || ((b - a) / 2.0) < tol)
{}
return p; // Output p; procedure completed successfully
(5) failed
if (FP == 0.0 || ((b - a) / 2.0) < tol)
cout << "Root: " << p << endl;
return p; // Output p; procedure completed successfully
. to comment-out (multi-line comments)
/*
cout << "The message is disabled" << endl;
*/
. 變動的檔名
#include <iostream>
#include <fstream> // Output with file
#include <string>
using namespace std;
int main()
{
std::string HistoryFilename = "temperature (n=" + std::to_string(0.5) + ")";
ofstream myfile;
myfile.open(HistoryFilename + ".txt");
myfile << 123 << endl;
myfile.close();
return 0;
}
2019年12月23日
Chapter 9 Class Inheritance and Virtual Functions
第 9 章基本 C++ 程式碼整理如下
9.1 Object-Oriented Programming Basics
9.2 Inheritance in Classes
∎ Deriving classes form a base class
Ex9_01.cpp (main function; #include "CandyBox.h")
CandyBox.h (derived class; #include "Box.h"; class CCandyBox : CBox)
Box.h (base class; class CBox)
9.3 Access Control under Inheritance
∎ Accessing private members of the base classclass
CCandyBox : public CBox vs. CBox (or private CBox)
∎ The function members defined in the derived class cannot access the private date members of a base class. To access the private members of the base class, one has to move the function "double volume() const" from the derived class to the base class.
∎ Constructor operation in a derived class
CCandyBox(double lv, double wv, double hv, const char* str = "Candy") : CBox {lv, wv, hv} // 1
explicit CCandyBox(const char* str = "Candy") // 2
∎ The access level of inherited class member
9.4 The Copy Constructor in a Derived Class
∎ The copy constructor in a derived class (Ex9_05)
CCandyBox(const CCandyBox& initCB) vs. CCandyBox(const CCandyBox& initCB) : CBox{initCB} // All copy constructors in both header files have to be called
9.5 Preventing Class Derivation
∎ Modifier "final"
9.6 Class Members as Friends
9.7 Virtual Functions
∎ Using an inherited function: early binding (Ex9_06)
myBox.showVolume(); // Call the volume() function in Box.h
myGlassBox.showVolume(); // Still call the volume() function in Box.h, not the one in GlassBox.h
∎ Fixing the CGlassBox: late binding (Ex9_07)
virtual double volume() const // Box.h
virtual double volume() const // GlassBox.h; don't forget to specify volume() as const, otherwise you won't override the base function
∎ Ensuring correct virtual function operation (Modifier "override")
virtual double volume() const override // The keyword "const" still cannot be omitted, however
∎ Preventing function overriding (Modifier "final)
virtual double volume() const final // If you don't want this volume() function to be overridden
∎ Points to base and derived classes (Ex9_08)
CBox myBox{ 2.0, 3.0, 4.0 }; // Define a base box
CGlassBox myGlassBox{ 2.0, 3.0, 4.0 }; // Define derived box of same size
CBox* pBox{}; // A pointer to base class objects
pBox = &myBox; // Set pointer to address of base object
pBox->showVolume(); // Display volume of base box
pBox = &myGlassBox; // Set pointer to derived class object
pBox->showVolume(); // Display volume of derived box
∎ Using references with virtual functions (Ex9_09)
output(myBox); // Output volume of base class object
output(myGlassBox); // Output volume of derived class object
void output(const CBox& aBox) // Accept an object of any class derived from CBox as an argument
{
aBox.showVolume();
}
∎ An abstract class (Ex9_10)
// Container.h
virtual double volume() const = 0; // No content; pure virtual function in the abstract base class
// Main.cpp
// Pointers to abstract base class, initialized with address of CBox object or CCan object
CContainer* pC1{ new CBox{ 2.0, 3.0, 4.0 } };
CContainer* pC2{ new CCan{ 6.5, 3.0 } };
pC1->showVolume(); // Output the volumes of the two objects ...
pC2->showVolume(); // ... pointed to
delete pC1; // Clean up ...
delete pC2; // ... the free space
∎ More than one level of inheritance (Ex9_11)
// Class CGlassBox is derived from its direct base class CBox and indirect base class CContainer
// Inheritance & Constructor (GlassBox.h)
class CGlassBox : public CBox
CGlassBox(double lv, double wv, double hv) : CBox{ lv, wv, hv } {}
∎ Calling the wrong destructor (Ex9_12)
9.8 Casting between Class Types
∎
9.9 Nested Classes
∎
9.10 Summary
∎
Reference: I Horton, Ivor Horton's Beginning Visual C++ 2013 (Wiley 2014).
9.2 Inheritance in Classes
∎ Deriving classes form a base class
Ex9_01.cpp (main function; #include "CandyBox.h")
CandyBox.h (derived class; #include "Box.h"; class CCandyBox : CBox)
Box.h (base class; class CBox)
9.3 Access Control under Inheritance
∎ Accessing private members of the base classclass
CCandyBox : public CBox vs. CBox (or private CBox)
∎ The function members defined in the derived class cannot access the private date members of a base class. To access the private members of the base class, one has to move the function "double volume() const" from the derived class to the base class.
CCandyBox(double lv, double wv, double hv, const char* str = "Candy") : CBox {lv, wv, hv} // 1
explicit CCandyBox(const char* str = "Candy") // 2
∎ The access level of inherited class member
9.4 The Copy Constructor in a Derived Class
∎ The copy constructor in a derived class (Ex9_05)
CCandyBox(const CCandyBox& initCB) vs. CCandyBox(const CCandyBox& initCB) : CBox{initCB} // All copy constructors in both header files have to be called
9.5 Preventing Class Derivation
∎ Modifier "final"
9.6 Class Members as Friends
9.7 Virtual Functions
∎ Using an inherited function: early binding (Ex9_06)
myBox.showVolume(); // Call the volume() function in Box.h
myGlassBox.showVolume(); // Still call the volume() function in Box.h, not the one in GlassBox.h
virtual double volume() const // Box.h
virtual double volume() const // GlassBox.h; don't forget to specify volume() as const, otherwise you won't override the base function
∎ Ensuring correct virtual function operation (Modifier "override")
virtual double volume() const override // The keyword "const" still cannot be omitted, however
∎ Preventing function overriding (Modifier "final)
virtual double volume() const final // If you don't want this volume() function to be overridden
∎ Points to base and derived classes (Ex9_08)
CBox myBox{ 2.0, 3.0, 4.0 }; // Define a base box
CGlassBox myGlassBox{ 2.0, 3.0, 4.0 }; // Define derived box of same size
CBox* pBox{}; // A pointer to base class objects
pBox = &myBox; // Set pointer to address of base object
pBox->showVolume(); // Display volume of base box
pBox = &myGlassBox; // Set pointer to derived class object
pBox->showVolume(); // Display volume of derived box
∎ Using references with virtual functions (Ex9_09)
output(myBox); // Output volume of base class object
output(myGlassBox); // Output volume of derived class object
void output(const CBox& aBox) // Accept an object of any class derived from CBox as an argument
{
aBox.showVolume();
}
∎ An abstract class (Ex9_10)
// Container.h
virtual double volume() const = 0; // No content; pure virtual function in the abstract base class
// Main.cpp
// Pointers to abstract base class, initialized with address of CBox object or CCan object
CContainer* pC1{ new CBox{ 2.0, 3.0, 4.0 } };
CContainer* pC2{ new CCan{ 6.5, 3.0 } };
pC1->showVolume(); // Output the volumes of the two objects ...
pC2->showVolume(); // ... pointed to
delete pC1; // Clean up ...
delete pC2; // ... the free space
∎ More than one level of inheritance (Ex9_11)
// Class CGlassBox is derived from its direct base class CBox and indirect base class CContainer
// Inheritance & Constructor (GlassBox.h)
class CGlassBox : public CBox
CGlassBox(double lv, double wv, double hv) : CBox{ lv, wv, hv } {}
9.8 Casting between Class Types
∎
9.9 Nested Classes
∎
9.10 Summary
∎
2019年12月19日
利用 MS Excel 的 Solver 進行曲線擬合 (Curve Fitting Using Excel Solver)
當我們進行數據分析時,常常碰到「找最佳參數值」的狀況。以下介紹如何利用 Microsoft Excel 內建的 Solver (規劃求解),快速完成黏度曲線擬合。
擬合公式為 Carreau-Yasuda 模型
此模型有五個參數,分別為 η∞、η0、λ、a、n,實驗數據如 Fig. 1 的黑色圓點。經使用 Excel Solver 求解後,可以得到 Fig. 1 的紅色曲線 (五個參數的最佳擬合值可見 Fig. 2 之結果)。對細節有興趣者,可參考文件 https://pages.mtu.edu/~fmorriso/cm4650/Using_Solver_in_Excel.pdf。
![]() |
| Figure 1 |
![]() |
| Figure 2 |
(註:在啟用規劃求解功能前,需至 Excel 的增益集新增該功能)
2019年12月18日
書籍 - 旋元佑英文字彙
訂閱:
文章 (Atom)














