Showing posts with label Matlab. Show all posts
Showing posts with label Matlab. Show all posts

Wednesday, April 28, 2010

HEART TO HEART

HEART TO HEART

A very interesting mathematical recreation is to conceive coherent drawings using algebraic functions. Bezier curves are the authentic way to generate such computer graphics. Bezier came up with his genius in early 60s while designing automobile parts. Other popular means are Hermite curves and Splines.

Though effective, these means are involved and computationally demanding. However, sometimes by providence we do have sensible shapes made out from simple functions.

PLOTTING THE HEART IN MATLAB

I discuss plotting a heart using simple cardioid, polar plots and algebraic equations

(a) The simplest one

The simplest 'heart curve' is the cardioid. It is not truly a heart, however it looks somewhat similar to one.


(b) Polar plot

A polar curve given by;

gives a near perfect heart !

The Matlab command line is;

>> ezpolar('((sin(t)*sqrt(abs(cos(t))))*(sin(t) + (7/5))^(-1)) - 2*sin(t) + 2')

(c) Algebraic Equation

A heart can be made from the implicit algebraic function,



However tinkering by adding a factor of (0.35) and (1.3) to the terms makes the heart more aesthetic.


The Matlab command is,

>> ezplot('(0.35)*((x^2 + y^2 - 1)^3) - (1.3)*(x^2)*(y^3)');

It is worth noting that for using ezplot t, x and y doesn't have to be defined.


(d) Another Algebraic Equation

This one is due to Matt ....




.
.
.
...then again forget MATLAB, we do have <3 to our rescue !



REFERENCES
(1) ezplot
(2) stackoverflow question 2720180
(3) stackoverflow question 323584
(4) Heart Curve page
(5) Wolfram page
(6) Bezier Heart in Gimp

Saturday, April 10, 2010

SINC LOOKS LIKE DIRAC DELTA

DABBLING IN MATLAB

After installing Matlab R2009b (7.9.0) on Ubuntu Karmic, I was trying out many thing ! ...... just for fun ! While trying out sinc function .... at a certain point it resembled dirac delta !
.
.
.
One very long spike unto infinity !


REFERENCES
(1) Delta Function
(2) Sinc - Delta Relationship

Friday, November 27, 2009

SINE INTEGRAL IN SCIPY

THE SINE INTEGRAL

The Sine Integral is a very important function in Physics, Astronomy, Electrodynamics, Mathematical Physics,Optics and Signal Processing.

A fundamental result in the sine integral is;

This result is analytically proven using contour integrals concept from complex theory.


TRYING IT IN MATLAB



MATLAB gives excellent results, particularly for the special case of (0-inf )it gives correct value.

TRYING IT IN SCIPY


In Scipy the sine integral (and the cosine integral) is via (si,ci) = sici function. It yields excellent values for numbers, however for infinity it yields nan (not a number). This should probably be corrected with an exception in the sici module.

It is worth noting that for sufficiently high values (which tend to infinity) the desired result of 1.57.... ( = pi/2) is obtained, which confirms the numerical evaluation is correct


REFERENCES

(1)
sici
(2) sine integral




Wednesday, November 25, 2009

RAISING IT TO THE POWER OF ......

LAWS OF EXPONENT

In the laws of exponents, a number can never be raised to an exponent to yield negative values. Only using complex exponents can negative values be obtained.


Trying the same formulation in python, it is worth noting that the formulation fails for a = 1 hence a special case output for a = 1.


Some sample output is ;


Similar treatments in MATLAB is also fruitful



The visible change is that iota in MATLAB it is i, while in Python it is j.


Monday, October 19, 2009

SQUARE ROOT OF IOTA

SQUARE ROOT OF COMPLEX NUMBERS

i, the square root of -1 the fundamental complex number. Working out the square-root of i;


ON MATLAB

Trying it on Matlab


Fig 1. Matlab 1



Fig 2. Matlab 2

Matlab gives very precise result both by 'power of 0.5' and 'sqrt function'.

USING CMATH

Using cmath module in Python;


Fig 3. cmath 1


Fig 4. cmath 2

cmath also gives wonderful results, however it is worth noting that the real and complex parts are different in the last 2 digits ( 0.70710678118654757 in the real part while 0.70710678118654746 in the complex part); which should not be so as they both represent the same number !

USING SCIPY

Using Scipy, scientific and numerical module in python



Fig 5. Using Scipy

Similar results to that of cmath.

SQUARING THE ROOT !

Squaring the square root often confirms to the accuracy and resolution of the software.


Fig 6. Squaring the root in Matlab


Fig 7. Squaring the root in cmath


Fig 8. Squaring the root in scipy

SOME OBSERVATIONS

Matlab on squaring the root, gives precise results

cmath and scipy on squaring the root gives precise results for the complex part but odd results for the real part (2.2204460492503131e-16 for scipy and -2.2204460492503131e-16 for cmath).

Using (1j)**0.5 and sqrt(1j) in scipy yields different results in real parts (2.2204460492503131e-16 for (1j)**0.5 and -2.2204460492503131e-16 for sqrt(1j)).


For developing scipy there should be a sense of consistency with cmath and the resolution (digits in the answer) should be controlled at the discretion of the user( It really looks sleek in Matlab). Further it looks odd and conveys a sense of inconsistency if the complex part tallies completely with the expected result while the real part has an inconsistency.

Sunday, October 11, 2009

EULER'S GAMMA !

EULER'S GAMMA

Once again ! .... we meet Leonhard Euler ... a constant named after him. Euler-Mascheroni constant which runs as .... 0.57721 … called 'gamma' ,denoted by the Greek alphabet 'gamma' and is one of the important constants of mathematics.

From an abinitio, 'gamma' is defined as;

IN SCIPY

Trying it out in scipy
yields a very accurate gamma.....

Fig 1. gamma in scipy

Should gamma be build into scipy as pi and e ?

Fig 2. pi and e in scipy

IN MATLAB

Trying it in MATLAB


MATLAB recognises the integral as a special integral ! ...... with a vpa, the value is obtained.

Gamma and other mathematical constants should be build into Scipy and Scipy should be intelligent enough to identify these expressions and integrals.







REFERENCES
(1) Murray Spiegel