Send your questions to my facebook, & get tips, solutions and answers.

Power sum in Ruby

March 18, 2013 Leave a comment
The logo, selected as winner of the Ruby Logo ...

The logo, selected as winner of the Ruby Logo Contest (Photo credit: Wikipedia)

1^m + 2^m + \ldots + n^m = ?

It is not easy to calculate if n is 50, nad m is 9. Here Ruby comes for help. If you had already installed Ruby 1.8 or Ruby 1.9, open terminal (in Linux) type irb and press enter. Then type following (don’t type > sign) :

>sum(n,m)
>return 1 if n == 1
>sum(n-1,m) + n^m if n > 1
>end

It is all, now type sum(50,9) and you will get the answer…

 

 

Advertisements

30 Trigonemetric Problems and Equations

March 18, 2013 Leave a comment

Quadrilateral Problem

January 7, 2013 Leave a comment

Fibonacci

January 7, 2013 Leave a comment

fibonacci_avatar

F_{1} =F_{2} =1; \; F_{n+2} = F_{n+1} + F_{n} ; \; \lim \limits_{ n \rightarrow \infty } \frac{ F_{n+1} }{ F_{n} } = \Phi \approxeq 1.61803... ;

F_{n} = \frac{1}{ \sqrt{5} } \cdot ( { \Phi }^n - ( 1- \Phi )^n ) ;

\sum \limits_{i=1}^{n} F_{i} = F_{n+2} - 1 ; \; \sum \limits_{i=1}^{n} { F_{i} }^2 = F_{n} \cdot F_{n+1} ;

F_{n+k} = F_{k} \cdot F_{n+1} + F_{k-1} \cdot F_{n} \; \; \; F_{2n} = F_{n} \cdot F_{n+1} + F_{n-1} \cdot F_{n}

Ruby code for Fibonacci numbers:

def fibo(n)
phi = ( Math.sqrt(5) + 1 )/2
pho = 1 - phi
if n > -1
Integer( ( phi**n - pho**n )/( Math.sqrt(5) ) )
else
Integer( ( (-1)**(n+1) )*fibo(-n) )
end
end

to be continued

Fuzzy Logic Calculator and Graph

January 4, 2013 Leave a comment

Triangle problem – finding height with given area and angles.

January 4, 2013 Leave a comment
Categories: Triangles Tags: , , ,

Accents and Symbols

December 20, 2011 Leave a comment
Categories: TeX Tags: ,
%d bloggers like this: