Tuesday, June 14, 2011

Solving Equations using Matlab

Equations, Polynomials & Curve Fitting

Algebra has it's origins in the Communal Era of Indian History. The Celebrated book Brāhmasphuṭasiddhānta  of Brahmagupta 598–668 CE is probably the most influential ancient book on the topic. It contains the following contents:-

  • The sum of two positive quantities is positive
  • The sum of two negative quantities is negative
  • The sum of zero and a negative number is negative
  • The sum of zero and a positive number is positive
  • The sum of zero and zero is zero.
  • The sum of a positive and a negative is their difference; or, if they are equal, zero
  • In subtraction, the less is to be taken from the greater, positive from positive
  • In subtraction, the less is to be taken from the greater, negative from negative
  • When the greater however, is subtracted from the less, the difference is reversed
  • When positive is to be subtracted from negative, and negative from positive, they must be added together
  • The product of a negative quantity and a positive quantity is negative
  • The product of a negative quantity and a negative quantity is positive
  • The product of two positive, is positive.
  • Positive divided by positive or negative by negative is positive
  • Positive divided by negative is negative. Negative divided by positive is negative
  • A positive or negative number when divided by zero is a fraction with the zero as denominator
  • Zero divided by a negative or positive number is either zero or is expressed as a fraction with zero as numerator and the finite quantity as denominator
  • Zero divided by zero is zero
His ideas about division by zero were wrong, however it was the earliest attempt at division by zero.
Methods for finding the square root were developed in the Sulba Sutras & by Aryabhatt another renowned Communalist. 
" Brahmagupta's theorem is a result in geometry. It states that if a cyclic quadrilateral is orthodiagonal (that is, has perpendicular diagonals), then the perpendicular to a side from the point of intersection of the diagonals always bisects the opposite side. It is named after the Indian mathematician Brahmagupta." The Wikipedia.

Seminal contributions have come in from the Babylonians, Egyptians, Greeks, and the Persians. Diophantus, Heron of Alexandria and of course the Incomparable Al Khwarizmi on whose book "Kitab-i-Al-Jabr-Wal-Muqabla" Algebra is named.

The basic tenet of equations can be summarized as follows:-
1) if LHS=RHS then
=> LHS-x=RHS-x;
=> LHS+x=RHS+x;
=> LHS*x=RHS*x;
=> LHS/x=RHS/x;

The above rules are actually a consequence of The Law of Conservation of Energy & Mass

An event from the recent past however proves that this Law no longer holds. This event was the beaming of light from a Teresa Photo on Sept. 5, 1998. So the equation now is:-


 Photo=Photo + Light
So LHS=RHS no longer Holds

So Einstein's famous equatiion Energy=Mass * Speed of Light squared.
becomes
Energy = Mass * Speed of Light squared + T raised to the power A.
where T is the amount of SCAM Money given by Charles Keating to Teresa.
and A is the number of Child Abusing Priests protected by RATzinger.





This new equation has not yet been adopted by the IITs and they are still sticking with the Blasphemous and unsecular Einstein version which I  believe Jairam Ramesh deplored via his IIT faculty are not World Class comments.



Polynomials in Matlab

>> p=[1 0 6 20];
will create the polynomial x^3 + 6x + 20;
To evaluate it for some given value of x we use the polyval function:

for x=1
>> polyval(p,1)

ans =

    27

>>


for x=2.5

>> polyval(p,2.5)

ans =

   50.6250

>>


for x= 1 + i
>> polyval(p,1 + i)

ans =

  24.0000 + 8.0000i

>>


To find the roots of the equation use 

>> roots(p)

ans =

   1.0000 + 3.0000i
   1.0000 - 3.0000i
  -2.0000         

>>


To store the roots in a vector:

>> r=roots(p);
>> r

r =

   1.0000 + 3.0000i
   1.0000 - 3.0000i
  -2.0000         

>>


Using the Poly function we can get the equation back
>> v=poly(r);
>> v

v =

    1.0000    0.0000    6.0000   20.0000

>>


To plot the function create a vector, then use the polyval function to get the values; Then create a plot using the plot function:
>> x=[0:0.01:10];
>> plot(x,polyval(p,x));
>>





Multiplication and Division of Polynomials:
Multiplication is done using the conv function, while Division is done using the deconv function:

Using the polynomial from before :

>> p

p =

     1     0     6    20

>> 

which means x^3 + 6x + 20
to multiply with x-2
>> product=conv(p,[1 -2]);
>> product

product =

     1    -2     6     8   -40

>>

which means x^4 -2x^3 + 6x^2 +8x-40

Dividing using deconv:
>> deconv(product,[1 -2])

ans =

     1     0     6    20

>>

we get back the original polynomial.
This Post will be further enhanced











No comments:

Post a Comment