Category Archives: Mathematics

Mental Math Tricks

Will share that soon

Area of Circle using function

for formula: http://www.mathsisfun.com/area.htm

code:

We have to always remember that value that define is always pass from main function to customized function named by user so here r=3 is passing to function britto and then the britto formula pi*r*r is applying and returned the value and it is printed in the main function where the variable defined as khetrofol.

Here pi declared as global variable with it’s value.

Find Maximum and Minimum and Summation value from array

Did this problem from subeen vai’s book.

For maximum value:

For minimum value:

Summation:

Average:

Will give here

 

 

Math Motivation

http://www.prothom-alo.com/bangladesh/article/580627/%E0%A6%97%E0%A6%A3%E0%A6%BF%E0%A6%A4-%E0%A6%85%E0%A6%B2%E0%A6%BF%E0%A6%AE%E0%A7%8D%E0%A6%AA%E0%A6%BF%E0%A7%9F%E0%A6%BE%E0%A6%A1%E0%A7%87%E0%A6%B0-%E0%A6%A4%E0%A6%BE%E0%A6%B0%E0%A6%95%E0%A6%BE%E0%A6%B0%E0%A6%BE-%E0%A6%95%E0%A7%87-%E0%A6%95%E0%A7%8B%E0%A6%A5%E0%A6%BE%E0%A7%9F

LCM – Least Common Multiple

Multiple of 3 is
3×1=3
3×2=6
3×3=9
3×4=12
3×5=15
3×6=18
3×7=21
3×8=24
3×9=27
3×10=30

Multiple of 4 is
4×1=4
4×2=8
4×3=12
4×4=16
4×5=20
4×6=24
4×7=28
4×8=32
4×9=36
4×10=40

Here in 3 and 4 mutilples common is 12
and it is only one value and so it is the lowest also then but if there were some more values than result could be something changed.

So here LCM=12
Here I implemented the code
applied this formula
lcm(a,b)=a*b/gcd(a,b);

code goes here :

 

GCD Greatest Common Divisor(Factor)/Highest Common Factor

এখানে লজিকটা হচ্ছে…Here the logic is:
For 12:
1×12=12
2×6=12
3×4=12
So factor of 12=1,2,3,4,6,12
(We don’t need the negative values here)

For 30:
1×30=30
2×15=30
3×10=30
5×6=30
So factor of 30=1,2,3,5,6,10,15,30

Now which is the common factor among 12 and 30
So factor of 12=1,2,3,4,6,12
So factor of 30=1,2,3,5,6,10,15,30

common factor=1,2,3,6
Largest common factor here=6

So now if we divide 12/6 then we get 2
and for 30/6 we get 5

that is all divided perfectly so the logic should be like this

1.Find all the factors of each number
2. Circle the common factors
3. Choose the greatest of those
4. Divide the existing number with greatest common factor thern also get a perfect divide

Here is my code:

gcd

Here is a link that described many thinks about this clearly: http://www.mathsisfun.com/greatest-common-factor.html

 

Another method can also apply here:
link for understanding the modarithmetic euclidean algorithmhttps://www.khanacademy.org/computing/computer-science/cryptography/modarithmetic/a/the-euclidean-algorithm

Code:

 

URI Online Judge Solution| 1036 Bhaskara’s Formula

An equation ax2 + bx + c = 0 where a,b and c are any number  and called the coefficient of the equation
It is known as quadratic equation because any seconbd degree polynomial equation is known as quadratic equation.This equation has two roots x1 and x2

This is Bhaskara’s Formula or Bhaskaracharya’s Formula where discriminant D or Del = b24ac
If D>0 then root of quadratic equation are real and unequal
If D=0 then root of quadratic equation are real and equal
If D<0 then root of quadratic equation are conjugate complex number
Source:http://encyclopedia2.thefreedictionary.com/Bhaskaracharya%2
7s+Formula

http://www.wolframalpha.com/input/?i=Bhaskara%20formula
So my code is here

 

C code using Forward Interpolation

Problem: The population of a town is given below as thousands
Year : 1891 1901 1911 1921 1931
Population : 46 66 81 93 101

Find the population of 1895 ?

 

Code:

Output:

forward interpolation

C code using lagrange method

Problem: The population of a town is given below as thousands
Year            : 1891  1901  1911  1921  1931
Population :  46       66      81      93     101

Find the population of 1895 ?

 

Code:

 Output:

lagrange method

C code using lagrange method

Problem: The population of a town is given below as thousands
Year            : 1891  1901  1911  1921  1931
Population :  46       66      81      93     101

Find the population of 1895 ?

 

Code:

 Output:

lagrange method

C code using Backward Interpolation

Problem: The population of a town is given below as thousands
Year            : 1891  1901  1911  1921  1931
Population :  46       66      81      93     101

Find the population of 1895 ?

 

Code:

 Output:

backward

C code using Gauss Seidel Method

Problem: Solve the following systems using gauss seidel method
5×1-x2-x3-x4=-4
-x1+10×2-x3-x4=12
-x1-x2+5×3-x4=8
-x1-x2-x3+10×4=34

Code:

 Output:

gauss seidel method

C code using Euler Method

Problem: Here we have to find dy/dx=x+y where y(0)=1 at the point x=0.05 and x=0.10 taking h=0.05

Algorithm:

  1. Start
  2. Define function
  3. Get the values of x0, y0, h and xn
    *Here x0 and y0 are the initial conditions
    h is the interval
    xn is the required value
  4. n = (xn – x0)/h + 1
  5. Start loop from i=1 to n
  6. y = y0 + h*f(x0,y0)
    x = x + h
  7. Print values of y0 and x0
  8. Check if x < xn
    If yes, assign x0 = x and y0 = y
    If no, goto 9.
  9. End loop i
  10. Stop

 

Code:

 Output:

euler

C code using Runge-Kutta 4th order method

Problem: Here we have to find y(0,2) and y(0,4), Given dy/dx=1+y^2 where y=0 when x=0

Algorithm:

Step 1: input x0,y0,h,last point n

Step 2:m1=f(xi,yi)

Step 3:m2=f(xi+h/2,yi+m1h/2)

Step 4:m3=f(xi+h/2,yi+m2h/2)

Step 5:m4=f(xi+h,yi+m3h)

Step 6:yi+1=yi+(m1+2m2+2m3+m4/6)h

Step 5:Display output

Code:

 Output:

runge kutta

C code for newton-raphson method

Problem: Here we have to find root for the polynomial x^3-8*x-4 upto 6D(decimal places)

Solution in C:

 Output:
2014-11-27 11_48_33-