Calisthenics: 2 months progress + diet change? + maths …

Posted on Updated on

I took the left picture around the 3rd or 4th of February, the one on the right is me 2 months later after eating tons of chicken, broccoli and other healthy stuff with my work out plan. So far good progress … i hope… Lets see how much I change in the next 2 months.

Since I started working out I’ve been watching closely at Frank Medranos videos for motivation and I’m really surprised he’s a vegan. Apparently he feels more energetic eating nothing but just veggies. So I looked this up on what kind of food I can make for lunch that’s easy and I came across this site:

http://www.forksoverknives.com/recipes/?sort_posts=most_popular

Seems interesting, guess I’ll give it a go!

Oh yeah and some maths .. well yesterday I was working on my Quadratics Equation solver and I couldn’t find a solution to C being a minus figure

e.g. ax2 + bx + c = 0
becomes ax2 + bx – c = 0

c would then be read as a minus figure and I modified my code to below:

/*
 * a、b、cの値を取得
 */
void firstSolution::enterValues() {
    // とりあえずこれでいける...
    cout << "二次方程式:ax2 + bx + c = 0" << "\n" << "ax2 + bx - c = 0 の場合は" <<
            "cをマイナス数字で入力してください\n";
 
    cout << "aの値を入力してください: " << "\n";
    cin >> a_value;
 
    cout << "bの値を入力してください: " << "\n";
    cin >> b_value;
 
    cout << "cの値を入力してください: " << "\n";
    cin >> c_value;
 
    cout << "aの値を [ " <<  a_value << " ]として入力されました。\n";
    cout << "bの値を [ " <<  b_value << " ]として入力されました。\n";
    cout << "cの値を [ " <<  c_value << " ]として入力されました。\n";
 
    this->calculateSquareRoot(a_value, b_value, c_value);
}

This seems to work but its very very lazy and doesn’t necessarily solve the problem, But for now … I’ll leave it as this.

EDIT:

Okay I think i’ve fixed my code:


/*
 * 4*(a*c)
 * 入力されたデータは一般化されたのでdoubleかintでも計算できる
 */
template<typename T>
T firstSolution::calculateAC(T a, T c) {
	return a*c;
}

/*
 * 2*a
 * 入力されたデータは一般化されたのでdoubleかintでも計算できる
 */
template<typename T>
T firstSolution::calculateTwoA(T a, T two) {
	return a*two;
}

/*
 * 平方根の計算
 */
void firstSolution::calculateSquareRoot(int a, int b, int c) {
	int ac = this->calculateAC(a, c);
	int atwo = this->calculateTwoA(a, 2);

	quadratic_formula = sqrt((b*b) - (4 * ac));				// ax2 + bx + c = 0
	result[0] = (((b * -1) + quadratic_formula) / atwo);	// 二次方程式(+)
	result[1] = (((b * -1) - quadratic_formula) / atwo);    // 二次方程式(ー)
}

/*
 * 処理された回答を取得
 */
void firstSolution::getValues() {
	for(int i = 0; i < 2; i++) {
		cout << "x = [ " <<  result[i] << " ]\n";
	}
}

Using templates I can throw in any variable type and the code will be compatible. When dividing by 2 I forgot to multiply it with the variable a which somehow gave me the wrong values when I enter the values a=5, b=6 and c=1 when I use the example from this page ( http://www.mathsisfun.com/algebra/quadratic-equation.html )

What I was concerned about was adding the method:

/*
 * 2*a
 * 入力されたデータは一般化されたのでdoubleかintでも計算できる
 */
template<typename T>
T firstSolution::calculateTwoA(T a, T two) {
	return a*two;
}

because its the same as calculateAC. But to avoid confusion I figured its just better to make a new method like this, incase I would want to modify something later. My output now becomes:

benjamin.lo% ./a.out
二次方程式:ax2 + bx + c = 0
ax2 + bx – c = 0 の場合はcをマイナス数字で入力してください
aの値を入力してください:
1
bの値を入力してください:
3
cの値を入力してください:
-4
aの値を [ 1 ]として入力されました。
bの値を [ 3 ]として入力されました。
cの値を [ -4 ]として入力されました。
x = [ 1 ]
x = [ -4 ]

And with the example from the webpage above:

benjamin.lo% ./a.out
二次方程式:ax2 + bx + c = 0
ax2 + bx – c = 0 の場合はcをマイナス数字で入力してください
aの値を入力してください:
5
bの値を入力してください:
6
cの値を入力してください:
1
aの値を [ 5 ]として入力されました。
bの値を [ 6 ]として入力されました。
cの値を [ 1 ]として入力されました。
x = [ 0 ]
x = [ -1 ]

… Close enough.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s