Search code examples
plotgraphscilabcalculus

Calculating rho values for a lemniscate graph


I am trying to graph a lemniscate in polar coordinates on scilab. Which formula is rho^2=a^2*cos(2*theta).

The thing is that calculating the square root of certain values will return an imaginary number as the value would be negative.

clear
close
clc
clf
a=3;
theta=[0:((1*%pi)/180):((359*%pi)/180)];
rr=(a*a)*cos(2*theta);
rho=sqrt(rr);
polarplot(theta,rho,2);

Anyways, the program breaks itself when the negative rr values are reached since the square root is not properly defined for them.

All I need is the code to ignore those points and plot the others.

I don't know if this is understandable, but I hope someone do and can help me with this.

Thanks in advance.


Solution

  • You may ignore (e.g. filter out) those points, but there is an even easier solution: use only the real part of your result vector for the plot with real

    polarplot(theta,real(rho),2);
    

    You may also assigh it to a new variable if want to use it later:

    rhoreal=real(rho);