Monday 28 April 2014

The Area of Triangle

1. Coordinates


△ABC
= ADEC - △ADB - △BEC
= 1/2(x1y2 + x2y3 + x3y1 - x2y1 - x3y2 - x1y3)


2. Heron's Formula
△= sqrt(s(s-a)(s-b)(s-c))
x = 1/2 (a+b+c)



Ref.:
http://en.wikipedia.org/wiki/Triangle
http://euler.tn.edu.tw/area.pdf


Wednesday 23 April 2014

Systems of Linear Equation in 2 Variable

How many can systems of linear equation have?
1. 1 Solution
2. Infinite Solutions
3. No Solution


A) 
If (a1 / a2 != b1 / b2), it involves lines that intersect exactly 1 time.
-- Situation 1

B) 
If (a1 / a2 == b1 / b2 == c1 / c2), it's a same line.
-- Situation 2

C)
If (a1 / a2 == b1 / b2 != c1 / c2), lines are parallel.
-- Situation 3


[Cramer's Rule]


where  A_i  is the matrix formed by replacing the ith column of  A  by the column vector  b .

 




to solve:http://zerojudge.tw/ShowProblem?problemid=a410
Code:

Ref. http://en.wikipedia.org/wiki/Cramer%27s_rule

Quadratic Formula

The result of 
is


Tuesday 22 April 2014

[C++] Pointers

Noted down the important concepts:
1. Reference Operator (&)
ex.
myvar = 25;  
foo = &myvar;
bar = myvar; 

2. Dereference Operator (*)
ex.
baz = *foo;

3. Pointers & Arrays
It collects so many ways to get address from an array and set value to an array.
#include <iostream>
using namespace std;

int main ()
{
  int numbers[5];
  int * p;

  p = numbers;
  *p = 10;

  p++;
  *p = 20;

  p = &numbers[2];
  *p = 30;

  p = numbers + 3;
  *p = 40;

  p = numbers;
  *(p+4) = 50;

  for (int n=0; n<5; n++)
    cout << numbers[n] << ", ";
  return 0;
Output:
10, 20, 30, 40, 50,

4. Pointers and Const
int x;
      int *       p1 = &x;  // non-const pointer to non-const int
const int *       p2 = &x;  // non-const pointer to const int
int const *       p3 = &x;  // also non-const pointer to const int
      int * const p4 = &x;  // const pointer to non-const int
const int * const p5 = &x;  // const pointer to const int 

5. Pointers to Pointers
char a;
char * b;
char ** c;

a = 'z';
b = &a;
c = &b;

6. Pointers and Functions
#include <iostream>
using namespace std;

int addition (int a, int b)
{ return (a+b); }

int subtraction (int a, int b)
{ return (a-b); }

int operation (int x, int y, int (*functocall)(int,int))
{
  int g;
  g = (*functocall)(x,y);
  return (g);
}

int main ()
{
  int m,n;
  int (*minus)(int,int) = subtraction;

  m = operation (7, 5, addition);
  n = operation (20, m, minus);
  cout << n;
  return 0;
}
Output:
8
Mostly, we use function point in sqort().

7. Arrow
Same description below:
(*p).foo;
p->foo;

Ref. http://www.cplusplus.com/doc/tutorial/pointers/

Friday 18 April 2014

Sikuli

Sikuli is a picture-driven computing

Let's see the Demo: